I would like to improve the following recipe
:0 hw
* ^Subject:.*unsubscribe \/.*
{
LOCAL=$MATCH
:0
* LOCAL ?? (_dot_)*(_at_)\/.*
{
SENDER=$LOCAL
}
}
This checks to see if the Subject line is attempting to unsubscribe some
email address, presumably a different email address than in the from line.
It puts the email address in the variable SENDER, where it is then used in
SENDMAIL -f $SENDER.
Assuming the input is
Subject: unsubscribe joe(_at_)aol(_dot_)com
this works just fine.
If they get fancy, and try to put in two email addresses, the whole string
after unsubscribe gets put in SENDER.
Subject: unsubscribe joe(_at_)aol(_dot_)com
sam(_at_)compuserve(_dot_)com
And SENDER = joe(_at_)aol(_dot_)com sam(_at_)compuserve(_dot_)com, which then
bombs SENDMAIL.
I would be happy just picking up the first email address, and ignoring
anything else.
If I try changing the regular expression to end with a space, it only works
for the second case.
:0 hw
* ^Subject:.*unsubscribe \/.* ()
and bombs on the more normal unsubscribe joe(_at_)aol(_dot_)com(_dot_)
This try was innovative, but fails if there is more one space, as the
regular expression is greedy.
:0 hw
* ^Subject:.*unsubscribe \/.*
{
saved = $SHELLMETAS
SHELLMETAS
LOCAL= `expr "$MATCH" : '\(.* \)' \| "$MATCH"`
:0
* LOCAL ?? (_dot_)*(_at_)\/.*
{
SENDER=$LOCAL
}
SHELLMETAS = $saved
}
Awk seems like a good choice, as it can easily parse between spaces, and
return the first word of a phrase. However, my attempt at invoking awk has
failed.
:0 hw
* ^Subject:.*unsubscribe \/.*
{
saved = $SHELLMETAS
SHELLMETAS
LOCAL= `echo "$MATCH" | awk 'print {$1}'`
:0
* LOCAL ?? (_dot_)*(_at_)\/.*
{
SENDER=$LOCAL
}
SHELLMETAS = $saved
}
So, I am all eyes, if somebody can point out how to improve on my original
receipe to handle the .0001% of the time when people put more than one
address in the Subject line. My guess is that a really good regular
expression, instead of just .*, would negate the need for any follow up
programs to pull out the first address.
Thanks
mark