[Mimedefang] Cool MIMEDefang/SpamAssassin trick...

Mark Roedel MarkRoedel at letu.edu
Fri Feb 22 15:38:41 EST 2002


Just realized I hadn't ever posted this here.  Mentioned it in the
SpamAssassin mailing list, and it looks like there'll be a function
added to their library to do the same, but in the meantime...

When I first started using SpamAssassin, my approach was just to add an
X-Spam-Warning header to any message with a score >= 5.  Works
beautifully, and allows those users who want it to create a filtering
rule in their mail client to automatically route those messages to a
different folder or whatever.

However, some people are subscribed to mailing lists, etc., that
occasionally look marginally like spam, and wondered whether there was
anything that could be done to reduce that sort of false positive.  I
initially thought about defining some sort of a graduated (green=5,
yellow=10, red=15) structure, but thought that might complicate the
filtering logic on the client side beyond what was necessary.

What I wound up doing instead was to create an X-Spam-Level header that
contains a string of *'s equivalent to the integer part of the
SpamAssassin score.  This lets a user who doesn't like the default
threshold to pick their own by looking for a header that contains, for
example, the string "X-Spam-Level: **********".

Here's the pertinent part of my mimedefang-filter code:

> sub filter_begin {
>   use POSIX qw(floor);
>   my $hits;
>   my $req;
>   my $names;
>   my $report;
>   my $spamassassintag = "SpamAssassin v2.1";
>   my $hitsint;
>   my $spamgraphchar = '*';
>   my $spamgraph;
>
>   # Don't run SA against messages bigger than 100k
>   if ((-s "./INPUTMSG") <= (100 * 1024)) {
>     ($hits,$req,$names,$report) = spam_assassin_2_check();
>     if ($hits >= $req) {
>       action_add_header("X-Spam-Warning", "$hits ($spamassassintag)");
>     }
>     if ($hits > 0) {
>       $hitsint = floor($hits);
>       $spamgraph = $spamgraphchar x $hitsint;
>       action_add_header("X-Spam-Level","$spamgraph
($spamassassintag)");
>     }
>   }
> }


---
Mark Roedel           | "One thing a computer can do that most
Systems Programmer    |  humans can't is be sealed up in a
LeTourneau University |  cardboard box and sit in a warehouse."
Longview, Texas  USA  |                        -- Jack Handey



More information about the MIMEDefang mailing list