Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tools:spamd [2022/07/08 01:27] – [Configure] darrontools:spamd [2022/07/12 13:25] (current) – external edit 127.0.0.1
Line 1: Line 1:
 +==== Spamassassin ====
 +
 +Setup on Debian for use with EXIM.
 +
 ===Install=== ===Install===
  
Line 5: Line 9:
 ===Configure=== ===Configure===
  
-==compile-spamd.sh==+==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__
 <code> <code>
 #! /bin/sh #! /bin/sh
Line 15: Line 27:
 </code> </code>
  
-===Update===+==Update==
  
-Run from cron once per day, week or month.+Run from cron once per day to download new rules and recompile.
  
-==update-spamd.sh==+__update-spamd.sh__
 <code> <code>
 #! /bin/sh #! /bin/sh
 sa-update --nogpg sa-update --nogpg
-compile-spamd.sh+if test $? -eq 0; then 
 +    compile-spamd.sh 
 +fi
 exit 0 exit 0
 +</code>
 +
 +
 +===Run it===
 +
 +<code>
 +#! /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
 +</code>
 +
 +=== Plugin===
 +
 +Example plugin I wrote to catch fake mailing list spam.
 +
 +<code>
 +#! /usr/bin/perl
 +#
 +# By
 +#       Darron M Broad, July 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.4.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) = @_;
 +
 +        $from = $permsgstatus->get("EnvelopeFrom");
 +        my @to = split /@/, $permsgstatus->get("To:addr"); # x@y.z
 +        my $name = $to[0];
 +        my $host = $to[1];
 +        if ($from && $name && $host) {
 +                # *mail-user=host@mail.*
 +                if ((index $from, "mail-$name=$host\@mail\.") > 0) {
 +                        info("LocalPlugin: SPAM $from");
 +                        return 1;
 +                }
 +                # newsletter-user=host@mail.*
 +                if ((rindex $from, "newsletter-$name=$host\@mail\.", 0) == 0) {
 +                        info("LocalPlugin: SPAM $from");
 +                        return 1;
 +                }
 +        }
 +        return 0;
 +}
 +
 +1;
 +
 +# vim: shiftwidth=4 tabstop=4 noexpandtab
 +</code>
 +
 +===Spam===
 +
 +Here is a PHP command line tool to send test spam.
 +
 +Change Host,  Sender and addAddress as appropriate.
 +
 +<code>
 +#! /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
 + */
 +?>
 </code> </code>