procmail
[Top] [All Lists]

Re: extracting a field from the body of a message and saving it as an environment variable

2000-05-03 22:07:15
"David G. Warner" <dgw(_at_)siderealsystems(_dot_)com> writes:
I routinely get email messages of the following form:
EMAIL=someone(_at_)somedomain(_dot_)com
NAME=Somebody Someone

I was hoping that I could extract the value from the EMAIL field and
save it as an environment variable in a procmail script.  The variable
would then be used to address an automated response to the person at
that email address.  I think I have the whole script down except the
(somewhat important) part about extracting the email address.  After
reading through the man pages and looking at some things on the Internet
I came up with
FROM=grep -v NAME | awk -F= '{print $2}'
Of course, this doesn't work and I've exhausted my minimal UNIX
knowledge.

You can use procmail's regexp to match the desired value directly and
capture it into the environment variable MATCH, from whence you can
copy it to the variable FROM:

        :0 B
        * ^EMAIL=\/.*
        {
            FROM = $MATCH
        }

The 'B' flag tells procmail to match the regexp against the body of the
message instead of against the header.  The '\/' token in the regexp
causes procmail to capture everything matched by the regexp to the
right of the \/ token to be saved into the variable MATCH.  The left
brace starts a nested block which can contain variable assignments and
other recipes.  In this case it just contains a variable assignment.

Does that make sense?


Philip Guenther

<Prev in Thread] Current Thread [Next in Thread>