1 |
jpp |
1.1 |
diff -Nur smeserver-learn-1.0.old/createlinks smeserver-learn-1.0/createlinks |
2 |
|
|
--- smeserver-learn-1.0.old/createlinks 2021-02-23 13:32:11.805000000 -0500 |
3 |
|
|
+++ smeserver-learn-1.0/createlinks 2021-02-23 14:23:16.390000000 -0500 |
4 |
|
|
@@ -7,3 +7,8 @@ |
5 |
|
|
safe_touch('root/etc/e-smith/db/configuration/defaults/Learn/Exclude'); |
6 |
|
|
safe_touch('root/etc/e-smith/db/configuration/defaults/Learn/Include'); |
7 |
|
|
|
8 |
|
|
+my $event="smeserver-learn-update"; |
9 |
|
|
+templates2events("/etc/cron.d/Learn",$event); |
10 |
|
|
+templates2events("/etc/mail/spamassassin/local.cf",$event); |
11 |
|
|
+event_link("LearnSpam-init", $event, "04"); |
12 |
|
|
+event_link("LearnSpam-run", $event, "30"); |
13 |
|
|
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 |
14 |
|
|
--- smeserver-learn-1.0.old/root/etc/e-smith/db/configuration/force/spamassassin/status 1969-12-31 19:00:00.000000000 -0500 |
15 |
|
|
+++ smeserver-learn-1.0/root/etc/e-smith/db/configuration/force/spamassassin/status 2021-02-23 14:19:59.599000000 -0500 |
16 |
|
|
@@ -0,0 +1 @@ |
17 |
|
|
+enabled |
18 |
|
|
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 |
19 |
|
|
--- smeserver-learn-1.0.old/root/etc/e-smith/db/configuration/force/spamassassin/UseBayes 1969-12-31 19:00:00.000000000 -0500 |
20 |
|
|
+++ smeserver-learn-1.0/root/etc/e-smith/db/configuration/force/spamassassin/UseBayes 2021-02-23 14:20:19.445000000 -0500 |
21 |
|
|
@@ -0,0 +1 @@ |
22 |
|
|
+1 |
23 |
|
|
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 |
24 |
|
|
--- smeserver-learn-1.0.old/root/etc/e-smith/events/actions/LearnSpam-init 1969-12-31 19:00:00.000000000 -0500 |
25 |
|
|
+++ smeserver-learn-1.0/root/etc/e-smith/events/actions/LearnSpam-init 2021-02-23 14:32:38.915000000 -0500 |
26 |
|
|
@@ -0,0 +1,20 @@ |
27 |
|
|
+#!/bin/bash |
28 |
|
|
+ |
29 |
|
|
+# default is 0, if kept to 0 we can not play there |
30 |
|
|
+/sbin/e-smith/db configuration setprop spamassassin UseBayes 1 |
31 |
|
|
+ |
32 |
|
|
+# default is empty, we shall set it if we want to have a run |
33 |
|
|
+/sbin/e-smith/config getprop spamassassin BayesAutoLearnThresholdSpam >/dev/null|| /sbin/e-smith/config setprop spamassassin BayesAutoLearnThresholdSpam 6.00 |
34 |
|
|
+/sbin/e-smith/config getprop spamassassin BayesAutoLearnThresholdNonspam >/dev/null|| /sbin/e-smith/config setprop spamassassin BayesAutoLearnThresholdNonspam 0.10 |
35 |
|
|
+ |
36 |
|
|
+# we really need spamassassin running |
37 |
|
|
+/sbin/e-smith/config setprop spamassassin status enabled |
38 |
|
|
+ |
39 |
|
|
+# default is 0 for no reject |
40 |
|
|
+#/sbin/e-smith/config setprop spamassassin RejectLevel 12 |
41 |
|
|
+ |
42 |
|
|
+# default is 5 |
43 |
|
|
+#/sbin/e-smith/config setprop spamassassin TagLevel 4 |
44 |
|
|
+ |
45 |
|
|
+# default is medium |
46 |
|
|
+#/sbin/e-smith/config setprop spamassassin Sensitivity custom |
47 |
|
|
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 |
48 |
|
|
--- smeserver-learn-1.0.old/root/etc/e-smith/events/actions/LearnSpam-run 1969-12-31 19:00:00.000000000 -0500 |
49 |
|
|
+++ smeserver-learn-1.0/root/etc/e-smith/events/actions/LearnSpam-run 2021-02-23 14:21:17.357000000 -0500 |
50 |
|
|
@@ -0,0 +1,6 @@ |
51 |
|
|
+#!/bin/bash |
52 |
|
|
+ |
53 |
|
|
+sa-learn --sync --dbpath /var/spool/spamd/.spamassassin -u spamd |
54 |
|
|
+chown spamd.spamd /var/spool/spamd/.spamassassin/bayes_* |
55 |
|
|
+chown spamd.spamd /var/spool/spamd/.spamassassin/bayes.mutex |
56 |
|
|
+chmod 640 /var/spool/spamd/.spamassassin/bayes_* |
57 |
|
|
diff -Nur smeserver-learn-1.0.old/root/usr/bin/Learn.pl smeserver-learn-1.0/root/usr/bin/Learn.pl |
58 |
jpp |
1.3 |
--- smeserver-learn-1.0.old/root/usr/bin/Learn.pl 2021-02-23 14:47:51.066000000 -0500 |
59 |
|
|
+++ smeserver-learn-1.0/root/usr/bin/Learn.pl 2021-02-23 16:04:45.733000000 -0500 |
60 |
jpp |
1.1 |
@@ -20,6 +20,7 @@ |
61 |
|
|
use Digest::MD5 qw(md5 md5_hex md5_base64); |
62 |
|
|
use File::Find; |
63 |
|
|
use File::Copy; |
64 |
|
|
+use File::Copy::Recursive; |
65 |
|
|
use File::Basename; |
66 |
|
|
use File::Path; |
67 |
|
|
use Encode qw/encode decode/; |
68 |
jpp |
1.3 |
@@ -42,7 +43,7 @@ |
69 |
|
|
my $agesecs=60*60*24*$DelayToMove; #converts $agedays to seconds |
70 |
|
|
my $daysago=time-$agesecs; #the time stamp of $agedays ago in seconds |
71 |
|
|
my $daysago2=localtime($daysago); #the time stamp of $agedays ago in words - mainly for printing |
72 |
|
|
-my $SpamLinks = $sadb->get_prop("LearnAsSpam", "SpamLinks") or ""; |
73 |
|
|
+my $SpamLinks = $sadb->get_prop("LearnAsSpam", "SpamLinks") || ""; |
74 |
|
|
my @files; |
75 |
|
|
|
76 |
|
|
#getting user list |
77 |
|
|
@@ -103,10 +104,9 @@ |
78 |
|
|
my @logdirs = ($sadb->get_prop($mode, "Uniq") eq "enabled")? sort grep { /^$dirname$/ } readdir(LOGDIR) :sort grep { /$dirname/ } readdir(LOGDIR); |
79 |
|
|
closedir(LOGDIR); |
80 |
|
|
|
81 |
|
|
+ ($login,$pass,$uid,$gid) = getpwnam($key) or die "$key not in passwd file"; |
82 |
|
|
# mk dir if not exist |
83 |
|
|
if (! @logdirs and ($sadb->get_prop($mode, "Uniq") eq "enabled")) { |
84 |
|
|
- ($login,$pass,$uid,$gid) = getpwnam($key) |
85 |
|
|
- or die "$key not in passwd file"; |
86 |
|
|
Vact();print "+->mkdir :". $MailDir . "/" . $dirname . "\n"; |
87 |
|
|
foreach $a ('','/cur','/tmp','/new'){ |
88 |
|
|
mkdir $MailDir . "/" . $dirname . "$a"; |
89 |
|
|
@@ -115,12 +115,32 @@ |
90 |
|
|
}; |
91 |
|
|
|
92 |
|
|
my $junkdir = $MailDir . "/.junkmail"; |
93 |
|
|
+ unless ( -d $junkdir ) { |
94 |
|
|
+ Vact();print "+->mkdir :". $junkdir . "\n"; |
95 |
|
|
+ foreach $a ('','/cur','/tmp','/new'){ |
96 |
|
|
+ mkdir $junkdir . "/" . "$a"; |
97 |
|
|
+ chown $uid,$gid,$junkdir . "/" . "$a"; |
98 |
|
|
+ } |
99 |
|
|
+ |
100 |
|
|
+ } |
101 |
|
|
+ |
102 |
|
|
# create junkmail links if necessary |
103 |
|
|
- if ($mode eq "LearnAsSpam" and ($SpamLinks or $user->prop('SpamLinks') ) ) { |
104 |
|
|
- $Spamlinks= $Spamlinks ? $Spamlinks .",".$user->prop('SpamLinks'): $user->prop('SpamLinks') if ($user->prop('SpamLinks')); |
105 |
|
|
+ my $Spamlinks = $user->prop('SpamLinks') || ""; |
106 |
|
|
+ if ($mode eq "LearnAsSpam" and ($SpamLinks or $Spamlinks ) ) { |
107 |
|
|
+ $Spamlinks= $SpamLinks ? $SpamLinks .",". $Spamlinks : $Spamlinks; |
108 |
|
|
+ $Spamlinks =~ s/,$//; |
109 |
jpp |
1.1 |
foreach $a (split(",",$Spamlinks)){ |
110 |
|
|
$a=(substr($a, 0, 1) eq '.')? $a: ".$a"; |
111 |
|
|
my $Link= $MailDir . "/" . $a; |
112 |
jpp |
1.3 |
+ next if ( $Link eq ".." || $Link eq "." || $Link eq "" ); |
113 |
|
|
+ next if ( -l $Link); |
114 |
jpp |
1.1 |
+ if (-d $Link) { |
115 |
jpp |
1.3 |
+ Vact(); print "+->move previous dir $Link content to $junkdir\n"; |
116 |
|
|
+ File::Copy::Recursive::dirmove($Link, $junkdir) or die "Can't move folder in place of our wanted link from %Link to $junkdir: $!"; |
117 |
|
|
+ #side effect : ownership is lost |
118 |
|
|
+ @files = ( glob( $junkdir . '/cur/*' ),glob( $junkdir . '/new/*' ), glob( $junkdir . '/tmp/*' ) ); |
119 |
|
|
+ chown $uid, $gid, @files; |
120 |
jpp |
1.1 |
+ }; |
121 |
|
|
if (! -e $Link) { |
122 |
|
|
Vact(); print "+->create link $Link on $junkdir\n"; |
123 |
|
|
symlink($junkdir, $Link) or die "Can't create symlink from $Link to $junkdir: $!"; |
124 |
jpp |
1.3 |
@@ -209,6 +229,10 @@ |
125 |
jpp |
1.1 |
for my $test ( quotemeta $subjectTAG , quotemeta $tag) { |
126 |
|
|
($Subject= $Subject) =~ s/$test//; |
127 |
|
|
} |
128 |
|
|
+ # we also remove Spam tag or client will move the mail again in spam dir |
129 |
|
|
+ $email->header_set("X-Spam-Flag",'NO'); |
130 |
|
|
+ $email->header_set("X-Spam-Level",'*'); |
131 |
|
|
+ $email->header_set("X-Spam-Status",'No, score=0.0 required=4.0 autolearn=disabled'); |
132 |
|
|
} |
133 |
|
|
# encoding as MIME Q (not B) with UTF8 as default. |
134 |
|
|
my $cleanTag= encode("MIME-Q",$sadb->get_prop($mode, "tag")); |
135 |
jpp |
1.3 |
@@ -243,7 +267,7 @@ |
136 |
jpp |
1.1 |
|
137 |
|
|
if ($newmd5 ne $md5) { |
138 |
|
|
`expand-template /etc/mail/spamassassin/local.cf`; |
139 |
jpp |
1.3 |
- `/etc/init.d/spamd restart`; |
140 |
jpp |
1.2 |
+ `/usr/bin/systemctl restart spamassassin.service`; |
141 |
jpp |
1.1 |
print "\n"; |
142 |
|
|
} |
143 |
|
|
|