#!/home/y/bin/perl -w use strict; use warnings; if ( !$ARGV[0] ) { print "Usage: spamheaders inputfile\n"; die; } my $fmail = $ARGV[0]; my %xheaders; sub isinterestingheader($) { my $header = shift; # If you want to ignore/unignore any particular X-headers, you can # add/remove it to the @ignore_x_headers variable. You do not need to # add the preceeding X- to the variables my @ignore_x_headers = qw/Original-To Spam-Status Mozilla-.* Quarantine-ID Virus-Scanned Spam-Score Spam-Level Spam-Flag Amavis-.* Mailer Priority Account-Key Priority /; my $regex_ignore_x_headers = join( "|", @ignore_x_headers ); unless ( $header =~ /X-($regex_ignore_x_headers)/i) { #print "[$header] is interesting and matched $1\n"; return 1; } return 0; } sub countthisheader($$) { my ($xkey, $value) = shift; if ( exists( $xheaders{$xkey}{count})) { $xheaders{$xkey}{count}++; $xheaders{$xkey}{value} = join( ", ", $xheaders{$xkey}{value}, $2 ); } else { $xheaders{$xkey}{count} = 1; $xheaders{$xkey}{value} = $2; } } open( INFILE, "$fmail" ) or die "Could not open input file!\n"; my $newletter = undef; while () { my $mline = $_; if ( $mline =~ /(^X-.*).*:\s(.+)/ ) { if (isinterestingheader($1)){ countthisheader($1,$2); } } } my ($key,$value); foreach $key (sort keys %xheaders) { my $count = $xheaders{$key}{count}; ($count < 10) ? printf "%-20.20s | %-d | %-80.80s\n", $key,$count,$xheaders{$key}{value} : printf "%-20.20s | %-d | \n", $key,$count ; }