On 6-Feb-2007, at 16:15, ignotus(_at_)freemail(_dot_)hu wrote:
Hello, rarely I get mail "from the future" (the Date header carries a
date that is in the future). In this case, I would like to replace
the
Date header with the current date from procmail, how can I do that? I
am sure lot of people would like to have a solution for this.
I wrote a fixdate routine (well, the list wrote it, really, I just
asked incessant questions for several months until it got to the
point it worked for me). I used this to process several thousand old
emails into a new hierarchical mail spool, but haven't really used it
much since. On my "Lists" account I run every message through it
though, so that threaded mails get threaded correctly.
% cat .datefix
# Change this to match you mailserver
WHICHRECVD = 'by [^ ]*(mail.)?covisp.net'
WEEKDAYS = '(S(un|at)|Mon|T(ue|hu)|Wed|Fri)'
MONTHS = '(J(an|u[ln])|Feb|Ma[ry]|A(pr|ug)|Sep|Oct|Nov|Dec)'
YEARS = '(199[0-9]|20[0-9][0-9])'
TIMESTAMP = '([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]'
# dates between 1990-2099 ok. Adjust following as needed.
# NB: DATE is only trusted from the WHICHRECVD server.
# proper Received header, should work 100% of the time.
RCVD_STAMP = "$WEEKDAYS, [0-9]+ $MONTHS $YEARS $TIMESTAMP"
# improper Received header, handles "Tue, 01" and "Tue, 1"
# ONLY use this version if your mailspool includes messages
# with improper headers on the WHICHRECVD line
#RCVD_STAMP = "$WEEKDAYS, +[0-9]+ $MONTHS $YEARS $TIMESTAMP"
# Get the received header I want the date from
# (when the message hit my mailsserver)
:0
* $ ^Received:.*$WHICHRECVD.*\/$RCVD_STAMP
{ xDATE = "$MATCH" }
# short-circuit w/o data
:0fw
* xDATE ?? ^^^^
| formail -i"X-Date-Munge: FAILED"
# If we didn't bail out early...
:0 E
{
# Build the new "From " header by extracting the date in the
# right order from xDate
# From: Sun, 02 Mar 2003 08:29:12
# To: Sun Mar 2 08:29:12 2003
:0
* $ xDATE ?? ^^\/$WEEKDAYS
{ ENVELOPE = "<$CLEANFROM> $MATCH" }
:0
* $ xDATE ?? ^^$WEEKDAYS, +[0-9]+ \/$MONTHS
{ ENVELOPE = "$ENVELOPE $MATCH"
MYMONTH=$MATCH
}
:0
* $ xDATE ?? ^^$WEEKDAYS, +\/[0-9]+
# { ENVELOPE = "$ENVELOPE $MATCH" }
# If you are using the broken RCVD_STAMP Comment out
# the previous line and uncomment this block
{
PADD = "0"$MATCH
:0
* PADD ?? ...
{
:0
* PADD ?? ^^.\/..
{ PADD = $MATCH }
}
ENVELOPE = "$ENVELOPE $PADD"
}
:0
* $ xDATE ?? ()\/$TIMESTAMP
{ ENVELOPE = "$ENVELOPE $MATCH" }
:0
* $ xDATE ?? $MONTHS \/$YEARS
{ ENVELOPE = "$ENVELOPE $MATCH"
MYYEAR=$MATCH
}
# Make sure the $ENVELOPE matches the desired format
# If it does, rewrite the From_
:0 fhw
* $ ENVELOPE ?? $WEEKDAYS $MONTHS [0-9]+ $TIMESTAMP $YEARS^^
| sed "s,^\(From \).*,\1$ENVELOPE,"
# And add a header showing we've altered the message
:0 afw
| formail -i"X-Date-Munge: SUCCESS"
# Otherwise, show that the attempt failed.
:0 efw
| formail -i"X-Date-Munge: FAILED"
MONTHSTRING=Jan01Feb02Mar03Apr04May05Jun06Jul07Aug08Sep09Oct10Nov11Dec12
:0
* $ MONTHSTRING ?? $MYMONTH\/..
{ MYMONTH=$MATCH }
MYDATE=$MYYEAR-$MYMONTH
# If the message is not from the current month and year, mark it
read
:0fw
* 9876543210^0 ! $MYYEAR ?? $CYEAR
* 9876543210^0 ! $MYMONTH ?? $CMONTH
| formail -I"Status: RO"
}
--
sometimes ascii is the best use of bandwidth... Tonya Engst
____________________________________________________________
procmail mailing list Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail