At 04:31 2005-08-03 +0000, Stephen Allen wrote:
I have lots of recipes similar to the ones below:
:0 c
* ^X-Original-To:.(fred|barney|wilma)@mydomain\.com
! me(_at_)anotherdomain(_dot_)com
:0 c
* ^X-Original-To:(_dot_)betty(_at_)mydomain\(_dot_)com
! you(_at_)yetanotherdomain(_dot_)com \
someoneelse(_at_)anywhere(_dot_)com
Keep in mind one of the procmail mantras (everone else, sing along with me):
Procmail is not an MTA.
You're trying to use procmail as an MTA, and there's always going to be
issues with that - take for instance when TWO or more parties are copied on
a message. Go ahead, send ONE message addressed to
fred(_at_)mydomain(_dot_)tld with
a cc to wilma(_at_)mydomain(_dot_)tld, and a bcc: to
betty(_at_)mydomain(_dot_)tld (but using
actual addresses as per your filters). How many copies does each person
get, and who doesn't get one?
Properly, this stuff should be handled at the MTA level (which is where the
'aliases' file which Damian referred to, resides), as the MTA knows all of
the envelope recipients - information it doesn't always share with the
local delivery.
Of course, not everybody has administrative control over their own server
(bummer for you if that's the case). You should first check with your ISP
and see whether there is an interface to permit user-specified aliasing at
the MTA level, and if so, use that, since it's the proper way to do
things. Otherwise, yea, you're pretty much stuck making do, but in doing
that, you need to be aware that it is rife with problems, and procmail
isn't at fault for the failures - you're trying to do something which
procmail isn't intended for, and which procmail will invariably not be
provided with enough data by the MTA to perform reliably.
It would be easier if I could just dump the names in a file, and have the
file parsed for forwarding addresses. Eg:
fred(_at_)mydomain(_dot_)com me(_at_)anotherdomain(_dot_)com
Problem: if you have multiple recipients on messages, you're going to need
to perform lookups against that file multiple times - one for each apparent
recipient of the message. That also means you need to parse the message
for recipients and extract them to a variable and walk through that variable.
betty(_at_)mydomain(_dot_)com you(_at_)yetanotherdomain(_dot_)com
someoneelse(_at_)anywhere(_dot_)com
The first column is the address here, the rest of the line is a list of
email addresses to forward to.
Sensible way to structure the file. awk or grep will work to extract
matches. The awk solution has already been presented. Here's a grep one
(assuming single-recipient -- I don't have the time to spare to write up a
loop for parsing your messages for multiple recipients):
# format the my aliases file with spaces as address separators.
:0
* ^X-Original-To:.\/(_dot_)+(_at_)mydomain\(_dot_)tld
{
FRO=$MATCH
REP=`grep -i -e "^$FRO "` my.aliases
# check that it's not a null string, then extract the other recipients
# the extraction is by matching whatever number of non-whitespace,
# followed by whatever number of whitespace, then enabling the match
# and matching a non-whitespace, followed by whatever to the
EOL. Thus
# you can use a bunch of spaces or tabs to make your my.aliases file
# pretty, but they won't appear in the alias.
:0
* ! REP ?? ^^^^
* REP ?? [^ ]*[ ]*\/^[ ]*.*
{
REP=$MATCH
}
# and forward (or whatever).
:0A
!$REP
}
(untested)
---
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.
____________________________________________________________
procmail mailing list Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail