procmail
[Top] [All Lists]

Re: procmail writing vars to file

1999-04-09 08:50:06
There's already a program that serves that purpose: echo.  You'll also
need the 'i' flag on the recipe to avoid problems due to the program in
the action (echo) never reading its input:

      :0 wi:
      * ^Subject:[    ]\/[^   ].*
      | echo "$MATCH" >>$HOME/BHmail_log

If you wanted to pass in multiple variables, just put them on the
command line.  Alternatively, you can make use of the fact that
procmail places all its variables in the environment, so that invoked
programs can just reference variables from the environment directly
rather than having to pass them all one by one on the command line.
(The exceptions are the punctuation and numeric variables like $?, $=,
$_, $1, $@, etc)

An observation and a question.

If the intent is to capture the subject, date, and something extracted
from the body to a log file, the method above, in which those items are
written one-at-a-time, is flawed. The problem is that, without a global
lock to serialize procmail instances, entries from one instance can be
interleaved with entries from another. There are two solutions. The
first, suggested above, is a global lock file. With low volume mail,
this may be acceptable. The other, and to my mind better, solution is
to wait until all three have been extracted and write all three
variables at once.

Now the question. Is there any disadvantage to using the existing
LOGging facility, as follows, to do this?

 oldLog=$LOGFILE
 LOGFILE=$HOME/BHmail_log
 LOG="\
Date: $DATE
Subj: $SUBJECT
Info: $INFO
"
 LOGFILE=$oldLog

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

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