#!/usr/bin/perl -w my @score; my @from; my @subj; # Setup a whitelist hash because it is faster than grepping the file every time. my %whitelist; open(WL, "/rigel4/rreid/mail/good.list") or warn "Could not open /rigel4/rreid/mail/good.list for reading"; while(){ chomp; $whitelist{$_} = 1; } close(WL); my @wlscore; my @wlfrom; my @wlsubj; print "Proofpoint suspected spam report\n"; print "********************************\n\n"; $/ = ">"; # Turn on quasiparagraph mode. while(<>){ if(/^\s*Report\s+(\d+)\s+([-a-zA-Z0-9.+_]+\@[-a-zA-Z0-9.+_]+)\s+(.*)/){ my $currscore = $1; my $currfrom = $2; my $currsubj = $3; # Shorten $currfrom if necessary by removing all but .domain.abc if(length($currfrom) > 32){ $currfrom =~ s/\@.+(\.[^.]+\.[^.]+)$/\@..$1/; } if(defined $whitelist{$currfrom}){ push @wlscore, $currscore; push @wlfrom, $currfrom; push @wlsubj, $currsubj; next; } # Skip this spam if $currsubj has an excess of funny characters... my @funnychars = ($currsubj =~ /[[:^ascii:]]/g); # ...or would if transliterated into the proper charset. if($currsubj =~ /^=\?(iso-2022|euc)-kr/){ push @funnychars, ("a", "b", "c", "d", "e"); # Any old 5 will do. } if(@funnychars < 5){ # Truncate those long UTF-8 and Windows-1251 Subject:s. if($currsubj =~ /^=\?utf-8\?/ || $currsubj =~ /^=\?Windows-1251\?/){ $currsubj =~ s/^=\?([^?]+).*/$1/; } push @score, $currscore; push @from, $currfrom; push @subj, $currsubj; } } } my $maxlength = 0; my $formatstr; if(@wlscore){ print "Whitelisted:\n"; print "------------\n"; foreach(@wlfrom){ my $templength = length; if($maxlength < $templength){ $maxlength = $templength; } } $formatstr = "!!( \%3d \%-${maxlength}s \%s )!!\n"; for (my $i = 0; $i < @wlfrom; ++$i){ printf($formatstr, $wlscore[$i], $wlfrom[$i], $wlsubj[$i]); } if(@from){ $maxlength = 0; print "\nSuspected spam:\n"; print "---------------\n"; } } foreach(@from){ my $templength = length; if($maxlength < $templength){ $maxlength = $templength; } } $formatstr = "\%3d \%-${maxlength}s \%s\n"; for (my $i = 0; $i < @from; ++$i){ printf($formatstr, $score[$i], $from[$i], $subj[$i]); }