[Mimedefang] Mimedefang>2.32 breaks SA rbl

Dirk Mueller dmuell at gmx.net
Tue May 27 18:47:02 EDT 2003


On Die, 27 Mai 2003, David F. Skoll wrote:

> (I don't use RBL's within SA, so I never run into the problem.)

I've debugged this problem the last few days. There are several problems in 
fact, and the attached patch fixes them: 

- The synthesized Received: header didn't mention the envelope
  Recipient. SpamAssassin needs this information. 

- Mimedefang did not simulate a generation of a Message-ID if the
  mail is missing it. This is necessary for several SpamAssassin
  header tests to trigger correctly (it checks if it finds the
  QueueID in the Received lines in the MessageID and similiar)

- The Received headers were multiline Strings in a single
  array entry. Spamassassin doesn't cope with that, it needs
  single line in the message array. a split/^/m fixes this. 

I've tested a few messages and they trigger correctly the same score
in mimedefang and spamassassin (finally!!!). Of course there is
probably something else we still don't simulate correctly, but we'll find 
out. 

David, please apply. 


-- 
Dirk
-------------- next part --------------
--- mimedefang-2.33/mimedefang.pl.in	2003-04-25 15:16:11.000000000 +0200
+++ mimedefang-2.33-my//mimedefang.pl.in	2003-05-28 00:41:09.000000000 +0200
@@ -402,9 +402,10 @@
 	$hdr = sprintf("Received: from %s ([%s])\n",
 		       $Helo, $RealRelayAddr);
     }
-    $hdr .= sprintf("\tby %s (8.12.9/8.12.9+MIMEDefang) with ESMTP id %s;\n",
-		    $hn, $MsgID);
-    $hdr .= sprintf("\t%s\n", $strdate);
+    $hdr .= "\tby $hn (8.12.9/8.12.9+MIMEDefang) with ESMTP id $MsgID;\n";
+    $hdr .= sprintf("\tfor %s; %s\n", $Recipients[0], $strdate);
+
+    return $hdr;
 }
 
 #***********************************************************************
@@ -1198,14 +1199,17 @@
     # Use cached value if we have it
     return $PrivateMyHostName if defined($PrivateMyHostName);
 
-    # Otherwise execute "hostname"
-    $PrivateMyHostName = `hostname`;
-
-    if (defined($PrivateMyHostName)) {
-	chomp($PrivateMyHostName);
-    } else {
-	$PrivateMyHostName = "localhost.localdomain";
-    }
+    # Otherwise find out hostname
+    use Sys::Hostname;
+    $PrivateMyHostName = hostname;
+
+    $PrivateMyHostName = "localhost" if(!defined($PrivateMyHostName));
+
+    # now make it FQDN
+    my ($FQDNHostName) = gethostbyname($PrivateMyHostName);
+    $PrivateMyHostName = $FQDNHostName 
+        if(defined($FQDNHostName) and 
+           length($FQDNHostName) > length($PrivateMyHostName));
 
     return $PrivateMyHostName;
 }
@@ -1220,16 +1224,32 @@
 #  Generates RFC2822-compliant Date and Message-ID headers.
 #***********************************************************************
 sub gen_date_msgid_headers () {
-    my($now, $tm, $mid);
-    $tm = time;
-    $now = strftime("%a, %d %b %Y %H:%M:%S %z", localtime($tm));
-
-    # Generate a "random" message ID
-    $mid = rand();
-    $mid .= $tm . '@' . get_host_name();
-    return "Date: $now\nMessage-ID: <$mid>\n";
+    return "Date: " . strftime("%a, %d %b %Y %H:%M:%S %z", localtime(time)) .
+           &gen_msgid_header();
+}
+
+
+#***********************************************************************
+# %PROCEDURE: gen_msgid_header
+# %ARGUMENTS:
+#  None
+# %RETURNS:
+#  A string like this: "Message-ID: <message at id.com>\n"
+# %DESCRIPTION:
+#  Generates RFC2822-compliant Message-ID headers.
+#***********************************************************************
+sub gen_msgid_header () {
+    my $now = strftime("%Y%m%d%H%M", localtime(time));
+    my $qid = $QueueID;
+    $qid = rand() if ($qid eq "NOQUEUE");
+
+    # Generate a "random" message ID that looks
+    # similiar to sendmail's for SpamAssassin comparing
+    # Received / MessageID QueueID
+    return "Message-ID: <$now.$qid\@" . &get_host_name() . ">\n";
 }
 
+
 #***********************************************************************
 # %PROCEDURE: send_quarantine_notifications
 # %ARGUMENTS:
@@ -4971,10 +4991,11 @@
     my @msg = <IN>;
     close(IN);
 
-    # Synthesize a "Return-Path" and "Received:" header
+    # Synthesize a "Return-Path", Message-ID and "Received:" header
     my @sahdrs;
-    push (@sahdrs, sprintf("Return-Path: %s\n", $Sender));
-    push (@sahdrs, synthesize_received_header());
+    push (@sahdrs, "Return-Path: $Sender\n");
+    push (@sahdrs, split (/^/m, &synthesize_received_header()));
+    push (@sahdrs, &gen_msgid_header()) if($MessageID eq "NOQUEUE");
 
     unshift (@msg, @sahdrs);
 


More information about the MIMEDefang mailing list