procmail
[Top] [All Lists]

Re: Archiving mail

1997-11-13 14:47:53
    6.2 Using dates

        Calling `date' in your procmail script _many_ times is not a good 
idea.
        Few times won't hurt, like below where we save one exra call.

            YYYY    = `date "+%Y"`
            MM      = `date "+%m"`
            DD      = `date "+%d"`

            :0
            * YYYY ?? ..\/..
            { YY = $MATCH }

            TODAY   = "$YYYY-$MM-$DD"       # ISO standard time: eg. 
1997-12-01

        You can also look the date from the first received header that will
        be same each time in your system. That could be a good alternative
        if you receive lot of mail and thus extra shell call should be
        avoided. There is two date packages available:

Why invoke date three times (if you decide to invoke it at all)? A much
(almost 3x) more efficient solution is hinted at in your match recipe
(off the top of my keyboard, uppercase what thou wilt:

  date=`date "+%Y %m %d"`  ## and add %H:%M%S if you want these as well
  :0
  * date ?? ^^..\/..
  { yy=$MATCH }
  :0
  * date ?? ^^.....\/..
  { mm=$MATCH }
  :0
  * date ?? ()\/..^^
  { dd=$MATCH }

If you are not in the same time zone as your server, and you want an
accurate report of the date, you might amend the invocation to the
following:

  date=`TZ="KDT9:30KST10:00,64/5:00,303/20:00";date "+%Y %m %d"` 

Of course, if you are concerned about efficiency, parsing the From_ or
first Received: header (if the format is unchanging and provides the
needed information) is probably orders of magnitude faster. It is no
more complex than the parsing of the date string above, although you
can use scoring to convert the abbreviated month name to a number
(which to some is more complex).

-- 
Rik Kabel          Old enough to be an adult              
rik(_at_)netcom(_dot_)com

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