You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by fe...@apache.org on 2006/12/03 20:16:02 UTC

svn commit: r481861 - in /spamassassin/trunk: lib/Mail/SpamAssassin/ArchiveIterator.pm sa-learn.raw spamassassin.raw

Author: felicity
Date: Sun Dec  3 11:16:01 2006
New Revision: 481861

URL: http://svn.apache.org/viewvc?view=rev&rev=481861
Log:
revert r481828 due to errors. :(

Modified:
    spamassassin/trunk/lib/Mail/SpamAssassin/ArchiveIterator.pm
    spamassassin/trunk/sa-learn.raw
    spamassassin/trunk/spamassassin.raw

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/ArchiveIterator.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/ArchiveIterator.pm?view=diff&rev=481861&r1=481860&r2=481861
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/ArchiveIterator.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/ArchiveIterator.pm Sun Dec  3 11:16:01 2006
@@ -238,21 +238,18 @@
 C<mbox> an mbox formatted file, or C<mbx> for an mbx formatted directory.
 
 C<detect> can also be used.  This assumes C<mbox> for any file whose path
-contains the pattern C</\.mbox/i>, C<file> anything that is not a
-directory, or C<directory> otherwise.
+contains the pattern C</\.mbox/i>, C<file> for STDIN and anything that is
+not a directory, or C<directory> otherwise.
 
 =item raw_location
 
-Path to file or directory.  File globbing is allowed using the
-standard csh-style globbing (see C<perldoc -f glob>).  C<~> at the
-front of the value will be replaced by the C<HOME> environment
-variable.  Escaped whitespace is protected as well.
+Path to file or directory.  Can be "-" for STDIN.  File globbing is allowed
+using the standard csh-style globbing (see C<perldoc -f glob>).  C<~> at the
+front of the value will be replaced by the C<HOME> environment variable.
+Escaped whitespace is protected as well.
 
 B<NOTE:> C<~user> is not allowed.
 
-B<NOTE 2:> C<-> is not allowed as a raw location.  To have
-ArchiveIterator deal with STDIN, generate a temp file.
-
 =back
 
 =cut
@@ -462,11 +459,6 @@
       next;
     }
 
-    if ($rawloc eq '-') {
-      warn 'archive-iterator: raw location "-" is not supported';
-      next;
-    }
-
     # use ham by default, things like "spamassassin" can't specify the type
     $class = substr($class, 0, 1) || 'h';
 
@@ -490,7 +482,8 @@
           # filename indicates mbox
           $format = 'mbox';
         } 
-	elsif (!(-d $location)) {
+	elsif ($location eq '-' || !(-d $location)) {
+	  # stdin is considered a file if not passed as mbox
           $format = 'file';
 	}
 	else {
@@ -694,7 +687,7 @@
   my ($self, $class, $folder, $bkfunc) = @_;
   my @files;
 
-  if (-d $folder) {
+  if ($folder ne '-' && -d $folder) {
     # passed a directory of mboxes
     $folder =~ s/\/\s*$//; #Remove trailing slash, if there
     if (!opendir(DIR, $folder)) {
@@ -799,7 +792,7 @@
   my ($self, $class, $folder, $bkfunc) = @_;
   my (@files, $fp);
 
-  if (-d $folder) {
+  if ($folder ne '-' && -d $folder) {
     # got passed a directory full of mbx folders.
     $folder =~ s/\/\s*$//; # remove trailing slash, if there is one
     if (!opendir(DIR, $folder)) {

Modified: spamassassin/trunk/sa-learn.raw
URL: http://svn.apache.org/viewvc/spamassassin/trunk/sa-learn.raw?view=diff&rev=481861&r1=481860&r2=481861
==============================================================================
--- spamassassin/trunk/sa-learn.raw (original)
+++ spamassassin/trunk/sa-learn.raw Sun Dec  3 11:16:01 2006
@@ -380,44 +380,29 @@
     close(F);
   }
 
-  ###########################################################################
-  # Deal with the target listing, and STDIN -> tempfile
+  # add leftover args as targets
+  foreach (@ARGV) { target($_); }
 
-  my $tempfile; # will be defined if stdin -> tempfile
-  my @targets = @ARGV;
-  @targets = ('-') unless @targets;
-
-  for(my $elem = 0; $elem <= $#targets; $elem++) {
-    # ArchiveIterator doesn't really like STDIN, so if "-" is specified
-    # as a target, make it a temp file instead.
-    if ( $targets[$elem] =~ /(?:^|:)-$/ ) {
-      if (defined $tempfile) {
-        # uh-oh, stdin specified multiple times?
-        warn "skipping extra stdin target (".$targets[$elem].")\n";
-        splice @targets, $elem, 1;
-        $elem--; # go back to this element again
-        next;
-      }
-      else {
-        my $handle;
-
-        local $/ = undef;    # go into slurp mode
-        ( $tempfile, $handle ) = Mail::SpamAssassin::Util::secure_tmpfile();
-        print {$handle} <STDIN>;
-        close $handle;
+  #No arguments means they want stdin:
+  if ( $#targets < 0 ) {
+    target('-');
+  }
 
-        # re-aim the targets at the tempfile instead of STDIN
-        $targets[$elem] =~ s/-$/$tempfile/;
-      }
-    }
+  # mbox and mbx 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] =~ /:mbo?x:-$/ ) {
+    my $handle;
+
+    local $/ = undef;    # go into slurp mode
+    ( $tempfile, $handle ) = Mail::SpamAssassin::Util::secure_tmpfile();
+    print {$handle} <STDIN>;
+    close $handle;
 
-    # make sure the target list is in the normal AI format
-    if ($targets[$elem] !~ /^[^:]*:[a-z]+:/) {
-      $targets[$elem] = target($targets[$elem]);
-    }
+    # re-aim the targets at the tempfile instead of STDIN
+    $targets[0] =~ s/:-$/:$tempfile/;
   }
-
-  ###########################################################################
 
   my $iter = new Mail::SpamAssassin::ArchiveIterator(
     {

Modified: spamassassin/trunk/spamassassin.raw
URL: http://svn.apache.org/viewvc/spamassassin/trunk/spamassassin.raw?view=diff&rev=481861&r1=481860&r2=481861
==============================================================================
--- spamassassin/trunk/spamassassin.raw (original)
+++ spamassassin/trunk/spamassassin.raw Sun Dec  3 11:16:01 2006
@@ -156,6 +156,7 @@
 
 my $doing_whitelist_operation = 0;
 my $count                     = 0;
+my @targets                   = ();
 my $exitvalue;
 
 my $init_results              = 0;
@@ -307,44 +308,6 @@
 }
 
 ###########################################################################
-# Deal with the target listing, and STDIN -> tempfile
-
-my $tempfile; # will be defined if stdin -> tempfile
-my @targets = @ARGV;
-@targets = ('-') unless @targets;
-
-for(my $elem = 0; $elem <= $#targets; $elem++) {
-  # ArchiveIterator doesn't really like STDIN, so if "-" is specified
-  # as a target, make it a temp file instead.
-  if ( $targets[$elem] =~ /(?:^|:)-$/ ) {
-    if (defined $tempfile) {
-      # uh-oh, stdin specified multiple times?
-      warn "skipping extra stdin target (".$targets[$elem].")\n";
-      splice @targets, $elem, 1;
-      $elem--; # go back to this element again
-      next;
-    }
-    else {
-      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[$elem] =~ s/-$/$tempfile/;
-    }
-  }
-
-  # make sure the target list is in the normal AI format
-  if ($targets[$elem] !~ /^[^:]*:[a-z]+:/) {
-    my $format = $opt{'format'} || 'detect';
-    $targets[$elem] = join ( ":", '', $format, $targets[$elem] );
-  }
-}
-
-###########################################################################
 
 # Everything below here needs ArchiveIterator ...
 my $iter = new Mail::SpamAssassin::ArchiveIterator(
@@ -355,6 +318,28 @@
 );
 
 $iter->set_functions( \&wanted, \&result );
+
+# add leftover args as targets
+# no arguments means they want stdin:
+push ( @ARGV, '-' ) if ( !@ARGV );
+@targets = map { join ( ":", '', $opt{'format'}, $_ ) } @ARGV;
+
+# mbox and mbx handling doesn't deal with STDIN, so make a temp file if they
+# want STDIN.  do it here since they may specify "-" on the commandline
+# instead of leaving it as the default.
+#
+my $tempfile;
+if ( $targets[0] =~ /:mbo?x:-$/ ) {
+  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/;
+}
 
 # Go run the messages!
 # bug 4930: use a temp variable since "||=" decides whether or not to set the