procmail
[Top] [All Lists]

Re: original date

2001-08-29 00:26:52
"Frank" <duranicub(_at_)gmx(_dot_)net> writes:
i use procmail, fetchmail, postfix and courier-imap
fetchmail get my mail from my pop briefcases from my isp periodically (
2 minutes) But if i kill fetchmail and reactivate him par exemple after
3 hours, all Mails have the same date i readed that i must remove with
procmail the last receive-header to get the original date back
can anybody tell me how ?

Becareful how you describe you goal: you want to remove the 'last'---as
in most recent---not the 'last'---as in furthest from the top of the
header---of the Received: header fields.  (The most recent Received:
header field was added by fetchmail when it transfered it to your
machine.)  Since Received: header fields are added before previous ones,
you want to remove the first Received: header field.

<insert an bad joke about how "the last shall be first, or last">


Having waded through that tangle of words, how do we actually accomplish
it?  While formail can be used to easily remove all but the first or all
but the final of the Received: header fields, it can't do the opposite.
Instead, we'll have to use a more general tool like sed, awk, or perl.

Here's an awk solution:
        :0 fhw
        | awk '/^Received:/ && ! seen { \
                   seen = 1; getline; while (/^[ \t]/) getline; \
               } \
               { print }'


Here's a perl solution:
        :0 fhw
        |perl -p -e 'next unless /^Received:/ && ! $seen;' \
                 -e '$seen = 1;' \
                 -e 'while (<>) { last unless /^[ \t]/; }' \

(Don't use perl's \s instead of the "[ \t]" character class: you don't
want it to match the blank line that terminates the header.)

The awk solution will probably be faster, as awk is much smaller than
perl, though it probably doesn't matter.


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>