procmail
[Top] [All Lists]

Check for RFC822 Date

1999-11-07 16:03:30
Hi,

I have tried to create a recipe that looks for a non RFC822 compliant
Date field in the header of a message.

The variables and the recipe:

  day        = "(Mon|Tue|Wed|Thu|Fri|Sat|Sun)"
  digit      = "[0-9]"
  month      = "(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)"
  date       = "$digit?$digit $month $digit$digit"
  hour       = "$digit$digit:$digit$digit(:$digit$digit)?"
  zone       = "(UT|GMT|EST|EDT|CST|CDT|MST|MDT|PST|PDT|([A-I]|[K-Z])) (+|-) 
$digit$digit$digit$digit"
  time       = "$hour $zone"
  
  # Check for messages with invalid Date fields.
  :0
  *$ ! ^Date: ($day, )$date $time$
  {
          nl
          nl      = ${notice+"$NL"}
          notice  = "$notice${nl}X-Note: Did not have a RFC822 compliant Date 
field."
  }


And this is the relevant part of the RFC:


     5.  DATE AND TIME SPECIFICATION

     5.1.  SYNTAX

     date-time   =  [ day "," ] date time        ; dd mm yy
                                                 ;  hh:mm:ss zzz

     day         =  "Mon"  / "Tue" /  "Wed"  / "Thu"
                 /  "Fri"  / "Sat" /  "Sun"

     date        =  1*2DIGIT month 2DIGIT        ; day month year
                                                 ;  e.g. 20 Jun 82

     month       =  "Jan"  /  "Feb" /  "Mar"  /  "Apr"
                 /  "May"  /  "Jun" /  "Jul"  /  "Aug"
                 /  "Sep"  /  "Oct" /  "Nov"  /  "Dec"

     time        =  hour zone                    ; ANSI and Military

     hour        =  2DIGIT ":" 2DIGIT [":" 2DIGIT]
                                                 ; 00:00:00 - 23:59:59

     zone        =  "UT"  / "GMT"                ; Universal Time
                                                 ; North American : UT
                 /  "EST" / "EDT"                ;  Eastern:  - 5/ - 4
                 /  "CST" / "CDT"                ;  Central:  - 6/ - 5
                 /  "MST" / "MDT"                ;  Mountain: - 7/ - 6
                 /  "PST" / "PDT"                ;  Pacific:  - 8/ - 7
                 /  1ALPHA                       ; Military: Z = UT;
                                                 ;  A:-1; (J not used)
                                                 ;  M:-12; N:+1; Y:+12
                 / ( ("+" / "-") 4DIGIT )        ; Local differential
                                                 ;  hours+min. (HHMM)


So, i think this comes close to what i would like to achieve. However,
there are probably a few things that i could do better. Any suggestions?

I also have a two additional questions:
- First, can i make this recipe case sensitive. When building the vars i
  have copied the case of each of the values, but i'm not sure if case
  matters here.
- Second, all those whitespaces, can they replaced by this variable that
  is used in the Message-ID check by Philip? This was that var:
        ws         = "[  ]*(\([^()]*\)[  ]*)?"


Any suggestions? Thanks in advance.

        -Rejo.

-- 
= Rejo Zenger  [Sister Ray Crisiscentrum]               
rejo(_at_)sisterray(_dot_)xs4all(_dot_)nl
= http://mediaport.org/~sister                                  PGP: see headers
--------------------------------------------------------------------------------

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