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 2004/02/01 06:12:51 UTC

svn commit: rev 6399 - incubator/spamassassin/trunk/lib/Mail/SpamAssassin

Author: felicity
Date: Sat Jan 31 21:12:49 2004
New Revision: 6399

Modified:
   incubator/spamassassin/trunk/lib/Mail/SpamAssassin/ArchiveIterator.pm
Log:
previous change broke sa-learn -- we now only use external files for message passing if -j > 1, also just stick # of messages at top of temp file, skip the whole IO child/parent thing ...

Modified: incubator/spamassassin/trunk/lib/Mail/SpamAssassin/ArchiveIterator.pm
==============================================================================
--- incubator/spamassassin/trunk/lib/Mail/SpamAssassin/ArchiveIterator.pm	(original)
+++ incubator/spamassassin/trunk/lib/Mail/SpamAssassin/ArchiveIterator.pm	Sat Jan 31 21:12:49 2004
@@ -84,9 +84,9 @@
     my $messages;
 
     # message-array
-    $MESSAGES = $self->message_array(\@targets);
+    ($MESSAGES, $messages) = $self->message_array(\@targets);
 
-    while ($message = $self->next_message()) {
+    while ($message = shift @{$messages}) {
       my ($class, undef, $date) = index_unpack($message);
       $result = $self->run_message($message);
       &{$self->{result_sub}}($class, $result, $date) if $result;
@@ -104,26 +104,17 @@
     # Have some kids ...
     $self->start_children($self->{opt_j}, \@child, \@pid, $select);
 
-    # Prep a temp file for messages to run
     my $tmpf;
     ($tmpf, $self->{messageh}) = Mail::SpamAssassin::Util::secure_tmpfile();
     unlink $tmpf;
-
-    # Prep to have child labor results ...
-    my $io = IO::Socket->new();
-    my($child,$parent) = $io->socketpair(AF_UNIX,SOCK_STREAM,PF_UNSPEC);
+    undef $tmpf;
 
     # Have a child figure out what we should be doing ...
     if ( $tmpf = fork() ) { # parent
-      close($parent);
-      chomp($MESSAGES = readline $child);
       waitpid($tmpf, 0);
-      close($child);
     }
     elsif ( defined $tmpf ) { # child
-      close($child);
-      select $parent;
-      print $self->message_array(\@targets),"\n";
+      $self->message_array(\@targets, $self->{messageh});
       exit;
     }
     else {
@@ -132,7 +123,7 @@
 
     # Ok, we now have a temp file with the messages to process ...
     seek ($self->{messageh}, 0, 0);
-    undef $io;
+    $MESSAGES = $self->next_message();
 
     # feed childen, make them work for it, repeat.
     while ($select->count()) {
@@ -211,6 +202,8 @@
 	$self->start_children($self->{opt_j}, \@child, \@pid, $select);
       }
     }
+
+    close($self->{messageh});
     # reap children
     $self->reap_children($self->{opt_j}, \@child, \@pid);
   }
@@ -219,7 +212,7 @@
 ############################################################################
 
 sub message_array {
-  my($self, $targets) = @_;
+  my($self, $targets, $fh) = @_;
 
   foreach my $target (@${targets}) {
     my ($class, $format, $rawloc) = split(/:/, $target, 3);
@@ -290,13 +283,12 @@
     push @messages, (splice @s), (splice @h);
   }
 
-  my $count = scalar @messages;
-  my $message;
-  while ($message = shift @messages) {
-    print { $self->{messageh} } "$message\n";
+  if ( defined $fh ) {
+    print { $fh } map { "$_\n" } scalar(@messages), @messages;
+    return;
   }
-
-  return $count;
+  
+  return scalar(@messages), \@messages;
 }
 
 sub next_message {