[Top] [All Lists]

Re: Store body in file and execute script

1999-02-01 13:46:17
Menco Bolt <mjbolt(_at_)lucent(_dot_)com> writes:
Hiya all,

Sorry for asking, but I read a lot of page's about procmail, but I can't get i
right. All I want to do is store the body in a file and then start a shell
script. The script doesn't need any input, it just needs to get started. The
message can be deleted. So this is what I did until now:

:0 b
* ^TOmjbolt
* ^From: mjbolt
* ^Subject:.*CPR_CREATE
 :0 c:

 :0 c
 | /home/mjbolt/bin/cpr/

but then i get the message anyway. How do I solve this ? 

The recipe that starts the shell script has the 'c' flag, so a copy of
the message is delivered to the shell script, but the original falls
through and continues through the rest of the rcfile.  If you don't
want that, pull the 'c' flag.

Next, the 'b' flag has no effect on nested block recipes.  You have to
put it on the recipe that actually saves the message.

Finally, if the shell script doesn't need any input, you should put the
'i' flag on the recipe, so that procmail knows that it isn't an error
when the program doesn't read the entire message.

Now for a warning: if the program is going to look at the cpr_create
folder to process the message just delivered to it, then you'll need to
put a lockfile around the entire region.  Otherwise, if two messages
arrive in quick succession, they could both be delivered to the file
before the program is started:

 |      mail 1 arrives
 |                                      mail 2 arrives
 V      delivered to cpr_create
                                        delivered to cpr_create runs

If that would be a problem, then take the lockfile off of the storing
to cpr_create and use a regional LOCKFILE around both the inside recipes:

        * ^TOmjbolt
        * ^From: mjbolt
        * ^Subject:.*CPR_CREATE
        {   # Lock the cpr_create mailbox for now
            LOCKFILE = cpr_create.$LOCKEXT

            # Save a copy of the body to the cpr_create mailbox under
            # the above lock
            :0 bc

            # If the save was successful, run the program.
            # It doesn't read stdin, but we should check it's exit status.
            :0 aiw
            | /home/mjbolt/bin/cpr/

            # If the save and the program execution were successful, then
            # we don't reach here.  Procmail doesn't the unlocking when it
            # exits.  If we did reach here then either the save failed or
            # the program failed.  Unlock the mailbox and let the failed
            # message drop through to the rest of the rcfile.

If that seems too complicated, change to accept the message
body on stdin and do the saving itself (this is probably the better way
to go).

Philip Guenther

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