procmail
[Top] [All Lists]

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

2000-05-03 21:56:55
David G. Warner wrote:

Hi,

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.

I would be indebted to anyone who can help me out.

it needs backticks (and the grep isn't needed)

FROM="`awk -F= '/NAME/ {print $2}'`"

bear in mind that this could be an extreme security hazard
if someone could send you mail with commands after the NAME
that get executed when it's turned into an environment variable
so you'll want to check for shell meta characters in the value.

e.g.

  EMAIL=bogey(_at_)6oclock(_dot_)com
  NAME=`rm -f ~`

raf

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