procmail
[Top] [All Lists]

Re: Modifying message body via procmail

1997-10-27 08:22:16
Walter Dnes asked,

|     What I'm trying to do... is to put a string at the
| beginning of the message body.

OK ... common thing to do, easily done.

| :0Hiw:

A couple problems already: `H' without `B' is the default; `i' is meaningless
when the action is to open braces; and when the action is to open braces
but not to launch a clone, `w' is meaningless and a local lockfile is
impossible (you'll get an error message, in fact).

| * ^Subject:.*//SYSTEST
| {
| :0bic
| BODY=`|cat`

`c' is superflous there, `i' is risky and the backquotes will mess things up.
The syntax should be

 :0b
 BODY=|cat

However, ...
 
| INSERT="I: have inserted this line into the message."
| 
| :0hf
| |(cat; echo $INSERT; echo $BODY)

If you filter only the head and replace it with all of that, you'll end
up with two copies of the original body when procmail reattaches it.

| }

There is a much better way to handle this.

  :0bfw # did you also want D here?
  * ^Subject:.*//SYSTEST
  | echo "I: have inserted this line into the message." ; echo "" ; cat

It filters the body (`b' and `f'), leaving the head unchanged.  Since
the two echo commands don't use any stdin, the entire original body is
fed cat and put after the echoed lines.  After filtering the body, procmail
will reattach the unchanged head.

If the messages on which this recipe will run tend to have heads smaller
than their bodies, this is better yet.  It will put the new text at the
end of the head with a blank line in between.  After procmail reattaches
the old body to the new head, the two new lines at the foot of the head
will end up in the new body:

  :0hfw # did you also want D here?
  * ^Subject:.*//SYSTEST
  | cat; echo "I: have inserted this line into the message." ; echo ""
 
Perhaps I should illustrate.  Both of these recipes have the same effect:

before the filter --

  original head
  a blank line
  original body

after the filter --

  original head
  same blank line from before
  I: have inserted this line into the message.
  newly added blank line
  original body

so the new body consists of this --

 I: have inserted this line into the message.

 original body

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