procmail
[Top] [All Lists]

Re: Picking Off Sender's Address

1997-06-29 11:24:00
On Sun, 29 Jun 1997 13:02:54 -0400 (EDT),
Paul O Bartlett <pobart(_at_)access(_dot_)digex(_dot_)net> wrote:
and see whether that address is in a file pointed to by variable
$USERLIST.  The file of users is a single record in the format:

user1(_at_)domain1, user2(_at_)domain2, user3(_at_)domain3, etc.  [commas 
for real]

I would think a lot of your problems could be solved if you reverted
to a line-oriented format. 

If this is not feasible, you can generate one for egrep to read on the
fly: 

    # Is this an eligible sender?
    :0 w
    | egrep -is $WHOFROM $USERLIST

    NL="
"

    :0 w
    | sed -e "s/, /$NL/g" $USERLIST | egrep -is $WHOFROM

or you could use Make to maintain two versions of the list, and have
the "slave" get updated semi-automatically each time you make updates
to the "master" version (which I would want to be the line-oriented
one, if I were you).

    More importantly for this inquiry, the From: header on an incoming
mail could legally be in either of these two forms:
    From: Foo Bar <user(_at_)domain>
    From: user(_at_)domain

The canonical way to get formail to strip an address down to just the
email terminus (i.e. user(_at_)domain) is

    formail -rtzxTo:

but this is not guaranteed to always pick the From: address for a
reply address (it will grab Reply-To instead if it's there, etc).

But if your line-oriented file only contains user(_at_)domain-type
addresses, you can instead flip the grep to see if any of the strings
in the file match the address. Do you specifically need egrep
functionality? fgrep would normally be better for this type of
matching: 

    :0 w
    | echo $WHOFROM | fgrep -isf $USERFILE

where USERFILE is a line-oriented file of addresses. Better yet, you
could instruct formail to extract a number of fields for you, instead
of whatever you happen to catch in WHOFROM, so that you get a match if
one of the addresses in your file is in any of From:, Sender:,
Reply-To:, or From_ (add more as you see fit):

    :0 w
    | formail -cz -xFrom -xSender: -xReply-To: | fgrep -isf $USERFILE

P.S.  If a mail actually gets delivered to a real folder deep with
nested blocks, doesn't that terminate all processing all the way 
back to the outer recipe of the .procmailrc file which "calls" all 
those nested blocks?  (That is my reading of the man page.)

Yes, it would seem so, provided that you haven't done :0c somewhere
along the way, of course.

/* era */

PS. Do you mean you currently do this:

    :0 w
    | egrep something

    :0a
    { yes, it matched: do this block }

    :0E
    { no, it didn't: do this block }

I would think it would probably be more readable with 

    :0 w
    * ? egrep something
    { yes; do this block }

    :0E
    { no; do this block }

... but YMMV.

-- 
Defin-i-t-e-ly. Sep-a-r-a-te. Gram-m-a-r.  <http://www.iki.fi/~era/>
 * Enjoy receiving spam? Register at <http://www.iki.fi/~era/spam.html>