At 19:44 2004-01-26 +0100, Peter Rosa wrote:
please, isn't there some simpler/quicker way to suck variables from
incomming mail then usage of formail ? Is this really the only solution:
TO_HEAD=`formail -x "To:"`
Time to spend some quality time with the procmail manpages. You're looking
for $MATCH.
And what, if I need to suck only the part of it, e.g. only the domain ? Is
this proper way:
DOMAIN=`formail -x "From:" | awk -F@ '{ print $2 }' | awk -F '>' '{ print
$1 }'`
If you've got a complaint about speed, eliminating *AWK* (especially two
pipelined invocations of it) from the equation will do a LOT to improve things.
If you really had to use a pipeline, the above would be much improved by
using sed instead:
(formail operation) | sed -e s/^.*@//
would delete everything before and including the @ sign, which in an ideal
world, basically leaves you with the domain portion, doesn't it? Conversely:
sed -e s/@.*$//
would delete the @ to the end of the line, which would leave you with the
username portion.
sed is a *LOT* less resource intensive than AWK.
Also, if someone uses their address (or just an @) in their address
COMMENT, your formail invocation is going to see that, and you'll have
troubles.
formail -rtzx "To:"
would grab just an address portion. In my sandbox, I use:
CLEANFROM=|formail -IReply-To: -rtzxTo:
to extract the From: address (by first eliminating the Reply-To:, which
would come into play from the "reply" type function of formail). Then,
obtaining the username and domain portions is performed entirely within
procmail using the MATCH construct.
It seems to be slow and consuming too much memory and processor time, isn't
it ?
That's the hallmark of AWK.
Follow the link in my .sig and head to my page on sandboxing. My basic
sandbox script inclodes procmail (+formail) code to extract an address and
split it into username and domain portions.
---
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(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail