Hi,
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
[/path/to/HeadersEqual.pm]
header SENDER_MISMATCH eval:headers_equal("ne", "From:addr",
"Return-Path: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:
https://gist.github.com/PhrozenByte/4af0045b6507ceb24e4231988c7d9fcf
Feedback is highly appreciated!
Cheers,
Daniel