#! /usr/bin/perl # # This script is set to $display_filter in .mutt/muttrc # which means that we can go wild with and do basicly # whatever we want in pager-view. Fixes some spam from # mailing-lists and long lines. Just add regexes om # footers you don't like to the @kill list. # # Check the macros in muttrc for how to control it # # Svein Harang, 2004. # use warnings; use strict; my $head = 1; my $sig = 0; my $kill = 0; my $lines = 0; my $line = 0; my $cp = 0; my $wrap = 72; my @bh; my @bs; my @bb; my @var_sig = ("^-- \$"); # Four lines from here we chop my @show = ("PGP", "signed data"); # Exceptions my @kill = (".*Yahoo\! Groups Links", # Chop at once ".*Ny versjon av Yahoo\! Messenger", "_{47}\$", # kill mailman " *_{65} *\$", # kill hotmail and yahoo "-{55}\$", # kill SF.net "-{49}\$", # kill tele2.no webmail "-{24} Yahoo", # kill Yahoo ".*Yahoo\! Groups", # kill Yahoo ".*To UNSUBSCRIBE", ".*IFRAME"); while (<>) { foreach my $mr (@kill) { $kill = 1 if (/^[ >|]*$mr/); } foreach my $mr (@var_sig) { if(/$mr/) { $kill = 1 if ($sig); $sig = 1; } } if ($head) { if (/^$/) { $head = 0; } else { push @bh, $_; } } elsif (($kill || $sig && $lines++ > 4) && !&show($_)) { $cp++; } elsif ($sig) { push @bs, $_; } else { push @bb, $_; } $line++; } #print headers print @bh; print "X-Lines-Chopped: $cp (press \'o\' to toggle view)\n\n"; # Print the mail $line = 0; my @words = (); my $indent = ""; foreach (@bb) { my $string = ""; s/^([ >|]*)//; if (scalar @words == 0) { $indent = $1; } $string = $indent; push @words, split(" "); unless ($bb[$line+1] && $bb[$line+1] !~ /^[ >|]*$/ && ($bb[$line+1] =~ /^$indent[^ >|]/ || $bb[$line+2] && $bb[$line+2] =~ /^$indent[^ >|]/ )) { foreach my $word (@words) { if (length($string) + length($word) >= $wrap){ print "$string\n"; $string = "$indent$word "; } else { $string = "$string$word "; } } print ("$string\n\n"); # Still buggy :( @words = (); } $_ = ""; print; $line++; } #print sig print @bs; sub show { my $show = 0; foreach (@show) { $show = 1 if ($_[0] =~ /$_/); } return $show; }