> And here we are (warning: untested).

Arrgl. Missed to change the last two replace by add. See
attached for the correct diff.

-kju

-- 
      It's an insane world, but i'm proud to be a part of it. -- Bill Hicks
--- /home/kju/qpsmtpd/qpsmtpd-cvs/plugins/spamassassin  2004-09-24 18:41:51.000000000 
+0200
+++ spamassassin        2004-09-24 19:01:02.000000000 +0200
@@ -50,6 +50,15 @@
 domain sockets for spamd.  This is faster and more secure than using
 a TCP connection.
 
+=item leave_old_headers [0|1|2]
+
+Another mail server before might have checked this mail already and may have
+added X-Spam-Status, X-Spam-Flag and X-Spam-Check-By lines. In general this
+headers can not be trusted (may be forged by an spammer) and should be 
+removed from the message (which is default or parameter '0'). You may want
+to opt for renaming them to X-Old-... (parameter '1') or leaving them 
+intact (parameter '2'). Think careful before making an decision.
+
 =back
 
 With both of the first options the configuration line will look like the following
@@ -89,6 +98,8 @@
   $self->log(6, "check_spam");
   return (DECLINED) if $transaction->body_size > 500_000;
 
+  my $leave_old_headers = $self->{_args}->{leave_old_headers} || 0;
+
   my $remote  = 'localhost';
   my $port    = 783;
   if ($port =~ /\D/) { $port = getservbyname($port, 'tcp') }
@@ -144,7 +155,21 @@
   my $line0 = <SPAMD>; # get the first protocol lines out
   if ($line0) {
     $self->log(6, "check_spam: spamd: $line0");
-    $transaction->header->replace("X-Spam-Check-By", $self->qp->config('me'), 0);
+
+    if ( $leave_old_headers == 1 )
+    {
+      foreach my $header ( $transaction->header->get('X-Spam-Check-By') )
+      {
+        $transaction->header->add('X-Old-Spam-Check-By', $header);
+      }
+    }
+    
+    if ( $leave_old_headers == 0 || $leave_old_headers == 1 )
+    {
+      $transaction->header->delete('X-Spam-Check-By');
+    }
+
+    $transaction->header->add("X-Spam-Check-By", $self->qp->config('me'), 0);
   }
 
   my ($flag, $hits, $required);
@@ -162,8 +187,27 @@
   $flag = $flag eq 'True' ? 'Yes' : 'No';
   $self->log(6, "check_spam: finished reading from spamd");
 
-  $transaction->header->replace('X-Spam-Flag', 'YES', 0) if ($flag eq 'Yes');
-  $transaction->header->replace('X-Spam-Status',
+  if ( $leave_old_headers == 1 )
+  {
+    foreach my $header ( $transaction->header->get('X-Spam-Flag') )
+    {
+      $transaction->header->add('X-Old-Spam-Flag', $header);
+    }
+
+    foreach my $header ( $transaction->header->get('X-Spam-Status') )
+    {
+      $transaction->header->add('X-Old-Spam-Status', $header);
+    }
+  }
+    
+  if ( $leave_old_headers == 0 || $leave_old_headers == 1 )
+  {
+    $transaction->header->delete('X-Spam-Flag');
+    $transaction->header->delete('X-Spam-Status');
+  }
+
+  $transaction->header->add('X-Spam-Flag', 'YES', 0) if ($flag eq 'Yes');
+  $transaction->header->add('X-Spam-Status',
                            "$flag, hits=$hits required=$required\n" .
                            "\ttests=$tests", 0);
   $self->log(5, "check_spam: $flag, hits=$hits, required=$required, " .

Reply via email to