No SpamAssassin report with MailScanner?
dml
dml at UNB.CA
Thu Apr 11 16:01:39 IST 2002
Almost works fine for me. Only problem is that I'm using Mailscanner's option
to modify the Subject line, and it was modifying the subject line even when
the report from SpamAssassin was negative, e.g.
Subject: {UNB: Possibly Spam} test
Date: Thu, 11 Apr 2002 10:42:49 -0300
X-UNB-SpamScanner: Scanned
X-UNB-MailScanner-SpamCheck: X-Spam-Status: No hits=0 required=5 tests=
X-Spam-Flag: NO
So I hacked the modification a bit with my neophyte perl skills, and ended up
with this. Seems to work better for me with "Spam Modify Subject" enabled in
mailscanner.conf.
If SpamAssassin reports it as spam, the report is added to the X-Mailscanner
header, and (if enabled), the subject is modified.
If SA doesn't report it as spam, the subject won't be modified, but no report
is generated. Which version is better depends on whether you have MA set to
modify the subject line or not.
Maybe somebody can improve this even more to allow the report to be added
without mistakenly causing the subject modification?
So, the question remains, is this a good solution? Does anybody have any idea
what the effect of opening the pipe between the child and parent will have on
load handling? What sort of extra limitations may this have on scaling?
D.
--- sendmail.pl.orig Thu Apr 11 10:14:32 2002
+++ sendmail.pl Thu Apr 11 10:38:11 2002
@@ -121,7 +121,7 @@
$MessagesInfo->{$id} = $MsgInfo;
$Headers->{$id} = $RHeaders; # Store all the headers for SpamAssassin
if (DefinitelyClean($RHeaders)) {
- push @$RClean, $id;
+ push @$RClean, $id;
$CleanMsgs++;
$CleanBytes += -s "$InQueueDir/" . MTA::HFileName($id);
$CleanBytes += -s "$InQueueDir/" . MTA::DFileName($id);
@@ -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,58 @@
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($SAResult) = int(($spamness->is_spam()))?1:0;
+
+ #The following two lines will be passed back to Mailscanner, for
inclusion into the email headers
+ #Scoring: hits=7.2 required=5.0
tests=ALL_CAPS_SUBJECT,PLING,DEAR_SOMEBODY,CLICK_BELOW,AOL_USERS_LINK,GREAT_OF
FER,HTTP_WITH_EMAIL_IN_URL,CLICK_HERE_LINK version=2.11
+ #X-Spam-Flag: YES
+ my($tests,$hits,$req,$stat);
+ $tests=$spamness->get_names_of_tests_hit();
+ $hits=$spamness->get_hits();
+ $req=$spamness->get_required_hits();
+ $stat=$SAResult?"Yes":"No";
+ my $txtSAResult="Scoring: hits=$hits required=$req tests=$tests" ."\n
X-Spam-Flag: " . uc($stat);
+
+
# Destroy the status result -- should be unnecessary
$spamness->finish();
+ if ($SAResult){
+ print PWRITE $txtSAResult;
+ }
+ else{
+ #If it's not spam, return zero, otherwise mailscanner's option to
insert a string into the subject will trigger
+ print PWRITE "0";
+ }
+ close PWRITE;
exit $SAResult;
}
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 +385,7 @@
# The return from the pipe is a measure of how spammy it was
Log::DebugLog("SpamAssassin returned $PipeReturn");
- return $PipeReturn>>8;
+ return $PipeReturn;
}
>===== Original Message From MailScanner mailing list
<MAILSCANNER at JISCMAIL.AC.UK> =====
>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
======================================================
David Lancaster
ITS ESS
More information about the MailScanner
mailing list