-
Notifications
You must be signed in to change notification settings - Fork 0
/
mmlearn
executable file
·54 lines (43 loc) · 1.16 KB
/
mmlearn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/sh
# Deployed via ansible
# Source http://www.jamesh.id.au/articles/mailman-spamassassin/mmlearn
MMHOME=/var/lib/mailman
SAHOME=/var/lib/spamassassin
list=$1
shift
HOME=$SAHOME/$list.prefs
export HOME
if [ ! -d $HOME ]; then
echo "Prefs for list $list not found"
exit 1
fi
if $MMHOME/bin/list_lists -b | grep -q $list > /dev/null 2>&1; then
:
else
echo "Mailing list $list not found"
exit 1
fi
tmpmbox=`mktemp ${TMPDIR:-/tmp}/mmlearn.mbox.XXXXXX`
# create an mbox file of all the held messages
PYTHONPATH=$MMHOME:$MMHOME/pythonlib python -c "
import os
import pickle
import email
from Mailman.mm_cfg import DATA_DIR
mbox = open('$tmpmbox', 'w')
files = [ file for file in os.listdir(DATA_DIR)
if file.startswith('heldmsg-$list') ]
for f in files:
filename = os.path.join(DATA_DIR, f)
if filename.endswith('.pck'):
msg = pickle.load(open(filename, 'rb')).as_string(unixfrom=True)
else:
msg = open(filename, 'r').read()
mbox.write(msg)
if msg[-1] != '\n': mbox.write('\n')
mbox.write('\n')
mbox.close()
"
sa-learn --showdots --spam --mbox $tmpmbox
rm -f $tmpmbox
chown -R debian-spamd.debian-spamd $HOME