This is an old revision of the document!


Spamassassin

Setup on Debian for use with EXIM.

Install

apt-get install spamassassin sa-compile

Configure

Local

Edit /etc/spamassassin/local.cf to add local rules.

Compile

Compiling rules will speed up spamd but it will work otherwise.

compile-spamd.sh

#! /bin/sh
sa-compile
chown -R debian-spamd:debian-spamd /var/lib/spamassassin
chmod -R go-w,go+rX /var/lib/spamassassin/compiled
kill -HUP `cat /var/run/spamd.pid`
exit 0
Update

Run from cron once per day to download new rules and recompile.

update-spamd.sh

#! /bin/sh
sa-update --nogpg
if test $? -eq 0; then
    compile-spamd.sh
fi
exit 0

Run it

#! /bin/sh
export TZ="UTC"
rm -f /var/run/spamd.pid
exec /usr/sbin/spamd --helper-home-dir=/var/lib/spamassassin --create-prefs --nouser-config -udebian-spamd -gdebian-spamd --socketpath=/var/run/spamd.sock --socketowner=debian-spamd --socketgroup=debian-spamd --socketmode=0777 --max-children 5 --pidfile /var/run/spamd.pid

Plugin

Example plugin I wrote to catch fake mailing list spam.

:...skipping...
#! /usr/bin/perl
#
# By
#       Darron M Broad 2022
#
# See:
#       https://spamassassin.apache.org/full/3.4.x/doc/Mail_SpamAssassin_Plugin.html
#       https://spamassassin.apache.org/full/3.4.x/doc/Mail_SpamAssassin_Logger.html
#       https://spamassassin.apache.org/full/3.3.x/doc/Mail_SpamAssassin_PerMsgStatus.html
#
# /etc/spamassassin/local.cf:
#
#       loadplugin LocalPlugin /etc/spamassassin/local/plugin.pm
#
#       header          LOCAL_FAKE_LIST eval:check_for_fake_list()
#       score           LOCAL_FAKE_LIST 100
#       describe        LOCAL_FAKE_LIST From Fake List

package LocalPlugin;

use Mail::SpamAssassin::Plugin;
use Mail::SpamAssassin::Logger;
use Mail::SpamAssassin::PerMsgStatus;

our @ISA = qw(Mail::SpamAssassin::Plugin);

sub new
{
        my($class, $mailsa) = @_;

        $class = ref($class) || $class;
        my $self = $class->SUPER::new($mailsa);
        bless ($self, $class);

        $self->register_eval_rule("check_for_fake_list");

        info("LocalPlugin: REGISTERED");

        return $self;
}

sub check_for_fake_list
{
        my($self, $permsgstatus) = @_;

        $path = $permsgstatus->get("EnvelopeFrom");
        my @to = split /@/, $permsgstatus->get("To:addr"); # x@y.z
        my $name = $to[0];
        if ($name) {
                my $host = $to[1];
                $s = "mail-$name=$host\@mail\.";
                if ((rindex $path, $s, 0) == 0) {
                        info("LocalPlugin: SPAM $path");
                        return 1;
                }
                $s = "newsletter-$name=$host\@mail\.";
                if ((rindex $path, $s, 0) == 0) {
                        info("LocalPlugin: SPAM $path");
                        return 1;
                }
        }
    return 0;
}

1;
This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies