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]; my $host = $to[1]; if ($name && $host) { $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; # vim: shiftwidth=4 tabstop=4 noexpandtab
Spam
Here is a PHP command line tool to send test spam.
Change Sender and AddAddress as appropriate.
#! /usr/bin/php -q <?php /* DEBIAN BUSTER */ require_once 'libphp-phpmailer/src/Exception.php'; require_once 'libphp-phpmailer/src/OAuth.php'; require_once 'libphp-phpmailer/src/PHPMailer.php'; require_once 'libphp-phpmailer/src/POP3.php'; require_once 'libphp-phpmailer/src/SMTP.php'; use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\SMTP; use PHPMailer\PHPMailer\Exception; $mail = new PHPMailer(true); $mail->SMTPDebug = SMTP::DEBUG_SERVER; $mail->isSMTP(); $mail->Host = 'localhost'; $mail->SMTPAuth = false; $mail->Sender = "newsletter-root=example.com@mail.example.com"; $mail->setFrom('root@example.com', 'SPAM'); $mail->addAddress('root@example.com', "SPAM"); $mail->addReplyTo('root@example.com', 'SPAM'); $mail->isHTML(false); $mail->Subject = 'Subject'; $mail->Body = 'Body'; try { $mail->send(); } catch (Exception $e) { echo $e->getMessage(); } /* * vim: shiftwidth=4 tabstop=4 softtabstop=4 expandtab */ ?>