procmail
[Top] [All Lists]

RE: timestamp in the procmail log?

2007-06-01 15:09:53
Instead of LOGABSTRACT, I use:

DATE=`date '+%d-%b-%Y'`
LONGDATE=`date "+%y-%b-%d %I:%M:%S %z"`
MYLOGFILE="pm-$DATE.log" LOGABSTRACT=no

TRAP='formail -l "$LASTFOLDER" ;echo "    Spam: $SPAM
Deliverd: $LONGDATE
    MATCH: $MATCH
    ";'

when a message is delivered, the TRAP gets output to the logfile

This gives me:

 From owner-postfix-users(_at_)postfix(_dot_)org  Fri Jun  1 13:17:55 2007
Subject: Re: Reject unknown Sender address
   Folder: /home/kremels/Mail/postfix-users/2007-06.postfix-
users           4638
     Spam:
Deliverd: 07-Jun-01 01:17:55 -0600
    MATCH: postfix-users(_at_)postfix(_dot_)org

Okay, but I don't see a need to run `date` twice in your
rcfile -- or even once, depending on the options you
use to call procomail in your .forward or on your system.
For example, with

  | /usr/local/bin/procmail -t -f-

we are taking advantage of the trailing hyphen on
the -f option, as explained in the man page:

 -f fromwhom
    Causes  procmail  to  regenerate  the  leading  `From  ' line with
    fromwhom as the sender (instead of -f one could use the  alternate
    and  obsolete  -r).   If fromwhom consists merely of a single `-',
    then procmail will only update the timestamp on the `From  '  line
    (if present, if not, it will generate a new one).

So we have a fresh date right there in the message.  Use it.
(We went over this a bunch years and years ago on this list.)

Here is something I've been using since 2002.  I actually
have an improved version as of 1.5 years ago, but this
one is still in use and has always worked.

#
##########################################################################
##
# Get current date-relevant info per From_ line (usu. generated by
procmail)
#
##########################################################################
##


 AWEEKDAY     = "(Mon|Tue|Wed|Thu|Fri|Sat|Sun)"
 MMtable      = "{ Jan:01 Feb:02 Mar:03 Apr:04 May:05 Jun:06
                  Jul:07 Aug:08 Sep:09 Oct:10 Nov:11 Dec:12 }"


 :0  # 030110 () save tail-end of FROM_ in order to parse DATE
 * $  ^^From .* \/$AWEEKDAY .+
 { FROM_ = $MATCH

    :0  # 021211 () find year in FROM_
     * FROM_ ?? ()\/....^^
     { THISYEAR = $MATCH }

    :0  # 021211 () find YY
     * THISYEAR ?? ()\/..^^
     { YY = $MATCH }

    :0  # 021211 () find MONTH
     * FROM_ ?? () \/...
     { MONTH = $MATCH }

    :0  # 021211 () find MM
     * $  MMtable ?? ()\<$MONTH:\/[01][0-9]
     { MM = $MATCH }

    :0  # 021212 () find DD
     * $ FROM_ ?? ()\<$MONTH +\/[1-3]?[0-9]
     *   MATCH ?? ^^..
     { DD = $MATCH }

    :0 E  # 021211 () replace space as necessary
     { DD = 0$MATCH }

    DATE = $YY$MM$DD
 }


--
dman
____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail