Mailing List Archive

svn commit: rev 6519 - incubator/spamassassin/trunk/lib/Mail/SpamAssassin
Author: felicity
Date: Thu Feb 5 12:40:15 2004
New Revision: 6519

Modified:
incubator/spamassassin/trunk/lib/Mail/SpamAssassin/CmdLearn.pm
Log:
bug 2869: sa-learn would fail if run with --mbox and reading from STDIN in certain circumstances. this commit lets sa-learn make a temp file to store the contents from STDIN, runs the appropriate code over the temp file, then removes it.

Modified: incubator/spamassassin/trunk/lib/Mail/SpamAssassin/CmdLearn.pm
==============================================================================
--- incubator/spamassassin/trunk/lib/Mail/SpamAssassin/CmdLearn.pm (original)
+++ incubator/spamassassin/trunk/lib/Mail/SpamAssassin/CmdLearn.pm Thu Feb 5 12:40:15 2004
@@ -236,6 +236,22 @@
target('-');
}

+ # mbox doesn't deal with STDIN, so make a temp file if they want STDIN.
+ # do it here since they may specify "-" on the commandline
+ #
+ my $tempfile;
+ if ( $targets[0] =~ /:mbox:-$/ ) {
+ my $handle;
+
+ local $/=undef; # go into slurp mode
+ ($tempfile, $handle) = Mail::SpamAssassin::Util::secure_tmpfile();
+ print { $handle } <STDIN>;
+ close $handle;
+
+ # re-aim the targets at the tempfile instead of STDIN
+ $targets[0] =~ s/:-$/:$tempfile/;
+ }
+
my $iter = new Mail::SpamAssassin::ArchiveIterator ({
'opt_j' => 0,
'opt_n' => 1,
@@ -252,6 +268,11 @@

print STDERR "\n" if ($opt{showdots});
print "Learned from $learnedcount message(s) ($messagecount message(s) examined).\n";
+
+ # If we needed to make a tempfile, go delete it.
+ if ( defined $tempfile ) {
+ unlink $tempfile;
+ }

if ($@) { die $@ unless ($@ =~ /HITLIMIT/); }
};