Subject: Re: The real TO:???

From: [email-masked] (David W. Tamkin)
Date: Sun, 31 Jul 1994 16:38:16 -0500 (CDT)

Ari Kornfeld asked,

| Ok, this is a tricky question:

It's one I went through myself.  I started running a mailing list here
with 'listname' and 'listname-request' simply aliased to dattier, relying
on ^TO tests to tell the two from each other and from my own mail, and I
realized that I had no way to divine the intended recipient when someone
used, for example, Elm's b)ounce command to forward mail to me.

| Is there some way of divining the true recipient (i.e., in my case, which
| alias it was sent to) from within the procmail family of programs or is my
| only recourse to add special entries to the system alias tables??

procmail cannot tell the outer envelope address of an incoming letter; it
can work only from the information in the text.

Sridhar Venkataraman has suggested looking for "Received:.*for alias" in
the headers.  Not all systems insert a "for" phrase like that.  If yours
does, then you have your answer.  Mine doesn't, so I had to try another way.

Unfortunately, in my position one is stuck doing what Ari doesn't want to
do: changing the system aliases file.  (That would also solve the problem of
overoptimization that you find when both aliases translate to the same real
user.)

One way is to use procmail's -a and -d options.  [Note that -d will work
only if procmail is (1) setuid root or all three of (2a) setuid to the
recipient named in the -d option, (2b) setgid to the login group of the
recipient named in the -d option, and (2c) running on a system with the
proper setuid/setgid semantics for (2a) and (2b) to work the way procmail
needs.]  I run a mailing list here with my own concocted .procmailrc recipes
rather than with SmartList.  The aliases look like this:

listname:	"|~dattier/bsdi/procmail -a listname -d dattier"
listname-request:	"|~dattier/bsdi/procmail -a listname-req -d dattier"

The sysadmin didn't install procmail here, so it isn't setuid root, but
~dattier/bsdi/procmail is a copy of procmail that is setuid dattier and
setgid to my login group.  (There's no security risk because procmail will
drop the setuid and setgid privileges unless it's invoked from the owner's
uid in the first place or started -d owner's_logname.)

In my .procmailrc I check $1; if it's "listname" then I know that the letter
was mailed to 'listname' even if the headers don't match "^TOlistname" nor
"^Received:.*for listname".  Likewise if $1 is "listname-req" I know that the
letter was mailed to listname-request and my .procmailrc proceeds
accordingly.  If $1 is unset, I know that the letter was mailed to dattier.

If you cannot use procmail's -d option [you can find out by checking the
description of the -d option in the procmail(1) man page], you still can do
this, ugly as it is, in the aliases file:

alias1:	"|/path/to/formail -I 'X-Envelope-To: alias1' | /bin/rmail yournamehere"
alias2:	"|/path/to/formail -I 'X-Envelope-To: alias2' | /bin/rmail yournamehere"
alias3:	"|/path/to/formail -I 'X-Envelope-To: alias3' | /bin/rmail yournamehere"

and then you'll have something reliable for your .procmailrc to work with,
and you'll also prevent overoptimization from multiple aliases that translate
to the same username.

David W. Tamkin  P. O. Box 3284  Skokie IL  60076-6284
[email-masked]   MCI Mail: 426-1818   +1 312 714 5610