procmail
[Top] [All Lists]

Re: Forcing valid date format in headers?

2001-04-06 14:14:23
Back on 23 March 2001, Alan Glover wrote:

I get some email with unusual date formats, eg:

Date: Wed Mar 21 07:23:08 AST 2001

I'd like to set up a procmail recipe that spots this, and rewrites the Date 
field.

What approach would you recommend, so far I've thought of looking for the 
presence of three consecutive capitals in the Date: header, and then:-

i) Use formail to mend the header I
[snip]
ii) Use formail to mend the header II
[snip]
iii) Do fancy stuff with regexps
[snip]
I'm not even sure this is possible with procmail's regexps, but I was 
thinking of matching on the AST, which I know to be -0400, and then 
re-ordering the time/date parameters into the standard layout of Wed, 21 
Mar 2001 11:36:48 -0400

Use GNU date; get it if you don't have it.  It's pretty tolerant of
offbeat date formats, and does indeed handle the one you gave.

You can extract with the MATCH operator, and then replace with formail,
something like this:
    # wherever GNU date is, unless it's the first date in your path:
    GDATE=/usr/local/bin/date

    :0
    * conditions which identify "bad" dates
    * ^Date: *\/[^ ].*
    {
        DSTR=`$GDATE --date="$MATCH" "+Date: %a, %d %b %Y %H:%M:%S %z"`
        :0f
        | formail -i "$DSTR"
    }
    ... continue here with modified Date header ...

(I used "-i" to leave an "Old-Date:" header; use -I if you don't
want that.)

HTH,
Stan
_______________________________________________
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>