From 3308914195fb689cf0c808a854e7c9d04afffe8e Mon Sep 17 00:00:00 2001 From: "Bradley M. Kuhn" Date: Sun, 21 Nov 2010 12:18:41 -0500 Subject: [PATCH] Failed open() should not be fatal; normalized full path file name. --- remove-spam-high-confidence-maildir.plx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/remove-spam-high-confidence-maildir.plx b/remove-spam-high-confidence-maildir.plx index a21785d..fdb20a8 100644 --- a/remove-spam-high-confidence-maildir.plx +++ b/remove-spam-high-confidence-maildir.plx @@ -42,9 +42,12 @@ MAIL: 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 $fullFileName = "$dir/$file"; + + unless (open(MAIL_MESSAGE, "<", $fullFileName)) { + print STDERR "File, $fullFileName, appears to have disappeared during processing ($!).\n (Ignoring that fact, but counts may be off.)\n"; + next MAIL; + } my $header = new Mail::Header(\*MAIL_MESSAGE); my $fields = $header->header_hashref; @@ -69,8 +72,8 @@ MAIL: foreach my $dir (@msgDirs) { $dspamVal{Probability} >= $DSPAM_PROB_MIN) { $countDeleted++; if (defined $COUNT_ONLY and $COUNT_ONLY) { - warn "unable to unlink $dir/$file : $!" - unless unlink("$dir/$file") == 1; + warn "unable to unlink $fullFileName: $!" + unless unlink("$fullFileName") == 1; } } close MAIL_MESSAGE;