--- /root/unstable/mailscanner/mailscanner/bin/MailScanner/SA.pm	Thu Jan  9 19:58:29 2003
+++ SA.pm	Thu Jan  9 19:56:52 2003
@@ -2,7 +2,7 @@
 #   MailScanner - SMTP E-Mail Virus Scanner
 #   Copyright (C) 2002  Julian Field
 #
-#   $Id: SA.pm,v 1.34 2003/01/09 14:26:26 jkf Exp $
+#   $Id: SA.pm,v 1.33 2002/12/04 16:37:54 jkf Exp $
 #
 #   This program is free software; you can redistribute it and/or modify
 #   it under the terms of the GNU General Public License as published by
@@ -42,7 +42,7 @@
 use vars qw($VERSION);
 
 ### The package version, both in 1.23 style *and* usable by MakeMaker:
-$VERSION = substr q$Revision: 1.34 $, 10;
+$VERSION = substr q$Revision: 1.33 $, 10;
 
 # Attributes are
 #
@@ -123,11 +123,28 @@
   # Bail out and fake a miss if too many consecutive SA checks failed
   my $maxfailures = MailScanner::Config::Value('maxspamassassintimeouts');
 
-  return (0,0,
-    sprintf(MailScanner::Config::LanguageValue($message,'sadisabled'),
-            $maxfailures), 0)
-    if $maxfailures>0 &&
-       $safailures>=$maxfailures;
+  # If we get maxfailures consecutive timeouts, then disable the
+  # SpamAssassin RBL checks in an attempt to get it working again.
+  # If it continues to time out for another maxfailures consecutive
+  # attempts, then disable it completely.
+  if ($maxfailures>0) {
+    if ($safailures>=2*$maxfailures) {
+      return (0,0,
+        sprintf(MailScanner::Config::LanguageValue($message,'sadisabled'),
+        2*$maxfailures), 0);
+    } elsif ($safailures>$maxfailures) {
+      $MailScanner::SA::SAspamtest->{conf}->{skip_rbl_checks} = 1;
+    } elsif ($safailures==$maxfailures) {
+      $MailScanner::SA::SAspamtest->{conf}->{skip_rbl_checks} = 1;
+      MailScanner::Log::WarnLog("Disabling SpamAssassin RBL checks");
+    }
+  }
+
+  #return (0,0,
+  #  sprintf(MailScanner::Config::LanguageValue($message,'sadisabled'),
+  #          $maxfailures), 0)
+  #  if $maxfailures>0 &&
+  #     $safailures>=$maxfailures;
 
   # Also only do this if the message is reasonably small.
   $dsize = (stat($message->{store}{dpath}))[7];
@@ -255,9 +272,15 @@
     # Increment the "consecutive" counter
     $safailures++;
     if ($maxfailures>0) {
-      MailScanner::Log::WarnLog("SpamAssassin timed out and was killed, " .
-                   "consecutive failure " . $safailures .
-                   " of " . $maxfailures);
+      if ($safailures>$maxfailures) {
+        MailScanner::Log::WarnLog("SpamAssassin timed out (with no RBL" .
+                     " checks) and was killed, consecutive failure " .
+                     $safailures . " of " . $maxfailures*2);
+      } else {
+        MailScanner::Log::WarnLog("SpamAssassin timed out and was killed, " .
+                     "consecutive failure " . $safailures .
+                     " of " . $maxfailures);
+      }
     } else {
       MailScanner::Log::WarnLog("SpamAssassin timed out and was killed");
     }