Hi!

I thought it might be useful to have a simple way of adding custom header that 
SpamAssassin rules can match on. With this small patch the list
@SpamAssassinHeaders
is available from relay_begin and on.

To add headers simple put them in the list (they should end with "\n"). Here's 
an example from my filter:
---8<---
my ($hits, $req, $names, $report);
# Add extra headers for checks?
if ($RelayHostname) {
        my $xh = sprintf('X-Reverse-FQDN-Check-Results: 
IP_FQDN_%02u,USER_FQDN_%02u,MAIL_FQDN_%02u,NO_FQDN_%02u',
                        check_ip_fqdn($RelayHostname,$RelayAddr),
                        check_user_fqdn($RelayHostname),
                        check_mail_fqdn($RelayHostname),
                        check_no_fqdn($RelayHostname,$RelayAddr),
        );
        debug_log(1,"$xh, $RelayHostname, $RelayAddr");
        push @SpamAssassinHeaders, "$xh\n";
}
if ($is_result_query) {
        debug_log(2,"spam: running spamassassin query");
        ($hits, $req, $names, $report) = 
spam_assassin_check('/usr/local/etc/mimedefang/sa-mimedefang-query.cf');
} else {
        debug_log(2,"spam: running spamassassin");
        ($hits, $req, $names, $report) = spam_assassin_check();
}
---8<---

The headers are added when mimedefang.pl adds other headers before calling 
SpamAssassin, so this ought to be cheaper than updating the files that 
mimedefang.pl uses when creating messages for SpamAssassin.

If this patch is a bad idea, please tell me so. :-)

Regards
/Jonas
--
Jonas Eckerman, FSDB & Fruktträdet
http://whatever.frukt.org/
http://www.fsdb.org/
http://www.frukt.org/
--- mimedefang.pl       Fri May 12 15:58:29 2006
+++ mimedefang.pl.new   Fri May 12 15:48:48 2006
@@ -58,7 +58,8 @@
            $AddApparentlyToForSpamAssassin $WarningCounter
            @VirusScannerMessageRoutines @VirusScannerEntityRoutines
            $VirusScannerRoutinesInitialized $MDOpenLogCalled
-           %SendmailMacros %RecipientMailers $CachedTimezone);
+           %SendmailMacros %RecipientMailers $CachedTimezone
+           @SpamAssassinHeaders);
 
 use vars qw($GeneralWarning);
 use vars qw($HTMLFoundEndBody $HTMLBoilerplate $SASpamTester);
@@ -5472,6 +5473,7 @@
     undef @StatusTags;
     undef @ESMTPArgs;
     undef @SenderESMTPArgs;
+    undef @SpamAssassinHeaders;
 }
 
 sub builtin_create_parser () {
@@ -5602,6 +5604,9 @@
        }
     }
 
+    # Setup empty spamassassin header list
+    @SpamAssassinHeaders = ();
+
     # Call pre-scan filter if defined
     if (defined(&filter_begin)) {
        push_status_tag("In filter_begin");
@@ -6478,6 +6483,7 @@
        push(@sahdrs, "Apparently-To: " .
             join(", ", @Recipients) . "\n");
     }
+    unshift (@msg, @SpamAssassinHeaders);
     unshift (@msg, @sahdrs);
     my $sa_ver = Mail::SpamAssassin->VERSION();
     # Only keep major version number
_______________________________________________
NOTE: If there is a disclaimer or other legal boilerplate in the above
message, it is NULL AND VOID.  You may ignore it.

Visit http://www.mimedefang.org and http://www.roaringpenguin.com
MIMEDefang mailing list [email protected]
http://lists.roaringpenguin.com/mailman/listinfo/mimedefang

Reply via email to