Message larger than max testing size

Tony Finch dot at DOTAT.AT
Wed Jul 23 14:00:05 IST 2003


Antony Stone <Antony at SOFT-SOLUTIONS.CO.UK> wrote:
>
>Could this be changed so that the size limit applies to the body of the email
>itself, without attachments, rather than the whole thing with images etc
>included?

I've patched MailScanner to SpamAssassinate only the first N bytes of
a message, according to the Max SpamAssassin Size, rather than not
scan large messages at all. This is closer to what my users want, and
it seems there are some large spams around, and it means I can get away
with a smaller setting and therefore less SA CPU usage.


--- EximDiskStore.pm    13 May 2003 17:44:43 -0000      1.13
+++ EximDiskStore.pm    21 Jul 2003 18:05:01 -0000      1.14
@@ -321,8 +321,8 @@
 # Passed a ref to the array.
 sub ReadBody {
   my $this = shift;
-  my($body) = @_;
-
+  my($body,$max) = @_;
+  my $size = 0;
   my $dh = $this->{indhandle};

   seek($dh, 0, 0); # Rewind the file
@@ -330,10 +330,11 @@
   my $line = <$dh>;
   # FIXME: check that id is correct here

-  while(<$dh>) {
+  while(defined <$dh> and $size < $max) {
     # End of line characters are already there, so don't add them
     #push @{$body}, $_ . "\n";
     push @{$body}, $_;
+    $size += length $_;
   }
 }

--- PFDiskStore.pm      4 Jul 2003 18:08:28 -0000       1.1.1.3
+++ PFDiskStore.pm      21 Jul 2003 18:05:01 -0000      1.2
@@ -381,14 +382,16 @@
 # Passed a ref to the array.
 sub ReadBody {
   my $this = shift;
-  my($body) = @_;
+  my($body,$max) = @_;
+  my $size = 0;

   my $b= Body->new( $this->{hdpath} );
   if ($b) {
     $b->Start();
     my $line;
-    while(defined($line = $b->Next())) {
+    while(defined($line = $b->Next()) and $size < $max) {
       push @{$body}, $line . "\n";
+      $size += length $line + 1;
     }
     $b->Done();
   }
--- SA.pm       4 Jul 2003 20:03:18 -0000       1.18
+++ SA.pm       21 Jul 2003 18:05:01 -0000      1.19
@@ -161,10 +161,7 @@
 # Do the SpamAssassin checks on the passed in message
 sub Checks {
   my $message = shift;
-
-  my($dfhandle);
-  my($dfilename, $dfile, $dsize, @WholeMessage, $SAResult, $SAHitList);
-  my($HighScoring, $SAScore);
+  my(@WholeMessage, $SAResult, $SAHitList, $HighScoring, $SAScore);

   # Bail out and fake a miss if too many consecutive SA checks failed
   my $maxfailures = MailScanner::Config::Value('maxspamassassintimeouts');
@@ -196,9 +193,13 @@
        # LEOH 26/03/2003 We do not always have dpath file, so we ask to
   #                 the store module the size
   # $dsize = (stat($message->{store}{dpath}))[7];
-  $dsize = $message->{store}->dsize();
-  return (-1,0, MailScanner::Config::LanguageValue($message,'satoolarge'), 0)
-    if $dsize > MailScanner::Config::Value('maxspamassassinsize');
+  #$dsize = $message->{store}->dsize();
+  #$dmax = MailScanner::Config::Value('maxspamassassinsize');
+  #return (-1,0, MailScanner::Config::LanguageValue($message,'satoolarge'), 0)
+  #  if $dsize > MailScanner::Config::Value('maxspamassassinsize');
+  #MailScanner::Log::InfoLog("Truncating large message %s for SpamAssassin",
+  #                          $message->{id})
+  #  if $dsize > $dmax and MailScanner::Config::Value('logspam');

   # Construct the array of lines of the header and body of the message
   # JKF 30/1/2002 Don't chop off the line endings. Thanks to Andreas Piper
@@ -212,7 +213,8 @@
   return (-1,0, MailScanner::Config::LanguageValue($message, 'sanoheaders'), 0)
     unless @WholeMessage;
   push(@WholeMessage, "\n");
-  $message->{store}->ReadBody(\@WholeMessage);
+  $message->{store}->ReadBody(\@WholeMessage,
+                        MailScanner::Config::Value('maxspamassassinsize'));

   #print STDERR "Whole message is this:\n";
   #print STDERR "----------------------\n";
--- SMDiskStore.pm      4 Jul 2003 19:13:31 -0000       1.13
+++ SMDiskStore.pm      21 Jul 2003 18:05:01 -0000      1.14
@@ -286,15 +286,17 @@
 # Passed a ref to the array.
 sub ReadBody {
   my $this = shift;
-  my($body) = @_;
-  my($dh) = $this->{indhandle};
+  my($body,$max) = @_;
+  my $size = 0;
+  my $dh = $this->{indhandle};

   seek($dh, 0, 0); # Rewind the file

-  while(<$dh>) {
+  while(defined <$dh> and $size < $max) {
     # End of line characters are already there, so don't add them
     #push @{$body}, $_ . "\n";
     push @{$body}, $_;
+    $size += length $_;
   }
 }

--- ZMDiskStore.pm      4 Jul 2003 18:08:28 -0000       1.1.1.3
+++ ZMDiskStore.pm      21 Jul 2003 18:05:01 -0000      1.2
@@ -291,13 +292,15 @@
 #REVISO LEOH
 sub ReadBody {
   my $this = shift;
-  my($body) = @_;
+  my($body,$max) = @_;
+  my $size = 0;

   my $b= Body->new( $this->{hdpath} );
   $b->Start();
   my $line;
-  while( $line= $b->Next() ) {
+  while(defined($line = $b->Next()) and $size < $max) {
     push @{$body}, $line;
+    $size += length $line;
   }
   $b->Done();
 }



Tony.
--
f.a.n.finch  <dot at dotat.at>  http://dotat.at/
ST DAVIDS HEAD TO COLWYN BAY, INCLUDING ST GEORGES CHANNEL: SOUTH TO SOUTHEAST
5 OR 6 LOCALLY 4 VEERING SOUTHWEST TO WEST 4 OR 5, LATER EASING WEST 4 LOCALLY
3. OUTBREAKS OF RAIN AT FIRST, FOLLOWED BY SCATTERED SHOWERS THEN MAINLY FAIR.
MODERATE BECOMING MAINLY GOOD LATER. SLIGHT TO MODERATE BUILDING MODERATE TO
ROUGH IN THE WEST.



More information about the MailScanner mailing list