procmail
[Top] [All Lists]

Re: Full header with the reply

1998-02-08 21:33:15
After implementing my suggestion, Hermann Wecke wrote again:

| I have now:
| 
| old header
| new comments added explaining why the message is refused
| old message
| 
| I need:
| new comments added explaining why the message is refused
| old header
| old message

Easy enough: you have a recipe that inserts comments at the beginning of the
body.  You have a recipe that inserts a copy of the head at the beginning of
the body.

Apparently you are inserting the comments first and then the duplicate head.
Just switch the order: duplicate the head and then run the recipe that pre-
pends the comments.

| Or, maybe, I just need a few fields instead of the full header:
| Original to:, from:, date: and subject:.

I considered a number of approaches to that and settled on this one, because
it needs only one more fork (and no shells) and because it is devious.  Let's
duplicate the entire head as before and then filter the body (which starts
with a fake head) through formail; formail then thinks that the fake head is
a real one, since it doesn't see the *real* real one.

 :0fhwr # duplicate the head
 | sed -e H -e '$ G'

 :0bfw # strip second head down to specific needed fields
 | formail -bkXFrom: -XTo: -XDate: -XSubject:

Some other advantages are that it will not be tripped up by unusual capitali-
zations (like "TO:" or "subject:") nor by continuation lines in those header-
fields.  [It also worked without the `r' flag but `r' makes me feel safer;
the formail call probably doesn't need the -b option either (though its
recipe *does* need the `b' flag!) unless the (real) body has lines beginning
"From " that were protected by a Content-Length: setting or by raw mode.]

With no From_ line in the returned text, you could even get away without
citation marks.  You can insert them, though, by continuing this way:

  savedmetas=$SHELLMETAS # if not already assigned
  SHELLMETAS # Don't be fooled by that pesky chevron.
  :0fw # invert (first) head for reply and cite (second head and) body
  | formail -rk -p'> ' -I"Whatever: the -I options were"
  SHELLMETAS=$savedmetas

  :0hfw # insert standard text at neck (Look, Ma, no shells!)
  | sed "$ a\\
line 1\\
line 2\\
\\
"

  :0 # return to sender
  ! -t

but it probably is more sensible to combine those three into one and to
use a shell for good reasons:

  :0 # note "/^$/a\\ ..." instead of "$ a\\ ..."
  | formail -rk -p'> ' -I"Whatever: the -I settings were" | \
    sed -e '1,/^$/!b' -e "/^$/a\\
line 1\\
line 2\\
\\
" | $SENDMAIL $SENDMAILFLAGS -t

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