wwgrol(_at_)sparc01(_dot_)fw(_dot_)hac(_dot_)com (W. Wesley Groleau x4923)
writes:
One of my wishes (as opposed to necessities) is to automatically get rid
of a lot of received headers that are really just clutter. Every piece of
mail I get has a minimum of five of these headers AFTER it gets past our
firewall.
...
The logic you gave (but that I elided) can more simply be given as
"print it unless it's a Received: that contains our-firewall-name".
The only tricky thing is the handling of header continuations. This
can be solved in perl, or farmed out to formail. Here's the formail
solution:
:0 fh
|formail -c | perl -ne 'print if !/^Received:/ || !/our-firewall-name/'
Here's the perl solution, in readable perl:
:0 fh
|perl -ne 'if(/^\s/) {' \
-e ' $h .= $_;' \
-e '} else {' \
-e ' print $h unless $h =~ /^Received:.*our-firewall-name/;' \
-e ' $h = $_;' \
-e '}'
"If the line we're looking at starts with whitespace (i.e., this is
continuation line), then append it to the header line that we're
growing in $h. Otherwise, print the grown header unless it's a
Received: header with the firewall name in it, and then store the
_current_line_ into $h, the growing header variable."
The perl solution will be faster, as it saves a process, a pipe, and a
pile of read/write pairs.
For those who can't stand clear perl, here's the line-noise version:
:0fh
|perl -ne '$h=/^\s/?$h.$_:($h=~/^Received:.*our-firewall-name/||print($h),$_)'
Note that removing _all_ the Received: headers if really easy:
:0 fh
|formail -IReceived:
Philip Guenther