[Top] [All Lists]

Re: original date

2001-08-29 11:23:39
Stan Ryckman <stanr(_at_)sunspot(_dot_)tiac(_dot_)net> writes:
At 03:07 AM 8/29/2001, Philip Guenther wrote:
Here's an awk solution:
        :0 fhw
        | awk '/^Received:/ && ! seen { \
                   seen = 1; getline; while (/^[ \t]/) getline; \
               } \
               { print }'

A couple of minor nits.  First, procmail is supposed to fold the
header, so the "while" loop, though harmless, isn't needed.  Second,

Procmail's folding of header fields is only for the internal regexp
engine.  When the message is fed to a program or delivered to a mailbox,
the headers will be in their original state.  Now, you could pipe
the message through "formail -c" first, but that would lose the folds
completely and it's faster to handle it directly in awk anyway.

the "Received:" could technically be any mix of upper or lower
case.  I would use:
        | gawk 'BEGIN{IGNORECASE=1} /^Received:/ && ! seen { \
                   seen = 1; getline; \
               } \
               { print }'
(gawk, GNU's awk, is faster than most system-provided awks, and supports
IGNORECASE), but if gawk is unavailable and the available awk doesn't
support IGNORECASE, then I'd go to:
        | awk '/^[Rr][eE][cC][eE][iI][vV][eE][dD]:/ && ! seen { \

Good point.

The same considerations would apply to the perl solution, but since
I'm not nearly as familiar with perl as with awk, I'll leave that
as an exercise for the reader  :-)

Changing the /^Received:/ to /^Received:/i should be sufficient.

Philip Guenther
procmail mailing list

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