> I have a C program that I want to use to a) modify the body of the
> message & pass the modified body back to procmail, and b) generate
> a variable which I want to pass back to procmail. To accomplish
> a) my c program will be modifying the STDIN; so, I should use
> | foo
No, that's not right. The original email expressed a need to run a
program without having the mail passed to it. That's what the recipe
above does. If the program does not read STDIN, or exits before
reading all of it, then use the 'i' flag, otherwise, procmail will
assume an error has occurred.
If you wish to "modify the body of the message", and pass it back, then
use the "fb" flags (please read procmailrc(1)):
Filterprogram should be designed to read stdin (which will be the
original email, body in this case) and write stdout (the modified body).
If the filterprogram exits with a 0 status (0 == okay), then procmail
will replace the original input body with the output of the
filterprogram. If the filterprogram exits with anything but zero,
procmail will report an "error" to the log, and "recover" the input (not
> Can I also pass a variable to procmail from the c program?
The only way to set a variable in procmail is to inherit it upon
invocation, or to do so explicitly. Child process envars are lost.
Here are the ways to set a variable:
VAR # clear the var
VAR=somevalue # set it to "somevalue"
VAR=`someprogram args...` # capture STDOUT output from someprogram
:0b # same as above, but STDIN is only the
VAR=|someprogram # body.
You could write filterprogram such that STDOUT is the modified body, and
STDERR is the value of the variable you wish to set, and save STDERR
into a file, and then read it.
VARF=/tmp/var # where to place value of the "variable"
LOCKFILE=$VARF.lock # protect tmp variable file
:0fb # filter body
|filterprogram 2>$VARF # STDOUT is new body, STDERR is variable value
VAR=`cat $VARF; rm -f $VARF`# set var to its value
LOCKFILE # release the protection
Alan Stebbens <stebbens(_at_)sgi(_dot_)com> (415) 933-6437
Digital TV, Silicon Interactive Group, Silicon Graphics, Inc. (SGI)
M/S:9L991, 2011 N. Shoreline Blvd., Mountain View, CA 94043
PGP Key Fingerprint: 94 A7 4B AB 1C F0 4D 92 DD BC B5 D7 11 A0 DC B3