procmail
[Top] [All Lists]

Re: Non Y2K compliant MUAs ;-{

2000-01-05 06:25:37
On Tue, 4 Jan 2000 16:23:56 -0500 (EST),
Richard A Nelson <cowboy(_at_)vnet(_dot_)ibm(_dot_)com> wrote:
Date: Mon, 03 Jan 00 18:48:10 -0500
I'd like to change the 00 to 2000

The problem with under-specific dates generally is that you can't
blindly just go and change them to something more specific, because
the information that is missing is, uh, missing.

If you can come up with a reasonably tight regular expression to fix
this under your particular circumstances, it's not very hard, though.

    :0fhw
    * ^Date:[   ]*(Mon|T(ue|hu)|Wed|Fri|S(at|un)),? [ 0-3][0-9] \
             (J([au]n|ul)|Feb|Ma[ry]|A(pr|ug)|Sep|Oct|Nov|Dec) [01][0-9] \
            [ 0-2][0-9]:[0-6][0-9]:[0-6][0-9] [+-]?[01][0-9][034][05]
    | sed -e \
's/\(same rx up to month name\)\([01][0-9] [0-2][0-9]:[0-6][0-9]:etc\)/\120\2/'
    # Wrapped on two lines to keep this under 80 chars; not strictly necessary

A complication is that all versions of sed don't grok parentheses and
alternation so you probably can't use +exactly+ the same regex as in
Procmail. It would be convenient to use $MATCH here but alas, $\MATCH
is not directly usable in sed, either, and if you don't substitute
special characters, you can't be completely safe, either. Perhaps like
this, though:

    :0fhw
    * ^Date:yada yada yada up to \/[01][0-9] [ 0-2][0-9]:[0-6][0-9]:[0-6][0-9]
    | sed -e '/^[Dd][Aa][Tt][Ee]/!b' -e "s/$MATCH/20$MATCH/"

This should work, provided that the date header doesn't use additional
colons anywhere. Perhaps you can put the earlier expression as the
first condition, and then the grabbing variant of it as the second
condition; Procmail should look at the same header both times (and
incoming messages will probably never contain two Date: headers if
you're using Sendmail, because it will "helpfully" rewrite anomalous
messages).

This is not completely foolproof. For example, it does not cover the
(theoretical) case of a Date: header which is folded over several lines.

Whose MUAs are you trying to "fix"? If they're local users, offer them
the alternatives to burn at the stake or switch to a working MUA. If
they're incoming messages from other sites, I don't see any compelling
reason to fix them, other than if your own MUA has trouble dealing
with troublesome dates (in which case +it+ is broken, no matter how
wicked that sounds; anyway, in that case, perhaps you want to insert
an X-Old-Date: header with the original date, to keep yourself
informed and to be safe even if your script occasionally misfires).

Hope this helps,

/* era */

-- 
 Too much to say to fit into this .signature anyway: <http://www.iki.fi/era/>
  Fight spam in Europe: <http://www.euro.cauce.org/> * Sign the EU petition

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