diff -Nur smeserver-learn-1.0.old/createlinks smeserver-learn-1.0/createlinks --- smeserver-learn-1.0.old/createlinks 2021-02-23 13:32:11.805000000 -0500 +++ smeserver-learn-1.0/createlinks 2021-02-23 14:23:16.390000000 -0500 @@ -7,3 +7,8 @@ safe_touch('root/etc/e-smith/db/configuration/defaults/Learn/Exclude'); safe_touch('root/etc/e-smith/db/configuration/defaults/Learn/Include'); +my $event="smeserver-learn-update"; +templates2events("/etc/cron.d/Learn",$event); +templates2events("/etc/mail/spamassassin/local.cf",$event); +event_link("LearnSpam-init", $event, "04"); +event_link("LearnSpam-run", $event, "30"); diff -Nur smeserver-learn-1.0.old/root/etc/e-smith/db/configuration/force/spamassassin/status smeserver-learn-1.0/root/etc/e-smith/db/configuration/force/spamassassin/status --- smeserver-learn-1.0.old/root/etc/e-smith/db/configuration/force/spamassassin/status 1969-12-31 19:00:00.000000000 -0500 +++ smeserver-learn-1.0/root/etc/e-smith/db/configuration/force/spamassassin/status 2021-02-23 14:19:59.599000000 -0500 @@ -0,0 +1 @@ +enabled diff -Nur smeserver-learn-1.0.old/root/etc/e-smith/db/configuration/force/spamassassin/UseBayes smeserver-learn-1.0/root/etc/e-smith/db/configuration/force/spamassassin/UseBayes --- smeserver-learn-1.0.old/root/etc/e-smith/db/configuration/force/spamassassin/UseBayes 1969-12-31 19:00:00.000000000 -0500 +++ smeserver-learn-1.0/root/etc/e-smith/db/configuration/force/spamassassin/UseBayes 2021-02-23 14:20:19.445000000 -0500 @@ -0,0 +1 @@ +1 diff -Nur smeserver-learn-1.0.old/root/etc/e-smith/events/actions/LearnSpam-init smeserver-learn-1.0/root/etc/e-smith/events/actions/LearnSpam-init --- smeserver-learn-1.0.old/root/etc/e-smith/events/actions/LearnSpam-init 1969-12-31 19:00:00.000000000 -0500 +++ smeserver-learn-1.0/root/etc/e-smith/events/actions/LearnSpam-init 2021-02-23 14:32:38.915000000 -0500 @@ -0,0 +1,20 @@ +#!/bin/bash + +# default is 0, if kept to 0 we can not play there +/sbin/e-smith/db configuration setprop spamassassin UseBayes 1 + +# default is empty, we shall set it if we want to have a run +/sbin/e-smith/config getprop spamassassin BayesAutoLearnThresholdSpam >/dev/null|| /sbin/e-smith/config setprop spamassassin BayesAutoLearnThresholdSpam 6.00 +/sbin/e-smith/config getprop spamassassin BayesAutoLearnThresholdNonspam >/dev/null|| /sbin/e-smith/config setprop spamassassin BayesAutoLearnThresholdNonspam 0.10 + +# we really need spamassassin running +/sbin/e-smith/config setprop spamassassin status enabled + +# default is 0 for no reject +#/sbin/e-smith/config setprop spamassassin RejectLevel 12 + +# default is 5 +#/sbin/e-smith/config setprop spamassassin TagLevel 4 + +# default is medium +#/sbin/e-smith/config setprop spamassassin Sensitivity custom diff -Nur smeserver-learn-1.0.old/root/etc/e-smith/events/actions/LearnSpam-run smeserver-learn-1.0/root/etc/e-smith/events/actions/LearnSpam-run --- smeserver-learn-1.0.old/root/etc/e-smith/events/actions/LearnSpam-run 1969-12-31 19:00:00.000000000 -0500 +++ smeserver-learn-1.0/root/etc/e-smith/events/actions/LearnSpam-run 2021-02-23 14:21:17.357000000 -0500 @@ -0,0 +1,6 @@ +#!/bin/bash + +sa-learn --sync --dbpath /var/spool/spamd/.spamassassin -u spamd +chown spamd.spamd /var/spool/spamd/.spamassassin/bayes_* +chown spamd.spamd /var/spool/spamd/.spamassassin/bayes.mutex +chmod 640 /var/spool/spamd/.spamassassin/bayes_* diff -Nur smeserver-learn-1.0.old/root/usr/bin/Learn.pl smeserver-learn-1.0/root/usr/bin/Learn.pl --- smeserver-learn-1.0.old/root/usr/bin/Learn.pl 2021-02-23 14:47:51.066000000 -0500 +++ smeserver-learn-1.0/root/usr/bin/Learn.pl 2021-02-23 16:04:45.733000000 -0500 @@ -20,6 +20,7 @@ use Digest::MD5 qw(md5 md5_hex md5_base64); use File::Find; use File::Copy; +use File::Copy::Recursive; use File::Basename; use File::Path; use Encode qw/encode decode/; @@ -42,7 +43,7 @@ my $agesecs=60*60*24*$DelayToMove; #converts $agedays to seconds my $daysago=time-$agesecs; #the time stamp of $agedays ago in seconds my $daysago2=localtime($daysago); #the time stamp of $agedays ago in words - mainly for printing -my $SpamLinks = $sadb->get_prop("LearnAsSpam", "SpamLinks") or ""; +my $SpamLinks = $sadb->get_prop("LearnAsSpam", "SpamLinks") || ""; my @files; #getting user list @@ -103,10 +104,9 @@ my @logdirs = ($sadb->get_prop($mode, "Uniq") eq "enabled")? sort grep { /^$dirname$/ } readdir(LOGDIR) :sort grep { /$dirname/ } readdir(LOGDIR); closedir(LOGDIR); + ($login,$pass,$uid,$gid) = getpwnam($key) or die "$key not in passwd file"; # mk dir if not exist if (! @logdirs and ($sadb->get_prop($mode, "Uniq") eq "enabled")) { - ($login,$pass,$uid,$gid) = getpwnam($key) - or die "$key not in passwd file"; Vact();print "+->mkdir :". $MailDir . "/" . $dirname . "\n"; foreach $a ('','/cur','/tmp','/new'){ mkdir $MailDir . "/" . $dirname . "$a"; @@ -115,12 +115,32 @@ }; my $junkdir = $MailDir . "/.junkmail"; + unless ( -d $junkdir ) { + Vact();print "+->mkdir :". $junkdir . "\n"; + foreach $a ('','/cur','/tmp','/new'){ + mkdir $junkdir . "/" . "$a"; + chown $uid,$gid,$junkdir . "/" . "$a"; + } + + } + # create junkmail links if necessary - if ($mode eq "LearnAsSpam" and ($SpamLinks or $user->prop('SpamLinks') ) ) { - $Spamlinks= $Spamlinks ? $Spamlinks .",".$user->prop('SpamLinks'): $user->prop('SpamLinks') if ($user->prop('SpamLinks')); + my $Spamlinks = $user->prop('SpamLinks') || ""; + if ($mode eq "LearnAsSpam" and ($SpamLinks or $Spamlinks ) ) { + $Spamlinks= $SpamLinks ? $SpamLinks .",". $Spamlinks : $Spamlinks; + $Spamlinks =~ s/,$//; foreach $a (split(",",$Spamlinks)){ $a=(substr($a, 0, 1) eq '.')? $a: ".$a"; my $Link= $MailDir . "/" . $a; + next if ( $Link eq ".." || $Link eq "." || $Link eq "" ); + next if ( -l $Link); + if (-d $Link) { + Vact(); print "+->move previous dir $Link content to $junkdir\n"; + File::Copy::Recursive::dirmove($Link, $junkdir) or die "Can't move folder in place of our wanted link from %Link to $junkdir: $!"; + #side effect : ownership is lost + @files = ( glob( $junkdir . '/cur/*' ),glob( $junkdir . '/new/*' ), glob( $junkdir . '/tmp/*' ) ); + chown $uid, $gid, @files; + }; if (! -e $Link) { Vact(); print "+->create link $Link on $junkdir\n"; symlink($junkdir, $Link) or die "Can't create symlink from $Link to $junkdir: $!"; @@ -209,6 +229,10 @@ for my $test ( quotemeta $subjectTAG , quotemeta $tag) { ($Subject= $Subject) =~ s/$test//; } + # we also remove Spam tag or client will move the mail again in spam dir + $email->header_set("X-Spam-Flag",'NO'); + $email->header_set("X-Spam-Level",'*'); + $email->header_set("X-Spam-Status",'No, score=0.0 required=4.0 autolearn=disabled'); } # encoding as MIME Q (not B) with UTF8 as default. my $cleanTag= encode("MIME-Q",$sadb->get_prop($mode, "tag")); @@ -243,7 +267,7 @@ if ($newmd5 ne $md5) { `expand-template /etc/mail/spamassassin/local.cf`; - `/etc/init.d/spamd restart`; + `/usr/bin/systemctl restart spamassassin.service`; print "\n"; }