procmail
[Top] [All Lists]

Re: Adding "From_" as an X-header

1997-05-31 23:12:00
revjack(_at_)Radix(_dot_)Net (revjack(_at_)radix(_dot_)net) writes:
Neither of my mail clients display the "From_" envelope line, and I'm
always curious as to what it is. So I thought I would add a formail
filter at the top of my .procmailrc to pick it up and insert it into
each mail as an X-header, so I can see it in my mail client. Here is
my test recipe:

The first thing to check is whether your mail system inserts a Return-Path:
header.  That header, where it exists, should contain the same address
as the 'From ' pseudo-header.

If your mail system doesn't, provide such, or if you're also desiring to
see the delivery date, then your recipe is pretty good idea.


:0
* ^Subject.*formailtest
{
ENVELOPE=`formail -xFrom `
:0f
| formail -I"X-Envelope: $ENVELOPE"
}

This recipe does not fail or give errors, but it seems to assign both
the "From_" *and* the "From:" lines to $ENVELOPE, with a newline
between them. Mail to myself looks like this:
...
Does anyone know how to tell formail to grab only the "From_" line?

When attempting to match headers given in command line arguments, formail
will match all those which begin with what is given.  If what you put
on the command line includes a colon, then there can obviously only be
one match.  To specify the 'From ' line, you need to include the space
in what formail sees.  The reason your recipe above doesn't work is that
the space after the From isn't quoted, as is thus stripped before formail
is called.  The solution?

        :0
        * ^Subject:.*formailtest
        {
            ENVELOPE = `formail -x'From '`      # or -xFrom' '
            :0 f
            |formail -I"X-Envelope-Line: $ENVELOPE"
        }

However, there are several efficiency improvements to be made on the
above.  One is to filter only the header through the second formail
by adding the 'h' flag to the recipe.  The more interesting one is to
use procmail to extract the 'From ' pseudo-header's value:

        :0 fh
        * ^Subject:.*formailtest
        * ^^From +\/[^ ].*
        |formail -I"X-Envelope-Line: $MATCH"

No muss, no fuss, no fork/exec yellow stain.

Philip Guenther

<Prev in Thread] Current Thread [Next in Thread>
  • Re: Adding "From_" as an X-header, Philip Guenther <=