0

i need procmail to place incoming mail into specific folder depending on some set of rules. I know how i can accomplish this, but i need to write static set of rules in a specific file. What i really need is to configure procmail to use rules stored in mysql database. How i can do this? I've read a bit about that and one solution i found is to pipe message to a php/perl script and return a folder name to place message. But i have completely no i idea how to use php script as a rule and then use its return value.

1 Answer 1

0

To "place incoming mail into [a] specific folder depending on some set of rules" is precisely what Procmail does out of the box, but I guess you are looking for something like this:

FOLDER=`/path/to/script.php`
:0
$FOLDER

It's deceptively simple, but that's really all it takes. A command in backticks will receive the current message as its standard input.

(If $FOLDER is a static file, you need to add locking, but that's a tangential topic.)

If this is all your Procmail rules do, you might want to think about whether Procmail is at all required. The delivery part is still useful and robust, so I recommend you keep it for that, but since Procmail is good at doing precisely what you are trying to do with PHP, perhaps you want to think about your approach.

If your database doesn't change very frequently, you might want to consider using a script to generate your .procmailrc from the database instead. Then the Procmail rules themselves can be static (ideally not require any external process) but you will need to regenerate them whenever the database is updated.

2
  • Can you tell me, what my script have to return in order to 'do nothing' and continue to the next rules? I want to place rule for my script at first to filter known messages, and all rest check with spamassassin (from the second rule)
    – WombaT
    Nov 21, 2012 at 8:00
  • I don't really understand the follow-up question. You mean it should have a way to say "I don't know" and have Procmail fall through? Maybe add a condition to check that the value of FOLDER is not the empty string, * FOLDER ?? .
    – tripleee
    Nov 21, 2012 at 8:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .