procmail
[Top] [All Lists]

Re: Procmail doing neat-o things.

2000-07-26 05:15:27
At 07:07 2000-07-25 -0400, Jason Slagle wrote:

[snip]
Anyone have any clue how to either 1)  Make the body available to my
program sending the emails so I can deliver the email myself, or 2, still
fork off to sendmail, but make procmail drop through to the next message.

I don't understand what you're asking in #1 - are you wanting to "deliver the mail" to the notification address, or as the reply? I assume you mean the bad code notification to the admin. Further, #2 is puzzling as well -- procmail doesn't "drop through" to the next message -- it is invoked separatley for each message (i.e. they all start at the top of the recipes) -- or are you referring to the next COPY you're going to send (again, to the admin)? If the latter, see my recipe below, which uses the 'c' flag to duplicate the message for the admin.


Use of the 'e' flag could be of use if you restructured your processing code (make the code processing block a FILTER, and then use the 'e' flag to determine if it succeeded or not), which ultimatley is probably what you're wanting to do.

You'll need to change your shell script to return an error condition if the code doesn't match (BTW - your shell script has a glaring bug -- XXDIR isn't used, instead you're using $XX):

#!/bin/sh
# Takes given argument and echos the code text, or error message.
XXDIR=$HOME/xx/xx/
CODE=$1

if [ -f $XXDIR/$CODE.txt ]; then
        cat $XXDIR/$CODE.txt
else
        # exit code is arbitrary, but nonzero means error condition
        # (this is necessary so that procmail can sense the failure)
        # error message is handled by procmail
        exit 1
fi


Now, you'd write the filter like so (note that 'h' is missing from the outermost flags -- it was meaningless). The brackets after subject contain a space and a TAB:

:0
* ^TOxx(_at_)xx(_dot_)net
* ^Subject:[    ]JSTEST1.*test/\/[^ ]+
* !^FROM_DAEMON
* !^X-Loop: xx(_at_)xx(_dot_)net
{
        # first, apply filter to headers that will apply for following
        # rules (globally handles the X-Loop for instance - including for the
        # copy sent to the admin, in case the admin is actually at THIS
        # address).
        :0fh
        | formail -I"Precedence: bulk" \
        -A"X-Loop: xx(_at_)xx(_dot_)net"

        # filter BODY - replaces the body text.  Ignore write errors
        # (conditions where the whole body is not read by the script)
        :0fbiW
        | $REPLYDIR/xx.procexp $MATCH

        # If the above filter failed (due to the exit code)
        :0e
        {
                # unfortunatley, the error text appears AFTER the body.
                # remove the 'k' flag if you don't want the original body
                # thrown back to the user.
                :0c
                | (formail -rtbk -I"From: <xx(_at_)xx(_dot_)net>" ; \
                 cat $REPLYDIR/unknown.txt ) | $SENDMAIL -oi -t

                # continue the above - send the message to the admin
                # (note that loop header is already handled)
                :0
                !adminaddr(_at_)xx(_dot_)net
        }

        # regular result - send the reply to the user.
        # KEEP the 'k' flag here, since the body was replaced by the
        # filter above...
        :0
        | (formail -rtbk -I"From: <xx(_at_)xx(_dot_)net>") | $SENDMAIL -oi -t
}


I've only performed a cursory test of this code, and it looks like it should do what I'm interpreting you're asking for. No guarantees.

---
 Please DO NOT carbon me on list replies.  I'll get my copy from the list.

 Sean B. Straw / Professional Software Engineering
 Post Box 2395 / San Rafael, CA  94912-2395


_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

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