On Thu, 4 Dec 1997 01:20:05 -0800 (PST), David Hunt <dh(_at_)west(_dot_)net>
wrote:
On Wed, 3 Dec 1997, Bishop & Bebe wrote:
What I want to do is take the senders name from an incoming email and
add it to an existing list.
... I have no idea if the incoming mail will have From:, X-Sender:, or
what. But I want to be able to know who is requseting certain files.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This leads one to believe that B&B is looking for an e-mail terminus,
not the real name of the requestor. Either way, David's proposed
solution is flawed: In the presence of both X-Sender: and From:, it
should probably prefer From: (I don't think X-Sender even contains
real names. Sender: is also predominantly just addresses, although you
see Sender: fields with real names in them. I've never bothered to add
my real name to my Reply-To: when I add one, either, but it's not that
uncommon to include it, either).
:0 chiw :$FILE$LOCKEXT
* ^(Reply-To|From|(X-)?Sender):\/.*[a-z0-9].*<(_dot_)*(_at_)(_dot_)*>
| echo $MATCH >> $FILE
This will simply grab the first one of the four alternatives that
Procmail happens to stumble over. Of course, since this requires the
presence of at least one alpha character before the opening bracket,
it will never even match fields with no real name, or fields where the
real name is coded differently, as in "Sender: era(_at_)iki(_dot_)fi (era)"
which
is a valid Sender: as far as I can tell; this syntax is also valid for
From: and Reply-To:.
The canonical way to get the address information is with
FROM=`formail -rzxTo:`
or some variation of this. This will strip off any real names or other
comments. You still have to take care of upper/lowercasing the
returned information yourself, if you want that.
| echo $MATCH >> $FILE;sort +1 -u $FILE -o $FILE
One could design a more elaborate sort. This one's fairly crude, but
should make readable files with a sort on lastname in most cases.
If this is used only for logging, it might be a better idea to sort
only when you actually want to view the log, and simply append the
data to the log at this point.
Here's what I have for preventing over-use of my ftp-by-mail server --
you are only allowed to request a three files per 24 hours per address
(of course, if you happen to do this around midnight in my time zone,
you could get away with up to six):
LUSERS=$HOME/ftp/lusers.$DATE
LOCKFILE=$LUSERS.lock
:0
* ? formail -rzxTo: | tee -a $LUSERS | ( fgrep -- "`cat -`" $LUSERS) | \
tail +4 | grep .
{
SUBJECT="File request rejected"
FILE=reject.txt
}
LOCKFILE
Perhaps this could be done more elegantly? I remember I struggled a
lot, for no obvious reason, to get all of this packed into a single
pipeline. :-)
Anyway, in my case, this gets invoked something like once to five
times a month, so it might not matter much how exactly I do it. (Lame
excuses dept.)
formail -r versus formail -rt is a tough choice to make -- with -rt,
you often end up relying on Reply-To: and From: which are very easy to
forge. On the other hand, with plain -r, many users on PPP links will
show up as a different address each time they connect to a different
dialup.
/* era */
--
Paparazzi of the Net: No matter what you do to protect your privacy,
they'll hunt you down and spam you. <http://www.iki.fi/~era/spam/>