From: epg <> Date: Sat, 3 Apr 2004 05:11:30 +0000 (+0000) Subject: Collapse the spam-checking and filtering passes into a single pass and X-Git-Url: https://diplodocus.org/git/minc/commitdiff_plain/95a97f883e0e32b7e78b58ff11424fe8a4d4630e Collapse the spam-checking and filtering passes into a single pass and adapt the diagnostic output to make sense in the new single pass. (store_message): Don't print anything. (preprocess): Move the message sorting to MAIN and spam processing to filter_mail. (filter_mail): Do spam filtering in this loop and do all status printing here. (%FOLDERS): This should not have been global; move it into filter_mail. (MAIN): Sort messages before calling filter_mail. If any SPAM messages were detected, scan(1) them. --- diff --git a/minc b/minc index 1b5100f..8d8b6a3 100755 --- a/minc +++ b/minc @@ -390,12 +390,6 @@ sub get_highest_msgnum { 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; @@ -479,11 +473,6 @@ sub store_message { } } } - - if (not $FOLDERS{$mhfolder}) { - print("+$mhfolder\n"); - $FOLDERS{$mhfolder} = 1; - } } # Parse a message file into a structure describing the headers. The @@ -535,47 +524,6 @@ sub get_headers { 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); -} - ############################################################################### # Filtering @@ -644,18 +592,47 @@ sub find_mh_folder { 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); } MAIN: { my @msglist; + my $st; if ($dumpfilters) { $Data::Dumper::Indent = 1; @@ -663,15 +640,20 @@ MAIN: { 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); }