procmail
[Top] [All Lists]

Re: rewriting "From " line

1998-07-16 19:07:43
Dave Robbins asked,

| I use mailx to read my mail.  I'd like something better but I haven't
| found anything else that allows me to read my mail as easily from any machine
| at any time.

Ah, but one thing wonderful about mailx is that you can easily make it filter
outgoing mail, and procmail's -m option is perfect for that.  [I think it was
our own Era Eriksson who nicknamed a procmail rcfile for outgoing mail a
"backward" (opposite of ".forward") file.]

| However, one major disadvantage of mailx is that it is
| brainless about where to get a sender's full name from when a mailing list
| rewrites the "From " line.

It is brainless about where to get the sender's name when the From: header
has no name, whether the From_ address has been rewritten or not, because
it makes a beeling for the From_ address instead of using the unnamed email
address in the From: header.

| Thus , for those who don't have full names
| such as AOL users, mailx displays the LH side of the "From " line
| when the h command is issued.  Instead of the sender's address,
| I get a list admin address.

Yup, but again, that is mailx's mistake, not the list administrator's.

| So, I want to use formail, I'm guessing, to rewrite the "From " line
| to get the sender's name from the From-with-a-colon line.  I've tried
| numerous things including modifying -f in the .forward file
| but no luck yet.

Now, normally I do not recommend screwing with the envelope sender address,
but this is on mail that has been safely delivered and is not still in tran-
sit and at risk of being bounced.  I do caution *against* leaving the au-
thor's or even the list administrator's address in the From_ line on copies
to be forwarded to other people; the forwarder should put his or her own ad-
dress there (as procmail by default arranges for the MTA to do on forwarding
actions).

  :0fwh
  | formail -IResent- -IReturn-Path: -I'From ' -ISender:
  :0fwh
  | formail

Note that it is not necessary to get rid of Reply-To:, and (except on mailing
lists that munge Reply-To:) the author's original choice will be intact.

One problem here is that if you run old mail through such an rcfile, the
original postmark time in From_ will be clobbered with the current timestamp.
You can preserve it elsewhere (and all other fields that have to be moved out
of the way for the second formail to pick up the correct address) by doing
this instead:

  MATCH # clear out any value from previous recipes

  # We're going to force formail to regenerate the From_ line, so we 
  # rename or remove everything with more precedence than From:.
  :0fwh
  * 1^0 ^\/Return-Path:
  * 1^0
  | formail -iResent- -IReturn-Path: -R 'From ' Old-From_: -iSender:

  :0fwh # generate new From_ and restore original Return-Path: if it had one
  | formail ${MATCH:+-I"$MATCH"}

Here is another approach that uses formail and sed instead of two formails;
it leaves everything else alone, including the timestamp, and clobbers the
From_ address with the From: address.  The original From_ address remains
in the Return-Path: header:

  savemetas=$SHELLMETAS
  SHELLMETAS

  :0h
  AUTHOR_ADDRESS=| formail -IReply-To: -IResent- -rtzxTo:

  :0fwh
  | sed "1s/^From [^ ]*/From $AUTHOR_ADDRESS/"

  SHELLMETAS=$savemetas

<Prev in Thread] Current Thread [Next in Thread>