On Wed, 3 Aug 2005, Professional Software Engineering wrote:
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.
[...]
Right, I liked the question as procmail riddle (:-)
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.
Thats challenge. I think that X-Original-To hold only one
address.
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):
There are three problems with grep. (1) The output includes
the word that you are looking for and we want only the address
after the first word. (2) grep can give you more then one
output, for example: sara(_at_)abcd(_dot_)co will give you lines with
sara(_at_)abcd(_dot_)com (you can solve it with "-w" flag). (3) From
previous example: sara(_at_)abcd(_dot_)co can be one of the forward
address
fields.
# 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)
Just for this case i.e. using "!", the spaces are not
problem so you can merge the two lines and blocks:
:0 c
* ! REP ?? ^^[ ]*^^
!$REP
Bye,
Udi
---
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
____________________________________________________________
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