diff -Nur --no-dereference smeserver-qpsmtpd-2.7.0.old/root/etc/e-smith/templates/var/service/qpsmtpd/config/peers/local/71forcespamcheck smeserver-qpsmtpd-2.7.0/root/etc/e-smith/templates/var/service/qpsmtpd/config/peers/local/71forcespamcheck --- smeserver-qpsmtpd-2.7.0.old/root/etc/e-smith/templates/var/service/qpsmtpd/config/peers/local/71forcespamcheck 1969-12-31 19:00:00.000000000 -0500 +++ smeserver-qpsmtpd-2.7.0/root/etc/e-smith/templates/var/service/qpsmtpd/config/peers/local/71forcespamcheck 2021-11-16 17:59:32.999000000 -0500 @@ -0,0 +1,39 @@ +{ +# this is based on 70spamassassin fragment +# it does the same except it will force check on fetchmail inputs + +# You can run the spamassassin plugin with options. See perldoc +# plugins/spamassassin for details. +# +# spamassassin +# rejects mails with a SA score higher than 20 and munges the subject +# of the score is higher than 10. +# +# spamassassin reject_threshold 20 munge_subject_threshold 10 + + my $status = $spamassassin{status} || 'disabled'; + return "# spamassassin disabled" unless ($status eq "enabled"); + + my @options = qw(forcespamcheck); + + if ($spamassassin{Sensitivity} eq "custom") + { + if ($spamassassin{RejectLevel} > $spamassassin{TagLevel}) + { + push @options, "reject", $spamassassin{RejectLevel}; + } + } + + if ($spamassassin{SubjectTag} eq "enabled") + { + push @options, "munge_subject_threshold", $spamassassin{TagLevel}; + } + + my $size = $spamassassin{MaxMessageSize} || ''; + if ($size =~ m/^\d+$/) + { + push @options, "size_limit", $size; + } + + return join " ", @options; +} diff -Nur --no-dereference smeserver-qpsmtpd-2.7.0.old/root/usr/share/qpsmtpd/plugins/forcespamcheck smeserver-qpsmtpd-2.7.0/root/usr/share/qpsmtpd/plugins/forcespamcheck --- smeserver-qpsmtpd-2.7.0.old/root/usr/share/qpsmtpd/plugins/forcespamcheck 1969-12-31 19:00:00.000000000 -0500 +++ smeserver-qpsmtpd-2.7.0/root/usr/share/qpsmtpd/plugins/forcespamcheck 2021-11-16 17:59:32.795000000 -0500 @@ -0,0 +1,61 @@ +#!perl -w +=head1 NAME + +forcespamcheck - SpamAssassin integration for qpsmtpd + +=head1 DESCRIPTION + +Plugin that forces check if the mail is spam by using the "spamd" daemon +from the SpamAssassin package. F + +=head1 CONFIG +This plugins needs spamassassin like arguments +Refer to spamassassin plugin + +On top of that it uses a config file with an ip per line corresponding of +local_ip of the qpsmtpd server on which the remote client is trying to deliver +the mail. Please be cautious this is not the remote client ip ! +THe initial idea is to force spam check for some deamons by making them +sending to 127.0.0.200:25 so other daemons trying to deliver on 127.0.0.1:25 +or LAN client delivering on 192.168.0.1:25 will avoid the spam check, unless you +also specify those ips in forcespamcheck file. + +=cut + +use strict; +use warnings; +use Qpsmtpd::Constants; +use Qpsmtpd::DSN; +use Socket qw(:DEFAULT :crlf); +use IO::Handle; + +sub register { + my ($self, $qp, %args) = @_; + $self->log(LOGERROR, "Bad parameters for the forcespamcheck plugin") + if @_ % 2; + #first if spamassassin already loaded return DECLINED; not to load it twice + my @datahooked = $qp->hooks('data_post'); + for my $item (@datahooked) { + $self->log(LOGNOTICE,"spamassassin aleady loaded") if $item->{name} eq "spamassassin"; + return DECLINED if $item->{name} eq "spamassassin"; + } + # else we can go on + my $param = join(q{ }, map{qq{$_ $args{$_}}} keys %args); + my $ip = $self->qp->connection->local_ip; + # read here list of ip from file; or default on 127.0.0.200 + my %forcespamcheck = map { $_ => 1 } $self->qp->config('forcespamcheck'); + # we force spamcheck on 127.0.0.200 as used by fetchmail + $forcespamcheck{'127.0.0.200'} = 1; + return DECLINED unless (exists $forcespamcheck{$ip}); + my $plugin_line = "spamassassin " . $param; + my $this_plugin = $self->qp->_load_plugin($plugin_line, $self->qp->plugin_dirs); + $self->register_hook('data', 'data_handler'); +} + +sub data_handler { + my ($self, $transaction) = @_; + my $ip = $self->qp->connection->local_ip; + # logged only there to avoid double line in log in register. + $self->log(LOGINFO, + "forcing spamassassin check for connection on $ip"); +}