spamassassin-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject New Mail::SpamAssassin::Plugin::HeadersEqual plugin
Date Thu, 08 Sep 2016 16:05:36 GMT

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.

It is mostly useful to compare the various address headers of an email, 
a frequent use case might be to compare the Return-Path: and From: headers:

   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.

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.

You can find it on GitHub Gist:

Feedback is highly appreciated!


View raw message