procmail
[Top] [All Lists]

Re: Forwarding and Appending

1998-04-29 02:05:25
On Tue, 28 Apr 1998 17:03:40 -0500 (EST), Sridhar Kompella
<kompella(_at_)ecn(_dot_)purdue(_dot_)edu> wrote:
I have this list which scans for the subject and forwards the
mail to a list of addresses. I want to append a few standard lines 
of text to each such mail before forwarding - like one could while 
auto-replying using formail and echo etc..

Perhaps this should go in the FAQ.

The generalized extension of the standard forward recipe:

    :0
    * conditions ...
    ! address1 address2 address3

is to pass the message through a pipe (typically, formail):

    :0
    * conditions ...
    * ! ^X-Loop: you(_at_)yourdomain\(_dot_)com
    | formail -A "X-Loop: you(_at_)yourdomain(_dot_)com" -other -formail -stuff 
|
      $SENDMAIL $SENDMAILFLAGS address1 address2 address3

This is more general because you can do stuff to both the headers and
the body by adding more commands to the pipeline. In your case, you
could use sed to add a few lines to the beginning of the body:

    NL="
"
    :0
    * conditions ...
    * ! ^X-Loop: you(_at_)yourdomain\(_dot_)com
    | formail -A "X-Loop: you(_at_)yourdomain(_dot_)com" | \
      sed -e '1,/^$/{' -e '/^$/a\'"$NL\
   These lines were added by a helpful sed script.\\$NL\
   Enjoy,\\$NL\\$NL\
   /* era */\\$NL" -e } | \
      $SENDMAIL $SENDMAILFLAGS address1 address2 address3

Trying to understand the ping-pong quoting and the backslash parsing
here will give you a headache as usual. Still, hope this helps,

/* era */

If you want to cheat and don't care that this might break in some
circumstances, you could try to do all the fiddling with formail. This
works with 3.11pre7 but I'm pretty confident it's not supposed to (-:

    NL="
"
    :0
    * conditions ...
    * ! ^X-Loop: you(_at_)yourdomain\(_dot_)com
    | formail -A "X-Loop: you(_at_)yourdomain(_dot_)com$NL\
$NL\
    These lines were added by formail.$NL\
    Enjoy,$NL\
$NL\
    /* era */" | $SENDMAIL $SENDMAILFLAGS address1 address2 address3

-- 
 Paparazzi of the Net: No matter what you do to protect your privacy,
  they'll hunt you down and spam you. <http://www.iki.fi/~era/spam/>

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