From 509be144a280293d2239c0cf9fefdaf5ea339f98 Mon Sep 17 00:00:00 2001 From: "Bradley M. Kuhn" Date: Sat, 20 Nov 2010 17:20:38 -0500 Subject: [PATCH] Removed useless outer loop; Corrected close()'s; Fixed Emacs compile command --- remove-spam-high-confidence-maildir.plx | 64 ++++++++++++------------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/remove-spam-high-confidence-maildir.plx b/remove-spam-high-confidence-maildir.plx index dc77991..34cb781 100644 --- a/remove-spam-high-confidence-maildir.plx +++ b/remove-spam-high-confidence-maildir.plx @@ -32,45 +32,43 @@ my($MAILDIR_FOLDER, $DSPAM_PROB_MIN, $DSPAM_CONF_MIN) = @ARGV; my($total, $countDeleted) = (0, 0); -foreach my $folder (@dupFolders) { - my @msgDirs = ("$folder/cur", "$folder/new"); - foreach my $dir (@msgDirs) { - die "$MAILDIR_FOLDER must not be a maildir folder (or is unreadable by you), since $dir isn't a readable directory: $!" - unless (-d $dir); - } - foreach my $dir (@msgDirs) { - opendir(MAILDIR, $dir) or die "Unable to open directory $dir for reading: $!"; - while (my $file = readdir MAILDIR) { - next if -d $file; # skip directories - my $existing_file = "$dir/$file"; - open(MAIL_MESSAGE, "<", $existing_file) or - die "unable to open $existing_file for reading: $!"; +my @msgDirs = ("$MAILDIR_FOLDER/cur", "$MAILDIR_FOLDER/new"); - my $header = new Mail::Header(\*MAIL_MESSAGE); - my $fields = $header->header_hashref; +foreach my $dir (@msgDirs) { + die "$MAILDIR_FOLDER must not be a maildir folder (or is unreadable by you), since $dir isn't a readable directory: $!" + unless (-d $dir); +} +foreach my $dir (@msgDirs) { + opendir(MAILDIR, $dir) or die "Unable to open directory $dir for reading: $!"; + while (my $file = readdir MAILDIR) { + next if -d $file; # skip directories + my $existing_file = "$dir/$file"; + open(MAIL_MESSAGE, "<", $existing_file) or + die "unable to open $existing_file for reading: $!"; - my %dspamVal; - foreach my $val ('Confidence', 'Probability') { - foreach my $dv (@{$fields{"X-DSPAM-$val"}}) { - if (not defined $dspamVal{$val}) { - $dspamVal{$val} = $dv; - } else { - $dspamVal = $dv if $dv < $dspamVal{$val}; - } - } + my $header = new Mail::Header(\*MAIL_MESSAGE); + my $fields = $header->header_hashref; + + my %dspamVal; + foreach my $val ('Confidence', 'Probability') { + foreach my $dv (@{$fields{"X-DSPAM-$val"}}) { if (not defined $dspamVal{$val}) { - print STDERR "File $file has no X-DSPAM-$val header. Skipping.\n"; - next; + $dspamVal{$val} = $dv; + } else { + $dspamVal = $dv if $dv < $dspamVal{$val}; } } - - $total++; - - if ($dspamVal{Confidence} >= $DSPAM_PROB_MIN and - $dspamVal{Probability} >= $DSPAM_CONF_MIN) { - $countDeleted++; + if (not defined $dspamVal{$val}) { + print STDERR "File $file has no X-DSPAM-$val header. Skipping.\n"; + next; } } + $total++; + + if ($dspamVal{Confidence} >= $DSPAM_PROB_MIN and + $dspamVal{Probability} >= $DSPAM_CONF_MIN) { + $countDeleted++; + } close MAIL_MESSAGE; } close MAILDIR; @@ -81,5 +79,5 @@ print "$countDeleted of $total would be deleted\n"; ############################################################################### # # Local variables: -# compile-command: "perl -c remove-dup-mails-from-maildir.plx" +# compile-command: "perl -c remove-spam-high-confidence-maildir.plx" # End: