Procmailrc recipe help; multiple To: recipient processing
am 16.02.2007 16:27:38 von toddboss
Hello. Apologies if this is a trivial matter but I can't seem to find
an answer to my issue.
I use procmailrc to filter and redirect mail coming into a generic
domainname (call it abc.com).
Mail sent to user1@abc.com needs to go to joe@gmail.com
Mail sent to user2@abc.com needs to go to bob@yahoo.com, etc.
I use a series of simple recipes in .procmailrc that look like this:
:0
* ^TO.user1@abc.com
! joe@gmail.com
and then have a catch all at the end (after spam processing and all
the other redirects)
:0
/var/mail/localuser
the problem: I have a number of mails coming in now that are sent to
"user1@abc.com, user2@abc.com" or are sent directly to "user1@abc.com"
and have CC: user2@abc.com which never get to the 2nd user because
procmailrc runs the recipe for the user1 account, forwards along the
mail to the joe@gmail.com account and never runs another recipe.
How do I get around this issue? The only solution i've seen in my
investigation seems to be to create local users for all these people
and just have simple .forwards for them but its not a machine i
control root on (ISP unix box with multiple domains hosted). to make
matters worse my users get email in many formats (firstname@abc.com,
firstinitlastname@abc.com, firstname.lastname@abc.com) so i really
need to use procmail to handle all the various conditions.
Is there a simple recipe out there that someone uses? Perhaps a loop
through recipients?
thanks, todd
Re: Procmailrc recipe help; multiple To: recipient processing
am 18.02.2007 01:00:22 von Alan Clifford
On Fri, 16 Feb 2007, tboss@bossconsulting.com wrote:
t>
t> the problem: I have a number of mails coming in now that are sent to
t> "user1@abc.com, user2@abc.com" or are sent directly to "user1@abc.com"
t> and have CC: user2@abc.com which never get to the 2nd user because
t> procmailrc runs the recipe for the user1 account, forwards along the
t> mail to the joe@gmail.com account and never runs another recipe.
t>
t> How do I get around this issue? The only solution i've seen in my
t> investigation seems to be to create local users for all these people
t> and just have simple .forwards for them but its not a machine i
t> control root on (ISP unix box with multiple domains hosted). to make
t> matters worse my users get email in many formats (firstname@abc.com,
t> firstinitlastname@abc.com, firstname.lastname@abc.com) so i really
t> need to use procmail to handle all the various conditions.
t>
This is not to be recommended. What about if the recipient is a bcc?
However, if you count the number of occurences of example.com in the to:
and cc: headers, you can cobble something together. Below is something I
did a few years ago. Essentially, get the to: and cc: header recipients
into a variable; check each of the three possible users, margaret, test
and testtest and forward the mail to them if appropriate. For example. a
mail comes to margaret@clifford.example, test@clifford.example and
mrblobby@clifford.example. It will be delivered to margaret and test and
the scoring at the end will result in 0 so a copy of the message will fall
through and be delivered to the default user (this was alan on my system).
Had mrblobby not been a recipient, the scoring at the the end would have
delivered the extraneous, unwanted copy to IN.notforalan.
#<------ procmail recipe ---------->
# get the to and cc headers
# this appears to put a blank before the start
:0 w
TOCCHEADER=| formail -x To: -x Cc:
# clifford.example mail
:0
* TOCCHEADER ?? @clifford\.example
{
# To margaret
:0 c
* TOCCHEADER ?? [^-a-zA-Z0-9_.]margaret@clifford\.example
! margaret
# To test
:0 c
* TOCCHEADER ?? [^-a-zA-Z0-9_.]test@clifford\.example
! test
# To proctest
:0 c
* TOCCHEADER ?? [^-a-zA-Z0-9_.]testtest@clifford\.example
! test
# is it for alan or unknown?
:0:
# add a +1 to ensure positive rather than 0
* 1^0 TOCCHEADER ?? @clifford\.example
# subtract 1 for each clifford.example
* -1^1 TOCCHEADER ?? @clifford\.example
# add one for each of the names specified above
* 1^1 TOCCHEADER ?? [^-a-zA-Z0-9_.]margaret@clifford\.example
* 1^1 TOCCHEADER ?? [^-a-zA-Z0-9_.]test@clifford\.example
* 1^1 TOCCHEADER ?? [^-a-zA-Z0-9_.]testtest@clifford\.example
# if positive, then not for alan or unknown
IN.notforalan
}
#<------ procmail recipe ---------->
So, to extend for extra users, you would have to put in an extra recipe
for each user and an extra line in the scoring section.
You could probably rationalize it using a database (even a simple text
file of addresses accessed using grep for example) if you have a large
number of users, but the principle algorithm remains the same - check for
mail to recipient and deliver if required; count the number of
@example.com occurances and discard the final copy of the email if not
required.
--
Alan
( If replying by mail, please note that all "sardines" are canned.
There is also a password autoresponder but, unless this a very
old message, a "tuna" will swim right through. )