Bug ID: 7350
           Summary: Add Mail::SpamAssassin::Plugin::HeadersEqual plugin
           Product: Spamassassin
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Plugins

Created attachment 5404


I would like to share my (pretty simple) SA plugin I've developed recently to
do a pretty basic task: Comparing message headers against each other.

Since SA doesn't support this out-of-the-box and because I think that many
users want to do something like that (just search for it on Google), I would
like to submit my plugin as default plugin for the next appropriate SA release.
What do you guys think about that and do I have to agree to some CLA or

You can use the plugin to e.g. compare the various address headers of an email
against each other. If you want to compare the Return-Path: and From: headers,
you could do something like the following:

   loadplugin Mail::SpamAssassin::Plugin::HeadersEqual
   header SENDER_MISMATCH eval:headers_equal("ne", "From:addr",
   score  SENDER_MISMATCH 0.5

As you can see, SA will increase the score by 0.5 when the From: and
Return-Path: headers don't match ("ne" for "not equal"). The plugin passes all
headers to Mail::SpamAssassin::PerMsgStatus->get(). This particularly allows
you to append :raw, :addr and :name to header names to adjust what is compared.
:addr e.g. causes SA to remove everything except the first email address from
the header field.

Please note that I'm not suggesting to add this particular rule to SA's default
rules (it produces many false positives), it's just an example.

You're not limited to comparing two headers, you can use a arbitrary number of
headers. Here's the full syntax:

   header HEADERS_EQUAL     eval:headers_equal(header1, header2, ...)
   header HEADERS_EQUAL     eval:headers_equal("eq", header1, header2, ...)
   header HEADERS_NOT_EQUAL eval:headers_equal("ne", header1, header2, ...)

This kind of functionality is traditionally realized using regexps, however,
regexps are very inflexible and expensive for this particular use case. AFAIK
there's no similar plugin yet.

The plugin's code is attached. Additionally you can find it on GitHub Gist:

Feedback is highly appreciated!


You are receiving this mail because:
You are the assignee for the bug.

Reply via email to