procmail
[Top] [All Lists]

Re: Name of the delivered file of a message - MH

2000-03-23 09:23:21
Jacku <jereecho(_at_)yahoo(_dot_)com> writes:
Now I want to record details ( and also add some
additional headers ) on incoming messages, so I invoke
another program from procmail which will parse my mail
( on stdin ) and extract various fields like
From,To,Subject etc., and also add one or two
additional headers and log all these in a log file. 
It then pipes out the entire message on to stdout. 
Now procmail gets this modified message and continues
with processing.

The issue is I also want to log the name of the file
in which the mail finally gets stored ( the MH file
number ).  

Any way I can do that ?

Procmail doesn't know the MH message number until it actually does the
delivery (after all some other program could deliver a message in the
mean time).  Once it does the delivery it puts the path to the file in
the variable LASTFOLDER.

So, while getting the number to the filter program is possible, it would
take some real trickery.  If logging it separately is fine, you can just
add the 'c' flag to the current delivering recipe (so that procmail will
continue processing) and then extract the message number from LASTFOLDER
and log it wherever.

        :0 c
        some/mh/folder/.

        # If we successfully delivered the message
        :0 a
        {
                # file path is in LASTFOLDER.  Extract the final number
                :0
                * LASTFOLDER ?? /\/[0-9]+$
                { NUMBER = $MATCH }

                LOGFILE = some-logfile
                LOG = "New message in some-mh-folder, number $NUMBER
                "
                LOGFILE = /dev/null     # Don't log anything else to this file
                HOST                    # we're done, so stop processing
        }

        # The delivery failed, argh!
        EXITCODE = 73          # EX_CANTCREAT
        HOST


This also has the advantage of not logging the message number if the
delivery fails.


Philip Guenther

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