procmail
[Top] [All Lists]

RE: on thin ice: using $COMSAT to decide how procmail was invoked

2003-03-08 00:50:03
"David W. Tamkin" <dattier(_at_)panix(_dot_)com> writes:

Jeff Orrok wrote,

| My interpretation of the procmailrc man page suggests that I could test
| $COMSAT to determine whether the .procmailrc was invoked manually on the
| command line or automagically by the MTA; however, my spider-sense is
| warning me to be beware of relying on such a side effect.

If you haven't yet assigned the LOGFILE variable, stderr will still point to
whatever destination was inherited from procmail's parent.  So if you've
invoked procmail from an interactive shell,

 * ? test -t 2

will pass; if procmail was invoked by the MTA either from the LDA definition
or from a pipe in ~/.forward or the alias file, or if procmail was invoked by
cron, stderr will not point to a terminal and that same condition will fail.

But note that once you assign LOGFILE to a file, or you make it null (just
LOGFILE= with no filename) or you unset LOGFILE, that distinction will be
lost, and it cannot be recovered.  So you have to save the initial condition
in a variable near or at the top of .procmailrc:

 INTERACTIVE=no
 :0
 * ? test -t 2
 { INTERACTIVE=yes }

And if /etc/procmailrc messes with the LOGFILE variable before you can do
that, well, you're out of luck.

I guess I'm lucky.  This system has no /etc/procmailrc.  So this solution
works, especially for the case in which the rcfile to be tested is not
included on the command line, in which case, $COMSAT is *not* off, and so
causes my test to leave $TEST unset instead of defaulting to "on".

Thanks!

Jeff

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