[Mimedefang] MimeDefang & Spamassassin

Michael D. Sofka sofkam at rpi.edu
Fri Feb 15 15:44:18 EST 2002


At 03:20 PM 2/15/2002 -0500, Rich West wrote:
>I'm trying to get Spamassassin to generate a report on the individual 
>spam messages so I can fine tune the scores.  I'm honestly trying to 
>track down why some of the non-spam messages were tagged as spam so I 
>can address it.
>
>However, it seems like Spamassassin either isn't inserting the reports, 
>or, and this is what I am guessing is more likely, MimeDefang isn't 
>allowing Spamassassin to alter the original message.

Mimedefang does not insert the full report by default.  But, you can
add it yourself.

>Is there a way to get the MimeDefang to allow for the report to be added 
>to the message.. at least, temporarily?
>
>When I run the message through the 'spamassassin', the message in 
>question is tagged as "not spam", but when it came through the mail 
>system, it was tagged as "Spam".

Here is what I'm doing on a SpamAssassin test machine.  I've set a lower
threshold of 3 so that near misses can also be checked.  The procedure
my_spam_assassin_check() is so I can run razor and DNS checks.  But,
be warned, razor is not reentrant.  That means you cannot run it with
the multiplexor.  If you're using the multiplexor use the default spam_assasin_check()
instead.


sub my_spam_assassin_check() {
    open(IN, "<./INPUTMSG") or return 0;

    my $mail = Mail::SpamAssassin::MyMailAudit->new(data=>\*IN);
    my $spamtest =
        Mail::SpamAssassin->new({
            local_tests_only   => 0,  # razor and DNS checks.
            dont_copy_prefs    => 1,
            userprefs_filename => "/etc/mail/spamassassin.cf"});

    my $status = $spamtest->check($mail);
    close(IN);

    my $hits = $status->get_hits;
    my $req = $status->get_required_hits();
    my $names = $status->get_names_of_tests_hit();
    my $report = $status->get_report();

    $status->finish();

    return ($hits, $req, $names, $report);
}

sub filter_begin {

    my $hits;
    my $req;
    my $names;
    my $report;

    # If you have a recognized anti-virus scanner, use this
    $VirusFound = message_contains_virus_sophos();

    if ((-s "./INPUTMSG") <= 100*1024) {
        ($hits,$req,$names, $report) = my_spam_assassin_check();

        if ($hits >= $req ) {
            action_add_header("X-Spam-Status", "Yes, hits=$hits required=$req tests=$names");
            action_add_header("X-Spam-Flag", "YES");
            action_change_header("Subject", "****SPAM**** $Subject");
        } else {
            action_add_header("X-Spam-Status", "No, hits=$hits required=$req tests=$names");
            action_add_header("X-Spam-Flag", "NO");
        }

        # For debugging.
        if ($hits >= 3.0) {
            $IS_SPAM=1;
        } else {
            $IS_SPAM=0;
        }
        $SA_REPORT = $report;
    } else {
        action_add_header("X-Spam-Warning", "Messages over 100k not checked");
        $SA_REPORT = "";
        $IS_SPAM = 0;
    }
}

sub filter_end {
    my($entity) = @_;
    if ($IS_SPAM) {
        append_boilerplate($entity, "\n$SA_REPORT\n");
    }
}

--
Michael Sofka                          sofkam at rpi.edu
CCT Sr. Systems Programmer  email, webmail, listproc, TeX, epistemology.
Rensselaer Polytechnic Institute, Troy, NY.    http://www.rpi.edu/~sofkam/




More information about the MIMEDefang mailing list