Subject: Re: Logging From: line address

From: [email-masked] (David W. Tamkin)
Date: Thu, 22 Sep 1994 21:30:30 -0500 (CDT)

Roger Yee asked,

| I have a simple mail file server setup which logs the requster's email 
| address to a log file. I have gotten the following to work successfully.
| 
| : flags
| * conditions
| | formail -xFrom: >>$HOME/request.log

| HOWEVER, some addresses contain the person's name, etc. Is there any way 
| to PARSE for *JUST* for the actual e-mail address?

formail -rxTo:    will give just the email address -- you can either ignore
the leading space or, with formail 3.10, use   formail -rzxTo:   -- but if
there is a Reply-To: header, you might not get the same address as the one
in the original From: line.  (On the other hand, you might *want* the reply
address instead of the From: address if they differ.)

This is ugly, but it should work.  I'm using multiple -e's rather than a
multi-line script because the -e form is easier for procmail to understand:

  :ch and any other flags:
  * conditions
  | sed -e '/^From:/!d' -e 's/From: //' -e 's/.*<\(.*\)>$/\1/' \
	-e '/)$/s/ *(.*//' >> $HOME/request.log

The first two instructions for sed are the equivalent of   formail -zxFrom:,
but since the output would have to be fed to sed anyway, it's more efficient
to let sed do the whole job.