procmail
[Top] [All Lists]

Re: Picking Off Sender's Address

1997-06-29 15:29:00
At 01:02 PM 6/29/97 -0400, you wrote:
   procmail v3.10 under SunOS 4.1.4  I am working on a moderately
complex (for me) recipe with some nested nesting blocks.  Within one of
those blocks I am trying to get the sender's email address user(_at_)domain
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]

So far I have the following two recipe fragments:

   # Find out whom it is from (incomplete)
   :0
   * ^From:.*\/[^ ].*
   { WHOFROM=$MATCH }

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

I test the return code from the egrep as to which of two actions to
take (the sender is or is not in the user list file).  I am not a grep
heavy, so I am uncertain whether this is the best way to make the test.

There are many ways to skin a cat.  Here's another way.

        FROM=`formail -rtx'To:'`
        #
        # The above grabs the "Reply-To:" if present over the "From:".
        # If you really want the "From:" address, then:
        # FROM=`formail -zxc'From:'`
        #
        # grep = GNU grep v2.0
        #
        :0
        * FROM ?? ? grep -i -f $USERLIST
        { ACTION TO TAKE FOR AN ELIGIBLE SENDER }

   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

As the upper recipe above now stands, $WHOFROM could contain either

   Foo Bar <user(_at_)domain>
   user(_at_)domain

but I need to isolate the latter form.  Otherwise the egrep will never
come up with a match, even if user(_at_)domain is in fact in the  $USERLIST 
file.  So far I have not come up with any ideas for isolating just the
email address proper into variable $WHOFROM.  All suggestions
gratefully received.

        WHOFROM=`formail -rtx'To:' | sed "s/.*<//;s/>.*//"`

But why not just make the userlist file a name of "email addresses proper"
only?  That way, no matter it would make no difference whether the "From:"
line was

        Foo Bar <user(_at_)domain>
        user(_at_)domain

and you could run into problems with the above WHOFROM if someone formatted
their email address like this:

        user(_at_)domain (Foo Bar)

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.  Once a recipe gets delivered, ProcMail terminates the processing of
the ".procmailrc" file unless you use something like a "c" flag on that
recipe.


Lates!
---------------------------------------------------------------------------
Tim <bodysurf(_at_)pobox(_dot_)com>                          
mailto:bodysurf(_at_)pobox(_dot_)com
Finger bodysurf(_at_)pobox(_dot_)com for my PGP public key (Bits 1024/KeyID 
09DA5C49).
PGP Key FPrint (09/03/94): 4C 97 F1 FA 70 55 68 91  49 D1 AD F2 DD 63 0C 15
---------------------> Please PGP encrypt your email <---------------------