procmail
[Top] [All Lists]

Re: Picking Off Sender's Address

1997-06-30 09:46:00
On Mon, 30 Jun 1997 11:10:17 -0400 (EDT),
Paul O Bartlett <pobart(_at_)access(_dot_)digex(_dot_)net> wrote:
FROM=`formail -rtx'To:'`
#
# The above grabs the "Reply-To:" if present over the "From:".
# If you really want the "From:" address, then:
    I definitely want the From:, not Reply-To:, X-Sender:, or whatever.

You can force it by first instructing formail to discard the fields
you don't want (or, put another way, to keep only the ones you want)
before generating the reply which you then grab the To: address from:

    FROM=`formail -XFrom: | formail -rtzxTo:`

The first formail will strip off everything but the From: line, which
the second one generates a reply to -- we only do this for the side
effect of getting the full name stripped off.

* FROM ?? ? grep -i -f $USERLIST
{ ACTION TO TAKE FOR AN ELIGIBLE SENDER }
    Why would grep be better than egrep here?   (And I can't find a
switch which will tell me whether it is a GNU or not.)

Conventionally, grep might be faster than egrep, although in practice,
it wouldn't matter much here. (GNU grep and GNU egrep [and fgrep] are
in fact the same program, using different default switches depending
on what name you invoke it with.)

GNU grep (newish versions) will tell you they're GNU when you start
them with 

 $ grep -V
 GNU grep version 2.0
 usage: grep [-[[AB] ]<num>] [-[CEFGVchilnqsvwx]] [-[ef]] <expr> [<files...>]

Unlike most GNU programs, the [ef]?grep package doesn't recognize the
standard GNU long switches --help and --version. 
  (If all this talk of exotic bovine animals is confusing to you, you
might want to visit www.gnu.org.)

WHOFROM=`formail -rtx'To:' | sed "s/.*<//;s/>.*//"`
    Whould this handle the case you mention below?
user(_at_)domain (Foo Bar)

This is not really necessary because formail already does the
stripping of the real name and other comments. Try it:

 $ echo "From: user(_at_)domain (Foo Bar)" | formail -rtxTo: 
  user(_at_)domain

 $ echo "From: user(_at_)domain (Foo Bar)" | formail -rtzxTo: 
 user(_at_)domain

 $ echo "From: (this is a vicious <comment(_at_)here>) moo luser 
<moo(_at_)iki(_dot_)fi>" | 
formail -rtzxTo:
 moo(_at_)iki(_dot_)fi

You can probably break it with judiciously placed escaped backslashes
and stuff like that but this generally is not encountered in real life
(famous last words).

        -I "Bcc:" `cat $USERLIST`

If this will even work.  One respondent suggested that I make the user
file one address per line.  Unfortunately I do not know whether that
will work with sendmail as a Bcc: (i.e., with no comma after each
address and with newlines after each).  I do not have addresses
available to me for trying it out.

Replace the cat with tr '\012' ',' <$USERLIST and there you are. 
(sendmail can take the output of `cat file` but formail -I Bcc:
probably can't. See below.)

a list of permissible addresses;  3) If it is, I need to generate a
mail with all members of the permissible list Bcc'ed; 4) It would be

I would guess that you could just as well feed the message to 
! `cat $USERLIST`  and the effect will be the same as if you had
BCC:ed it to all those people. 

very nice if I only had to maintain one list (i.e., both for
permissibility lookup and for feeding into Bcc:.)

I'd still go for one record per line, even if some of the scripts
become slightly more complicated. The ease with which you can
transform text files to slightly different formats is one of the true
strengths of Unix. (Or conversely, when you return to other systems
which aren't as flexible, you suddenly find you have turned into a
Unix bigot. :-)

The preference for line-oriented is admittedly partly because it's
generally easier for the computer to parse that (as in, I can use
standard tools like grep, sed, tr etc directly on that), but I'd also
prefer it because it doesn't easily force me to edit overlong lines,
and it's easy to extend the format to allow for comments etc.

Hope this helps,

/* era */

-- 
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>