Komal Tagdiwala (ktagdiwa | 28 Oct 2011 02:58
Picon
Favicon

Querying a DB to determine destination mailbox for an email using Procmail

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). 
3. The Perl script performs the actual query to database for a given keyword to find the corresponding
mailbox name.
4. The script then returns the mailbox name to the procmail script/recipe that invoked the Perl script.
5. The procmail recipe then directs that email (which had the keyword) to its intended mailbox (which was
dynamically determined using the query executed by the PERL script).

Is the above approach an appropriate way to implement the requirement outlined at the beginning of this email?

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?

If no, can you suggest an alternate way of achieving this requirement?

Thanks and regards,
Komal

------------------------------------------------------------------------------------------------------------------------------------------------------------------
Komal Tagdiwala | IT Engineer | Cisco Systems, Inc.| Contact Center Applications & Technologies
400 E Tasman Dr | SJC 12/3 | San Jose, CA 95134 | ktagdiwa <at> cisco.com | Office: (408)527-2163
------------------------------------------------------------------------------------------------------------------------------------------------------------------
(Continue reading)

LuKreme | 28 Oct 2011 03:56
Favicon

Re: Querying a DB to determine destination mailbox for an email using Procmail


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
email1 <at> example.com Friends
email2 <at> example.com Mom
(Continue reading)

Komal Tagdiwala (ktagdiwa | 28 Oct 2011 04:16
Picon
Favicon

RE: Querying a DB to determine destination mailbox for an email usingProcmail

Thanks for the prompt response.

My requirement does need a database based approach because:
(a) The values for key/value combination will be maintained using a
different application (to be designed) that is used by Business folks.
(b) The values would change dynamically as and when Business changes
them at different times of the week/weekend (when emails need to be
handled by different teams at different times).

If we maintain those values in a delimited flat file, business folks
(who may not have access to the system or may not have the technical
background to change the value) won't be able to update it at different
times of the week.

Regards,
Komal

-----Original Message-----
From: procmail-bounces <at> lists.RWTH-Aachen.de
[mailto:procmail-bounces <at> lists.RWTH-Aachen.de] On Behalf Of LuKreme
Sent: Thursday, October 27, 2011 6:57 PM
To: procmail <at> lists.RWTH-Aachen.de
Subject: Re: Querying a DB to determine destination mailbox for an email
usingProcmail

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.
(Continue reading)

Robert Bonomi | 28 Oct 2011 04:27

Re: Querying a DB to determine destination mailbox for an email using Procmail

> From procmail-bounces <at> lists.RWTH-Aachen.de  Thu Oct 27 20:57:18 2011
> Subject: Re: Querying a DB to determine destination mailbox for an email using
>     Procmail
> From: LuKreme <kremels <at> kreme.com>
> Date: Thu, 27 Oct 2011 19:56:53 -0600
> To: procmail <at> lists.RWTH-Aachen.de
>
>
> On 27 Oct 2011, at 18:58 , Komal Tagdiwala (ktagdiwa) wrote:
>
> > Requirement: I need to devise a solution where a procmail script can dynam
> > ically 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 b
> > ut wanted some expert opinion on finding the right approach.
> > 1. Use a database to maintain a key/value pair type information for a keyw
> > ord and a corresponding mailbox name. This information may be maintained m
> > anually or using a custom application (outside of procmail).
> > 2. Write a Perl script which takes an input parameter from procmail (I hav
> > e not done this before but I believe procmail can call a Perl script and j
> > ust pass an argument in the call). 
>
> If it is simply a matter of key/value pair, then it is much easier to use gr
> ep.

Assuming the number of pairs to check is 'rerasonable', 'grep' is a clear
winner.  If the count is in the millions, or hundreds of millions (unlikely!
admitted :) then the start-up cost of a real database query is likely to
(Continue reading)

Re: Querying a DB to determine destination mailbox for an email using Procmail

Another approach which I haven't yet seen mentioned, is to have 
procmail deliver TO the perl/whatever script, and have THAT script 
deal with delivery (though it must also deal with locking).

Your perl script can do the db operation, get a mailbox name, then 
append the message to it.

:0
| /path/to/perlscript

Safer, you could follow this with fallback handling - if the 
perlscript returns a nonzero result code, procmail can deliver the 
message to a default mailbox:

:0w
| /path/to/perlscript

:0:
problem.mbx
---
  Sean B. Straw / Professional Software Engineering

  Procmail disclaimer: <http://www.professional.org/procmail/disclaimer.html>
  Please DO NOT carbon me on list replies.  I'll get my copy from the list.
Komal Tagdiwala (ktagdiwa | 28 Oct 2011 16:03
Picon
Favicon

RE: Querying a DB to determine destination mailbox for an email usingProcmail

This approach of letting the PERL script take care of mailbox assignment
sounds very promising. Also, your recommendation to use a default
mailbox should the script result fail is nice to keep in mind as a
"catch-all" condition.

The question I have is... While I have used PERL to monitor mailbox
sizes and such purely by reading files from the file system, I don't
know how I can actually perform mailbox operations like intercepting an
email (as a procmail recipe does) and assign it to a specific mailbox
from within PERL.

Can you provide any pointers/guidelines on what modules to use in PERL
or any template/example for the same?

Thanks for your suggestion.

Regards,
Komal
------------------------------------------------------------------------
------------------------------------------------------------------------
------------------
This email may contain confidential and privileged material for the sole
use of the intended recipient. Any review, use, distribution or
disclosure by others is strictly prohibited. If you are not the intended
recipient (or authorized to receive for the recipient), please contact
the sender by reply email and delete all copies of this message.

For corporate legal information go to:
http://www.cisco.com/web/about/doing_business/legal/cri/index.html
(Continue reading)


Gmane