-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdspam-learn
executable file
·138 lines (127 loc) · 4.9 KB
/
dspam-learn
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/bash
set -euo pipefail
# normally this is a good idea, but in this case it messes with $BE_NICE
#IFS=$'\n\t'
########################################################################
# 2015-02-23 Christopher Hirschmann [email protected]
# 2016-02-01 Christian González [email protected]
########################################################################
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
########################################################################
#
# This script will look for a system user's primary maildir
# $HOME/Maildir and possible vMailMgr maildirs under $HOME/users/
# and search them for folders indicating a certain DSPAM setup:
#
# \
# \___ Inbox
# \
# \___ Junk || Spam || Junk-E-Mail
# \
# \___ als Spam lernen
# \
# \___ als Ham lernen
#
# If it finds this folder structure in any maildir, it will show files
# from the folders 'als Ham lernen' and 'als Spam lernen' to DSPAM (so
# it can learn) and after that it will delete them.
#
# You can make this script more verbose with '-v'.
#
# You can also test this script with '-n' in dry run mode. If combined
# with '-v' it will output what it would have done, but won't do any-
# thing.
#
########################################################################
DRYRUN=0;
VERBOSE=0;
while getopts ":hvn" Option
do
case $Option in
h ) echo -e "Usage:\n-n\tdry run\n-v\tbe verbose\n-h\tthis help message"; exit 0;;
n ) DRYRUN=1; ;;
v ) VERBOSE=1; ;;
* ) echo -e "ERROR: Unimplemented option chosen: -${OPTARG}"; exit 1;;
esac
done
if `grep -q "CentOS release 5" /etc/redhat-release`;
then
# ionice -c3 is not supported on CentOS 5 for users != root (needs Linux => 2.6.25)
# so let's fall back to ionice -c2 -n7 which is better than nothing
BE_NICE="nice -n 19 ionice -c2 -n7";
else
BE_NICE="nice -n 19 ionice -c3";
fi
[ "${DRYRUN}" == "1" ] && echo "Running in dry run mode."
# to be able to process directory and file names regardless of any kind
# of weird characters we need to list these names separated by null
# characters and process them accordingly.
( find ${HOME} -name Maildir -print0 ; if [ -d ${HOME}/users ]; then find ${HOME}/users/ -mindepth 1 -maxdepth 1 -print0 ; fi )| while read -d $'\0' -r DIR ;
do
[ "${VERBOSE}" == "1" ] && echo -e "\nTrying to find Junk directory in ${DIR}.";
# Thunderbird, de-facto standard
# used, if nothing else found.
JUNKDIR=".Junk"
if [ -d "${DIR}/.Junk-E-Mail" ];
then
# Outlook
JUNKDIR=".Junk-E-Mail"
elif [ -d "${DIR}/.Spam" ];
then
# GMail
JUNKDIR=".Spam"
fi
if [ "${VERBOSE}" == "1" ];
then
echo -e "Found junk directory ${DIR}/${JUNKDIR}."
echo -e "Looking for mails in ${DIR}.";
fi
if [ -d "${DIR}/${JUNKDIR}.als Spam lernen" ];
then
for SUBDIR in new cur ;
do
find "${DIR}/${JUNKDIR}.als Spam lernen/${SUBDIR}" -type f -print0 | while read -d $'\0' -r spammail ;
do
[ "${VERBOSE}" == "1" ] && echo -e "\tEating spam \"${spammail}\". Yuk!"
if [ "${DRYRUN}" == "0" ];
then
${BE_NICE} /package/host/localhost/dspam/bin/dspam --class=spam --source=error --stdout < "${spammail}";
rm -f "${spammail}";
fi
done
done
else
[ "${VERBOSE}" == "1" ] && echo -e "\t'als Spam lernen' not found in ${DIR}/${JUNKDIR}."
fi
if [ -d "${DIR}/${JUNKDIR}.als Ham lernen" ];
then
for SUBDIR in new cur ;
do
find "${DIR}/${JUNKDIR}.als Ham lernen/${SUBDIR}" -type f -print0 | while read -d $'\0' -r hammail ;
do
[ "${VERBOSE}" == "1" ] && echo -e "\tEating ham \"${hammail}\". Yum!"
if [ "${DRYRUN}" == "0" ];
then
${BE_NICE} /package/host/localhost/dspam/bin/dspam --class=innocent --source=error --stdout < "${hammail}";
rm -f "${hammail}";
fi
done
done
else
[ "${VERBOSE}" == "1" ] && echo -e "\t'als Ham lernen' not found in ${DIR}/${JUNKDIR}."
fi
done
[ "${VERBOSE}" == "1" ] && echo "Done looking for mails."