David Hunt suggested to W. Wesley Groleau,
| This is not the requested perl, but a procmail\formail method I find
| handy to reduce the number of "Received:" fields:
| :0 fw
| | formail -zu"Received:
Oh my ... that needs a lot of corrections.
First, there is no need to drag the body through it; add the `h' flag to
improve efficiency, since the body would come out unchanged anyway.
Second, if the item was sent from another account on your own site, it might
have only one Received: header, so it would be a waste to call formail then.
Make sure there are at least two Received: headers before bothering.
Third, the unclosed quote will really mess things up. Close it ... or
don't open it, because the quotes aren't needed here.
Fourth, David seems to have confused the meanings of -u and -U, which he
| From the manpage:
| -u Make the first occurrence of this field unique, and
| thus delete all subsequent occurrences of it.
| -U Make the last occurrence of this field unique, and
| thus delete all preceding occurrences of it.
"First" and "last" are determined not by age of insertion but by order
of appearance. -u will keep the topmost, which for Received: is, as David
said, the most recent; -U will keep the bottommost, which is the oldest.
| The above will dump all "Received:" lines except the last, which is
| the first one inserted. This is usually the more relavent one.
No. It will dump all but the first, which is the one most recently inserted.
If you consider the earliest one inserted to be the only relevant one, then
you need -U.
:0fwh # H is implicit; regexp cannot leak into body
| formail -zU Received:
All that said, I advise against doing it. A spammer can forge a Received:
header or two before sending the garbage out, so the earliest legitimately
inserted Received: header might not necessarily be the bottommost.