spamassassin-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apache.org+spamassas...@daniel-rudolf.de
Subject New Mail::SpamAssassin::Plugin::HeadersEqual plugin
Date Thu, 08 Sep 2016 16:05:36 GMT
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

Mime
View raw message