procmail
[Top] [All Lists]

Re: Regenerate From_ with Date in formail

2003-03-02 09:57:42
On Friday, Feb 28, 2003, at 17:54 Canada/Mountain, Don Hammond wrote:
You've added some needs since your original message.  There is an
example rcfile and suggested usage and testing for the first request at:

http://www.xray.mpe.mpg.de/mailing-lists/procmail/2003-02/msg00544.html

I went ahead and put this in production, though there were a few typos in the message you posted (besides the doubled :0). I also added some comments.

Maybe you should add this to the mythical CVS repository? I think it's a great learning tool for matching. And it's marginally useful, which is always a plus.

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)'
# A string or regex to identify WHICH received header to take the date from
WHICH_RECVD = 'by southgaylord.com'
# YEARS = '(199[0-9]|200[0-3])'  <-- what I'm using
YEARS = '(19[89][0-9]200[0-3])'
TIMESTAMP = '([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]'
# dates between 1980-2003 ok. Adjust following as needed.
RCVD_STAMP = "$WEEKDAYS, [0-9]+ $MONTHS $YEARS $TIMESTAMP"

# <space><tab> in [character class] below
:0
* ^Return-Path:[        ]*<\/[^>]*>
* MATCH ?? ^^\/[^>]*
{ RETURNPATH = "${MATCH:-MAILER-DAEMON}" }

# Get the date from the right received header
# (in this case when the message hit my mailserver)
:0
* $ ^Received:.*$WHICH_RECVD.*\/$RCVD_STAMP
{ xDATE = "$MATCH" }

#LOG=$xDATE$NL

# short-circuit w/o data
:0fw
* 1^0 RETURNPATH ?? ^^^^
* 1^0 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 = "$RETURNPATH  $MATCH" }
   :0
   * $ xDATE ?? ^^$WEEKDAYS, [0-9]+ \/$MONTHS
   { ENVELOPE = "$ENVELOPE $MATCH" }
   :0
   * $ xDATE ?? ^^$WEEKDAYS, \/[0-9]+
   { ENVELOPE = "$ENVELOPE $MATCH" }
   :0
   * $ xDATE ?? ()\/$TIMESTAMP
   { ENVELOPE = "$ENVELOPE $MATCH" }

   :0
   * $ xDATE ?? $MONTHS \/$YEARS
   { ENVELOPE = "$ENVELOPE $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"
}

--
Love seeketh not itself to please
Nor for itself hath any care
But for another gives it's ease
And builds a heaven in Hell's despair


_______________________________________________
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>