No SpamAssassin report with MailScanner?

Tal Kelrich tal at MUSICGENOME.COM
Tue Apr 9 17:19:03 IST 2002


I was wondering whether this is a good solution, here goes.
I didn't test it, i'm probably making some big mistakes there, and I
can't promise anything other than it compiles ok

--- sendmail.pl.old     Mon Apr  1 11:09:59 2002
+++ sendmail.pl Tue Apr  9 18:51:58 2002
@@ -231,7 +231,7 @@
     $spammy = SpamAssassinChecks($Headers, $mID);
     if ($spammy) {
       $SpamText->{$mID} .= ", " if $SpamText->{$mID};
-      $SpamText->{$mID} .= "SpamAssassin ($spammy hits)";
+      $SpamText->{$mID} .= $spammy;
       ## Make a copy of the spam for later analysis and checking
       #system("/bin/cp $dfilename /export/2/var/spam/queue");
     }
@@ -300,27 +300,47 @@
 
   my $PipeReturn = 0;
 
+#  local (*PWRITE);
+#  local (*PREAD);
+  pipe PREAD, PWRITE;
+  die "could not open pipe: $!" if($!==0);
   my $pid = fork();
   die "Can't fork: $!" unless defined($pid);
 
   if ($pid == 0) {
     # In the child
     POSIX::setsid();
+    close PREAD;
     # Do the actual tests and work out the integer result
     my($spamness) = $Test->check($Mail);
     my($SAResult) = ($spamness->is_spam())?1:0;
-    $SAResult = int($spamness->get_hits()) if $SAResult;
+    my($tests,$hits,$req,$stat);
+    #X-Spam-Status: Yes, hits=7.2 required=5.0 tests=ALL_CAPS_SUBJECT,PLING,DEAR_SOMEBODY,CLICK_BELOW,AOL_USERS_LINK,GREAT_OFFER,HTTP_WITH_EMAIL_IN_URL,CLICK_HERE_LINK version=2.11
+    $tests=$spamness->get_names_of_tests_hit();
+    $hits=$spamness->get_hits();
+    $req=$spamness->get_required_hits();
+    #X-Spam-Flag: YES
+    $stat=$SAResult?"Yes":"No";
+    $SAResult="X-Spam-Status: $stat hits=$hits required=$req tests=$tests" ."\n X-Spam-Flag: " . uc($stat);
     # Destroy the status result -- should be unnecessary
     $spamness->finish();
-    exit $SAResult;
+    print PWRITE $SAResult;
+    close PWRITE;
+    exit 0;
   }
-
+  
   eval {
     local $SIG{ALRM} = sub { die "Command Timed Out" };
+    close PWRITE;
     alarm $Config::SpamAssassinTimeout;
     wait;
-    $PipeReturn = $?;
+    $PipeReturn = "";
     alarm 0;
+    while(<PREAD>)
+     {
+      $PipeReturn.=$_;
+     }
+    close PREAD;
     $pid = 0;
   };
   alarm 0;
@@ -354,7 +374,7 @@
   # The return from the pipe is a measure of how spammy it was
   Log::DebugLog("SpamAssassin returned $PipeReturn");
 
-  return $PipeReturn>>8;
+  return $PipeReturn;
 }
 

-- 
Tal Kelrich

PGP Fingerprint: 3EDF FCC5 60BB 4729 AB2F  CAE6 FEC1 9AAC 12B9 AA69
PGP key-id: 12B9AA69
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 240 bytes
Desc: This is a digitally signed message part
Url : http://lists.mailscanner.info/pipermail/mailscanner/attachments/20020409/0eaa16f6/attachment.bin


More information about the MailScanner mailing list