-
Notifications
You must be signed in to change notification settings - Fork 0
/
sa-train-user.sh
65 lines (53 loc) · 1.48 KB
/
sa-train-user.sh
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
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/bash
shopt -s extglob
if [[ -r /etc/sa-train.conf ]]; then
while read -r name value; do
if [[ -n "$name" && ! "$name" =~ ^\s*# ]]; then
typeset "$name=$value"
fi
done < /etc/sa-train.conf
fi
if [[ -r ~/.sa-train/config ]]; then
while read -r name value; do
if [[ -n "$name" && ! "$name" =~ ^\s*# ]]; then
typeset "$name=$value"
fi
done < ~/.sa-train/config
fi
SPAMFOLDER=${spam_folder:-Spam}
typeset -i "MAX_AGE=${max_age:-90}"
function examine
{
local subdir=$1
if [[ -n "$subdir" && "$subdir" == "${subdir%/}" ]]; then
subdir="$subdir/"
fi
if [[ ! -d ./${subdir}cur ]]; then
return
fi
local action=${2:-ham}
echo Learning from ${subdir:-Inbox} as $action
pushd ${subdir}cur
if [[ -f ~/.sa-train/last$1 ]]; then
find -H . -type f -regex ".*:2,[a-zA-Z]*S[a-zA-Z]*$" -newer ~/.sa-train/last$1 -exec sa-learn --$action --no-sync {} \+;
else
find . -type f -regex ".*:2,[a-zA-Z]*S[a-zA-Z]*$" -mtime -$MAX_AGE -exec sa-learn --$action --no-sync {} \+;
fi
rm -f ~/.sa-train/last$1
if [[ $( ls *\:2,*([a-zA-Z])S*([a-zA-Z]) 2>/dev/null ) ]]; then
ln -s $( realpath $( ls -1t *\:2,*([a-zA-Z])S*([a-zA-Z]) | head -1) ) ~/.sa-train/last$1;
fi
popd
}
if [ -d ~/Maildir ]; then
mkdir -p ~/.sa-train
pushd ~/Maildir
examine .$SPAMFOLDER spam
examine
examine .Root
for inboxdir in ./.INBOX*; do
examine $(basename $inboxdir);
done;
echo sa-learn --sync
popd
fi