procmail
[Top] [All Lists]

Re: most efficient way to get rid of all headers except 3

2001-12-30 02:17:55
"Gary Funck" <gary(_at_)Intrepid(_dot_)Com> writes:
Timothy J. Luoma writes:
...
In a certain recipe, I would like to get rid of all headers except:

From
Subject
Date

All the headers will exist for all messages.
...
You might try the following recipe:

:0 fhw
| (formail -X From -X From: -X Subject: -X Date: ; echo "")

The "-X From" is optional, but needed if you want the resulting message
to be well-formed. Likewise the 'echo ""' is needed to ensure that the
header terminates with a blank line.

The "-X From" should include a quoted space to avoid matching on any
header field that starts with "From".  The echo can be eliminated by
instead giving formail the -k option, so that it will preserve the blank
line that ends the header:

        :0 fhw
        | formail -X"From " -XFrom: -XSubject: -XDate: -k

Since procmail can invoke formail in that action directly without using
a shell, it'll be more efficient.

Good job, Gary, catching the need for the "From " and blank lines.


...
Optionally, you can use egrep:

:0 fhW
| egrep -i '^(From |From: |Date: | Subject:|$)'

This doesn't handle continued header fields, so I would recommend
against it.


Philip Guenther
_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

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