era eriksson <era(_at_)iki(_dot_)fi> writes:
Yes, and the solution is slightly simpler than what you have, although
the syntax is a bit awkward.
The key to it all is the \/ grabbing operator. With that, we don't
need the call to formail, and if we turn your pseudocode into actual
Procmail syntax, we get
:0 # The \/ says, "if we have a match, save the part that follows"
* ^Delivered-To:[ ]*\/[^ ]+(_at_)foo\(_dot_)com
{
# The string that matched the regex after \/ is now in $MATCH
# Keep a copy in DELIVERED
DELIVERED=$MATCH
# Rename the Delivered-To: field to Old-Delivered-To:
:0fwh # added a w flag -- always a good idea
| formail -i "Delivered-To:"
# Now deliver according to what was in Delivered-To:
:0
* DELIVERED ?? bar(_at_)foo\(_dot_)com
! a
:0
* DELIVERED ?? bloo(_at_)foo(_dot_)com
! b
...
Great... I even added a couple of "improvements/bugs"
:0
* ^Delivered-To:[ ]*\/[^ ]+(_at_)ingrand\(_dot_)net
{
DELIVERED=`echo $MATCH | sed -e 's/@ingrand\.net$//' -e
's/^redirect-//' -e 's/^ingrand\.net%//'`
# now DELIVERED contains the "user" name only
# Rename the Delivered-To: field to Old-Delivered-To:
:0fwh # added a w flag -- always a good idea
| formail -i "Delivered-To:"
# Now deliver according to what was in Delivered-To:
:0
* DELIVERED ?? felix
....
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
"Si on avait su que tout ca finirait pour voir Barthez embrasser McDonald's."
Professional: http://www.laas.fr/~felix Jean Luc Godard
Personal: http://www.ingrand.net/felix