procmail
[Top] [All Lists]

Re: Executing programs

1997-05-11 05:31:00
On Sat, 10 May 1997 10:11:29 +0000, "Larry Canter"
<Larry(_dot_)Canter(_at_)gridsat(_dot_)thegrid(_dot_)net> wrote:

(You wouldn't happen to be married to someone named Martha? :-)

I need to save e-mail to a file(stripping out the headers), and then 
call a program with the file-name as an argument.  Saving the mail to 
a file is no problem, but I can't get the program to execute.  Recipe 
 in .procmailrc looks like this:
      :0 bc
     | cat >>$HOME/filename
     | program_name filename

I've tried it using semi-colon at end of the first action, placing 
the program execution in a separate recipe, and the same thing 
happens - the file is created and that's it.

The action line can only be a single line, but it can contain several
commands. (You can splice it onto several lines by using a backslash
escape on the newlines.) You will then probably have to figure out how
to lock the file $HOME/filename (and you should name a full pathname
in both places where you reference the file) if it makes a difference
to program_name what's in the file at a certain time.

    :0bc:$HOME/filename$LOCKEXT
    * conditions for when this should be done, if any
    | cat >>$HOME/filename \
    ; program_name $HOME/filename

(The FAQ I have at http://www.iki.fi/~era/procmail/mini-faq.html
attempts to describe this file locking business a little bit, you may
want to read that.)

Finally, here's an alternative solution. The h flag on the second
recipe is there on the assumption that the header will usually be
shorter than the body of the message. The only meaning of it is to
minimize what is written to program_name, since it will ignore its
input anyway:

    :0 c
    * conditions anyone?
    {
        :0bc:
        $HOME/filename

        :0hi
        | program_name $HOME/filename
    }

If the recipe really is unconditional, you can skip the braces. 

    :0bc:
    $HOME/filename

    :0hic
    | program_name $HOME/filename

Perhaps you could code program_name or write a simple wrapper script
around it so it will accept the current message on standard input and
add it to the end of the data file itself. This will encapsulate the
action nicely and presumably make the thing more self-contained. 
  (You also rid yourself of the aesthetic glitch of copying and piping
stuff into a program which ignores the data you pipe to it. Procmail
currently has no really idiomatic way of simply executing a program in
its own right, without feeding it the current message on standard
input. It's easily done with a | action with an i flag but this
construct sort of bothers me ... It would be nice with a new action
line directive for this purpose. Stephen, are you listening?)

Hope this helps,

/* era */

-- 
Defin-i-t-e-ly. Sep-a-r-a-te. Gram-m-a-r.  <http://www.iki.fi/~era/>
 * Enjoy receiving spam? Register at <http://www.iki.fi/~era/spam.html>

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