procmail
[Top] [All Lists]

Re: formail and multiple tasks

1995-10-12 15:13:40
Hal Wine suggested to pse(_at_)ix(_dot_)netcom(_dot_)com,

| >          It struck me that if you remove the separator line, that you
| >          can simply 'cat' additional header lines into the stream,
| >          which is a LOT easier than having to give formail lots of
| >          options.
| 
| If I understand your need, you really just want to modify the headers.
| Just use the 'h' (headers only) flag when you filter your header:
| 
| :0 hf
| * whatever
| | $FORMAIL -rt | cat - $HOME/newHeaders
| 
| This sends only the headers ('h' option) to first formail to play with
| them.  Formail's output is the sent to cat, which replicates them, followed
| by the new headers.  The result is used to replace the original headers
| ('f' option)

Procmail and formail treat the separating blank line as part of the head;
Hal's recommendation (which also depends on having defined $FORMAIL; I
prefer to define $PATH and let procmail find formail) will append the
header lines in $HOME/newHeaders after the blank line and make them part
of the body.

This might work:

   :0hf
   * whatever
   | $FORMAIL -rt -X "" ; cat $HOME/newHeaders ; echo

If $HOME/newHeaders ends in a blank line, you don't need the "; echo".
Under some circumstances procmail puts back the blank separating line if
it gets lost, but I'm not sure exactly what those are, and you have a
SHELLMETAS character in there already (the first semicolon), so a shell
is forked anyway.

But this is my favorite way (it assumes that formail -r will never generate a
continuation line for From:); if you use it, make sure that the newHeaders
file does NOT contain a trailing blank line:

 :0hwf
 * whatever
 | $FORMAIL -rt
 :0Awfh
 | sed "/^From:/r $HOME/newHeaders"

Look, Ma, no shells!

If I ever think of an easy way to make sed pinpoint the last non-blank line
(sed's `r' instruction, unfortunately, copies the named file to output below
the current line and cannot be made to copy the file to output above the
current line, so once you find the blank line that terminates the head, it's
too late), I'll modify the suggestion accordingly.  One can terminate the
file with a blank line and do this, but I would hate to ask people to copy
or even paste this sed code:

  sed -e N -e '/\n$/ba' -e P -e D -e :a -e 's/.$//' -e "r $HOME/newHeaders"

One could shorten it to this, I guess:

  sed -e N -e '$ ba' -e P -e D -e :a -e 's/.$//' -e "r $HOME/newHeaders"

This has already gotten messy enough, because some of these ideas forbid a
blank line at the foot of the newHeaders file and some require it.

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