procmail
[Top] [All Lists]

Re: Received: headers after From:

1997-11-06 14:49:18
Ed Sabol wrote,

| Unfortunately, nobody has yet posted the solution to Greg's original request
| specifically: How does one get rid of all Received: headers that come after a
| From: header?

True (or it was true until later in Ed's post, where he supplied one).

The sticking point in a procmail-only solution is saving the left side of an
extraction.  I looked at Ed's recommendation, and it just makes my head swim.
(And it does call echo, which means either /bin/echo or a shell, so it does
need a fork at the end.  There are no forks in the recursively called
INCLUDERC itself.)

| Of course, it's highly debatable whether one should do this or not.

Agreed; I get a lot of legit mail with one or more Received: after From:.
This in itself is not reason for trashing mail, just for suspecting it
more.

| Caveat reader: I haven't tested the above code specifically, but it is
| largely based on code that I have tested and used. Also, you need procmail
| version 3.11pre5 or higher or else procmail will strip the newlines from the
| end of MATCHes.

Yes, but echo will put the newlines back.

Anyhow, I'm going to try this myself from scratch.  If I come up with
anything here, it's sure to have some resemblances to Ed's code, but
it baffles me where he was going with his AFTERFROM counter.  (Comments
are sometimes a *good* thing.)

I'm also concerned about how well Ed's code handles continuation lines, which
Received: headers tend to have.  Procmail wraps them automatically when the
search area is H (or above the first empty line if the search area is HB),
but I think it does not for any other search area.

Here's a method with one formail and one shell but no recursion.

:0 # see if we're going to do it at all
* ^From:.*$(.+$)*Received:
{
  :0 # save up through a From: line and operate on everything after
  * ^^\/(.+$)+From:.*
  { ABOVE_REPROACH = "$MATCH
" } # this method should preserve the closing newline in any version

  :0hir # save rest of head in another variable
  * $ ^^$\ABOVE_REPROACH\/(.+$)$^^
  BENEATH_CONTEMPT=| echo "$MATCH" | formail -fI Received:

  :0fwhi # if blank line at neck is intact
  * BENEATH_CONTEMPT ?? $($)^^
  | echo "$ABOVE_REPROACH$BENEATH_CONTEMPT"
  :0Efwhi # if not, restore it
  | echo "$ABOVE_REPROACH$BENEATH_CONTEMPT
"
}

Now to the next big puzzler: if there are two or more From: lines, what
should be done with Received: headers that appear between them?  The code I
just wrote will keep them; I'm not sure what Ed's will do (my guess is that
it will remove them).  Mine can be made to drop them with one change. 
Instead of defining $ABOVE_REPROACH this way:

  * ^^\/(.+$)+From:.*

which would include through the last From:, do this:

  * ^^\/From .*$(([^F]|.[^r]|..[^o]|...[^m]|....[^:]).*$)*From:.*

which stops with the first From:.