--- qmail-scanner-queue.pl	2004-06-22 19:53:14.718750000 +0200
+++ qmail-scanner-queue.pl+max_recip_domain-patch	2004-06-22 20:09:31.593750000 +0200
@@ -1015,6 +1015,10 @@
   my ($ps_skipfile,$extension);
   my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks,$fsize);
   my ($attachment_list,$perlscan_time);
+  #these are for max_recip_domain patch
+  my (@recips_array);
+  my ($single_recip);
+  my (%recip_domain);
   &debug("p_s: starting scan of directory \"$ENV{'TMPDIR'}\"...");
   
   use DB_File;
@@ -1039,7 +1043,25 @@
       $var =~ s/^[0-9]+://;
       $type =~ s/^Virus-//g;
       &debug("p_s:  checking for objects containing $type: $var");
-      if ($headers{$type} =~ /^$var$/) {
+      if ($var =~ /^[0-9]+$/) {
+        &debug("p_s:  max recipients allowed for domain $type: $var");
+        @recips_array = split(/\0/,$trecips);
+        foreach $single_recip (@recips_array) {
+          $single_recip =~ s/^.+@//;
+          if (!defined($recip_domain{$single_recip})) {
+            $recip_domain{$single_recip} = 1;
+            &debug("p_s:   -> $single_recip set to 1");
+          } else {
+            $recip_domain{$single_recip}++;
+            &debug("p_s:   -> $single_recip incremented to $recip_domain{$single_recip}");
+          }
+        }
+        if ($var < $recip_domain{$type}) {
+          $quarantine_description="maximum email recipients for domain $type exceeded; $var allowed, $recip_domain{$type} found";
+          $quarantine_event="Perlscan:max_recip_domain";
+          &debug("p_s:   -> max email recipients for domain $type exceeded ($recip_domain{$type}/$var)");
+        }
+      } elsif ($headers{$type} =~ /^$var$/) {
 	$quarantine_description="$desc";
 	($quarantine_event=$quarantine_description) =~ s/\s/_/g;
 	$quarantine_event="Perlscan:".substr($quarantine_event,0,$QE_LEN);
@@ -1690,7 +1712,7 @@
       chomp;
       $count++;
       ($match,$type,$descr)=split(/\t+/,$_,3);
-      if ( $match eq "" || ($type !~ /^[0-9]+$/ && $type !~ /^Virus-[0-9a-z\_\-]+:$/i) ) {
+      if ( $match eq "" || ($type !~ /^[0-9]+$/ && $type !~ /^Virus-[0-9a-z\_\-]+:$/i && $match !~ /^[0-9]+$/) ) {
 	print "ERROR: incorrect format on line \"$line\"\n";
 	&error_condition("ERROR: incorrect format on line \"$line\"");
       } else {
@@ -1709,11 +1731,14 @@
 	  $match =~ s/^\^|\$$//g;
 	  #Now make unique
 	  $match = "$line:$match";
-	  $type =~ s/:$//;
-	  $type =~ /^Virus\-(.*)/;
-	  if ($1 !~ /^(MAILFROM|RCPTTO|TCPREMOTEIP)$/) {
-	    $type="Virus-".tolower($1);
-	  }
+          #This one is only needed for header matching, not for max_recip_domain patch
+          if ($type =~ /^Virus.*/) {
+	    $type =~ s/:$//;
+	    $type =~ /^Virus\-(.*)/;
+	    if ($1 !~ /^(MAILFROM|RCPTTO|TCPREMOTEIP)$/) {
+	      $type="Virus-".tolower($1);
+	    }
+          }
 	}
 	$array{"$match"}="$type\t$descr";
       }
