return $highest;
}
-# We want to print the name of each list that has new mail only once,
-# so use this hash to store the lists that have already been printed.
-# Start the list out with SPAM already in it, since we don't care when
-# new messages are added to it.
-my %FOLDERS = ('SPAM'=>1);
-
sub store_message {
my $msg = shift;
my $mhfolder = shift;
}
}
}
-
- if (not $FOLDERS{$mhfolder}) {
- print("+$mhfolder\n");
- $FOLDERS{$mhfolder} = 1;
- }
}
# Parse a message file into a structure describing the headers. The
return %headers;
}
-###############################################################################
-# Spam handling, sorting, etc.
-
-sub preprocess {
- my @msglist = @_;
- my @baton;
- my $msg;
- my $i;
- my $st;
- my @result;
-
- @baton = spam_start_hook();
-
- foreach $msg (@msglist) {
- printf('%sChecking for spam... %6d/%d',
- "\r", ++$i, scalar(@msglist));
- if ($printfilenames) {
- print($msg);
- }
- if (spam_check($msg, @baton)) {
- print(" SPAM\n");
- store_message($msg, 'SPAM');
- } else {
- push(@result, $msg);
- }
- }
- print("\nDone: ", scalar(@result), " survivors\n");
-
- spam_stop_hook(@baton);
-
- return (map { $_->[1] }
- sort { $a->[0] <=> $b->[0] }
- map {
- if (not ($st = stat($_))) {
- die("stat($_): $!");
- }
- [$st->mtime, $_]
- }
- @result);
-}
-
\f
###############################################################################
# Filtering
sub filter_mail {
my @msglist = @_;
+ my $msgcount = scalar(@msglist);
+ my @baton;
my $msg;
my $mhfolder;
+ my $spam = 0;
+ my $saved = 0;
+ my %FOLDERS = ('SPAM'=>1);
+ @baton = spam_start_hook();
+
+ print("$msgcount messages...");
foreach $msg (@msglist) {
- $mhfolder = find_mh_folder($msg);
+ if (spam_check($msg, @baton)) {
+ $mhfolder = 'SPAM';
+ $spam = scalar(@SPAM)+ 1;
+ } else {
+ $mhfolder = find_mh_folder($msg);
+ $saved++;
+ }
+
store_message($msg, $mhfolder);
+
+ print("\r");
+ if (not $FOLDERS{$mhfolder}) {
+ print(' ' x length($msgcount));
+ print(" \r+$mhfolder\n");
+ $FOLDERS{$mhfolder} = 1;
+ }
+
+ printf('%6d SPAM %6d saved %6d/%1d',
+ $spam, $saved, $spam + $saved, $msgcount);
}
+ print("\n");
+
+ spam_stop_hook(@baton);
}
\f
MAIN: {
my @msglist;
+ my $st;
if ($dumpfilters) {
$Data::Dumper::Indent = 1;
exit;
}
- @msglist = getfiles("$MAILDIR/new");
+ @msglist = (
+ map { $_->[1] }
+ sort { $a->[0] <=> $b->[0] }
+ map {
+ if (not ($st = stat($_))) {
+ die("stat($_): $!");
+ }
+ [$st->mtime, $_]
+ }
+ getfiles("$MAILDIR/new"));
- if (not $filteronly) {
- @msglist = preprocess(@msglist);
- }
+ filter_mail(@msglist);
- if (not $spamonly) {
- filter_mail(@msglist);
- }
+ @SPAM and (exec('scan', '+SPAM', @SPAM) or die);
}
\f