procmail
[Top] [All Lists]

Re: Piping through program

1997-04-20 12:28:00
allad000(_at_)goofy(_dot_)zdv(_dot_)uni-mainz(_dot_)de (Dirk Allard) writes:
I have the following problem:

      A mail with a given Subject should be piped
      through a program which produces an output
      on stdout. This output should be sent to the
      originator of the mail, the mail should be
      appended to folder xyz.

Anybody who can help me?


Exactly what do you need to pipe through the program?  Just the body?
If so, then it's easy:

        # Does the Subject: match?
        :0
        *   ^Subject: given
        * ! ^X-Loop: allad000(_at_)goofy(_dot_)zdv(_dot_)uni-mainz(_dot_)de
        * ! ^FROM_DAEMON
        {
            # First, take care of the appending to folder xyz
            :0
            xyz

            # Pipe the body through some program
            :0 fb
            |/some/program

            # Generate the reply and sent it out
            :0
            |formail -rkbA"X-Loop: 
allad000(_at_)goofy(_dot_)zdv(_dot_)uni-mainz(_dot_)de" | \
                $SENDMAIL $SENDMAILFLAGS -t

        }

The X-Loop: stuff is to keep a loop from forming and filling your xyz
mailbox (and melting down your mailserver).

Now, if you need to pipe the entire message through the program, it's a
little more complicated, as formail needs a copy of the header to generate
the header for the reply.  The solution is to generate the reply header
first, capturing formail's output in a variable.  Replace the last two
recipes above with:

            # Capture the reply header
            :0 h
            HEADER=|formail -rkbA"X-Loop: 
allad000(_at_)goofy(_dot_)zdv(_dot_)uni-mainz(_dot_)de"

            # Feed the message through the program and generate the reply
            # in one feel swoop:
            :0
            |(echo "$HEADER"; /some/program) | $SENDMAIL $SENDMAILFLAGS -t

Does that make sense?

Philip Guenther

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