Re: Querying a DB to determine destination mailbox for an email using Procmail
LuKreme <[email protected]>
| Newsgroups | gmane.mail.procmail |
|---|---|
| Message-ID | <[email protected]> |
On 27 Oct 2011, at 18:58 , Komal Tagdiwala (ktagdiwa) wrote: > Requirement: I need to devise a solution where a procmail script can dynamically determine the final destination mailbox by querying a database for a particular keyword to get the corresponding mailbox. > > Approach I have in mind: > Based on my knowledge of procmail so far, I envision the following steps but wanted some expert opinion on finding the right approach. > 1. Use a database to maintain a key/value pair type information for a keyword and a corresponding mailbox name. This information may be maintained manually or using a custom application (outside of procmail). > 2. Write a Perl script which takes an input parameter from procmail (I have not done this before but I believe procmail can call a Perl script and just pass an argument in the call). If it is simply a matter of key/value pair, then it is much easier to use grep. # I think Sean wrote this, essentially. :0 h CLEANFROM=|formail -IReply-To: -rtzxTo: WHITELIST=$HOME/.friends ISLISTED=`grep -i "^$CLEANFROM " $WHITELIST` :0 * ISLISTED ?? ^[^ ]+[ ]+\/[^ ]+ $MATCH .friends [email protected] Friends [email protected] Mom [email protected] Bob [email protected] Friends > 3. The Perl script performs the actual query to database for a given keyword to find the corresponding mailbox name. If you need to query an actual database, then yes you will need an external script to do it. > 4. The script then returns the mailbox name to the procmail script/recipe that invoked the Perl script. That won’t work, the procmail recipe has to either wait for success, or assume success. This will be the hangup. > If yes, are there any conditions that I missed in my approach that I need to be mindful of before beginning research and development for this solution using this approach? The biggest issue is that your procmail deliveries will come to a complete stop while your query script runs. This might be a critical flaw, a minor annoyance, or of no importance at all. -- The only way of discovering the limits of the possible is to venture a little way past them into the impossible.