procmail
[Top] [All Lists]

Re: how do i run something _after_ the mail is delivered?

2001-10-06 10:34:07
When I posted,

That's what TRAP is for.  The command(s) in TRAP will be executed as
procmail exits, with the message as stdin and the logfile as
stderr and stdout (any of which can be redirected, of course).  I use
it, for example, to append more headers to those in the usual logabstract.

... another list member wrote to me privately to ask me to post the way I
code that.  OK, here it is:

TRAP='echo "\
$FLOG
Process-Id: $PID
__________ $HOST ${INTERACTIVE}${1+$1 }__________ ${EXITCODE-0}
"'

where, except for $HOST and $EXITCODE, all the variables are defined some-
where in my .procmailrc (possibly after TRAP is assigned, or they are
possibly changed after TRAP is assigned: that's why it's all in strong
quotes).  In particular,

 FLOG = `formail -X To: -X Cc: -X Reply-To: -X From: -X Apparently-To: \
 -X Mess -X Date: -X X-Envelope-To: -X Priority: -X Action:`

Echoing $FLOG in the TRAP appends all those headers (if they're present on
the message) to the logabstract.

 :0 # This appears before LOGFILE is defined
 * ? test -t 2
 { INTERACTIVE = "interactive " }

and

 PID=$$

(Why don't I just use "$$" instead?  Because I want the PID of the procmail
 process that's exiting, not that of the shell that was needed to run the
 TRAP when I had characters from $SHELLMETAS in it.)

I really should update the stuff about "$1" to handle "$@" now that procmail
accepts multiple -a options.

_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

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