procmail
[Top] [All Lists]

Re: problem with environment variable which is lost

1997-12-14 10:28:52
"Denis B. Roegel" <Denis(_dot_)Roegel(_at_)loria(_dot_)fr> writes (back in 
October):
...
My procmail script ends with
...
:0 c:
* (^TO|^From.*)johnny
johnny-folder
 :0A
 { FOUND="$FOUND johnny" }

:0:
|rm -f headers.tmp;echo "From:" $FROM >> headers.tmp;echo "To:" $TO >> 
headers.tmp;echo "Cc:" $CC >> headers.tmp;echo "Found:" $FOUND >> 
headers.tmp;RESULT=`myfilter headers.tmp`;echo $RESULT >> result.list1

# If RESULT is non empty, put the message in `my-default' folder
:0:
#* RESULT ?? [^        ]
|echo $RESULT >> result.list2
my-default

Now, the problem is that I loose the value of RESULT, as is confirmed
by the two files result.list1 and result.list2. The first contains non empty
lines (actually some filtering function performed by the `myfilter' program)
and the second contains only empty lines.

The problem is that the assignment to RESULT occurs in a subprocesses (the
shell processing that action) and procmail therefore never sees it.  In
this case some rearranging can take advantage of another procmail action
format to solve your problem:

        :0i:result.lock
        RESULT=| (echo "From: $FROM"; echo "To: $TO"; echo "Cc: $CC"; \
                  echo "Found: $FOUND" ) > headers.tmp; \
                  myfilter headers.tmp | tee -a result.list1

The "variable=|" action format tells procmail to grab the output of the
action and store it in the variable given.  The "tee -a" command replaces
the "echo $RESULT" that previously was there; RESULT is no longer set
inside the processing of the action, so we have to sneak a copy of the
output of 'myfilter' directly.

Also, if myfilter can take its input on stdin instead of having to store
it in a file and name it on the command line, or if it can be changed to
do so, then the action gets even simpler:

        :0i:result.lock
        RESULT=| (echo "From: $FROM"; echo "To: $TO"; \
                  echo "Cc: $CC"; echo "Found: $FOUND" \
                 ) | myfilter headers.tmp | tee -a result.list1

No temporary files!


What am I doing wrong ? Besides, are there other stupid/dangerous
things in what I wrote above ?

You need the 'i' flag on both of those recipes, as neither action reads
the message being piped to it by procmail, and procmail will consider
that an error without the 'i' flag.  Also, with as complicated an
action as the one you had, I would want to explicitly name the lockfile
just so I didn't wonder which ">>" procmail looked at.


Philip Guenther

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