procmail
[Top] [All Lists]

Re: Grab all headers as a variable

2001-08-01 11:08:18
Kip Turk <kipt(_at_)wcc(_dot_)net> writes:
I'd like to add the original headers when I warn a sender that I denied
their message due to a virus.  I know it's quite trivial to pass just the
headers, but I can't find a simple way to store them all.  Here's the jist
of what I'm after:

:0
< various checks >
{
       :0h
       | (formail -r -I "Subject: Virus/Worm Infection"; \
       echo "You recently sent a message to one of our users that contained a
 virus."; \
       echo "The headers of your original message were: "; \
       echo "$VAR"; \
       echo "To clean the virus, please see $PAGE"; \
       ) | /usr/sbin/sendmail -t
       /dev/null
}

I see it dropping in to the last recipe properly, but I can find an easy
way to throw in the old headers at $VAR.  Everything I checked showed
breaking the headers out singly into variables.  Is this the only way to
go about it?  I also found how to drop the headers into a file and cat
that into the message, but then I'm forced to spawn another process to
wipe the file after each message.

As Matt Dunford pointed out, you can do something like:

        VAR = `formail -X ""`

Slightly more efficient is the variable capture syntax, as we can tell
procmail to feed only the header to the program and just use "cat":

        :0 hw
        VAR=|cat

That also has the advantage of not being subject to the LINEBUF limit:
if the header is more than $LINEBUF bytes long, the "VAR = `formail..."
version will choke and procmail will give up on the rcfile.


A slightly more efficient solution is to generate the auto-reply header
into a variable and put the headers into the message directly:

        :0 hw
        RH = |formail -r -I "Subject: Virus/Worm Infection" \
                -A "X-Loop: kipt(_at_)wcc(_dot_)net"

        :0 h
        | ( echo "$RH"; echo "You recently..."; \
            cat -; \
          ) | $SENDMAIL $SENDMAILFLAGS -t


The auto-reply header is smaller than the original headers, so the above
minimizes the copying.  It also can easily be changed to include the
entire original message (not a good idea in this case, but useful in
other situations).

Oh, and don't need to put "/dev/null" after the recipe; it's a delivering
recipe, so procmail stops right there.  If procmail did get past there
then it would call the "/dev/null" a syntax error as it's neither a
recipe nor a variable assignment.


Philip Guenther

_______________________________________________
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>