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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
|
# -*- mode: python; -*-
import subprocess
processor.maildir_base = "~/Maildir"
processor.auto_reload_rcfile = True
def is_to_or_from(mail,address):
return (
mail["From"].contains(address)
or mail.target.contains(address))
def is_to_or_from_re(mail,address):
return (
mail["From"].matches(address)
or mail.target.matches(address))
def bogofilter_auto(mail):
p = subprocess.Popen(
["bogofilter", "-u", "-v", "-I", mail.path],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
(output, _) = p.communicate()
processor.log("*** Bogofilter result: {0!r}".format(output.rstrip()))
if p.returncode not in [0, 1, 2]:
processor.log_error(
"Error running bogofilter: Return code = {0!r}".format(
p.returncode))
return p.returncode
def bogofilter_ham(mail):
subprocess.call(["bogofilter", "-S", "-n", "-I", mail.path])
def bogofilter_spam(mail):
subprocess.call(["bogofilter", "-N", "-s", "-I", mail.path])
def handle_incoming_spam_training(mail):
bogofilter_spam(mail)
mail.move(".Bulk Mail")
def handle_incoming_ham_training(mail):
bogofilter_ham(mail)
mail.move(".Ham")
def handle_incoming_ham(mail):
my_filters(mail)
def handle_incoming_unknown(mail):
# Filter spam
spam = bogofilter_auto(mail)
if spam == 0:
mail.move(".Bulk Mail")
return
elif spam == 1:
mail.move(".Ham")
return
elif spam == 2:
# maybe spam
my_filters(mail)
return
else:
mail.move(".Error")
return
def my_filters(mail):
# Sort into software mailing lists
if mail["List-Id"].matches("bug-gsrc\.gnu\.org"):
mail.move(".software.bug-gsrc")
return
if mail["List-Id"].matches("bug-make\.gnu\.org"):
mail.move(".software.bug-make")
return
if mail["List-Id"].matches("help-make\.gnu\.org"):
mail.move(".software.help-make")
return
if mail["List-Id"].matches("social(|-discuss)\.gnu\.org"):
mail.move(".software.social")
return
# Sort email from some social websites
if mail["From"].matches("@facebook(|mail)\.com"):
mail.move(".Social.Facebook")
return
if mail["From"].matches("identi\.ca"):
mail.move(".Social.Identica")
return
if mail["From"].matches("twitter\.com"):
mail.move(".Social.Twitter")
return
if mail["From"].matches("@xkcd\.com"):
mail.move(".Social.xkcd")
return
# Sort email related to Troop 276
if (
False
or mail["List-Id"].contains("troopmailinglist.troop276.net")
or is_to_or_from(mail,"t276_announcements@att.net")
or mail["Subject"].matches("troop")
or mail["Subject"].matches("merit\s*badge")
or is_to_or_from(mail,"jsting@sbcglobal.net")
or is_to_or_from(mail,"trdindy@comcast.net")
or is_to_or_from(mail,"wjensen111@aol.com")
or is_to_or_from(mail,"dhoyt@yourhomecompany.com")
or is_to_or_from(mail,"salupo_vincent_p@lilly.com")
or is_to_or_from(mail,"basu@maharjan.org")
or is_to_or_from(mail,"muellerindy@yahoo.com")
or is_to_or_from(mail,"solorzano.luis@rocketmail.com")
or is_to_or_from(mail,"eldredmac@comcast.net")# MacDonell
or is_to_or_from(mail,"mitchprather@sbcglobal.net")
):
mail.move(".Troop276")
return
if mail["From"].matches("margieshu@sbcglobal\.net"):
mail.move(".misc.Mom")
return
# Sort mail from robotics people
for address in [
"jeffreysmith@msdlt.k12.in.us",
"jason.zielke@gmail.com",
"allison.m.babcock@gmail.com",
"william.walk@gmail.com",
"BBonahoom@stanleyworks.com",
"wcxctrack829@aim.com", # Pat
"djnels1@comcast.net", # Dave and Julie Nelson
"sarahlittell@comcast.net",
"skiplittell@comcast.net",
"dave.nelson@ecolab.com",
"@ni.com",
"@precisepath.com",
]:
if is_to_or_from(mail,address):
mail.move(".School.Robotics")
return
for subject_re in [
"robotics",
"1024",
"kil-?a-?bytes",
]:
if mail["Subject"].matches(subject_re):
mail.move(".School.Robotics")
return
# Sort mail from scoftware people
for address in [
"gnu.org",
"gitorious.org",
"sourceforge.com",
"ietf.org",
"kde.org",
"trustees@core3.amsl.com",
"esr@thyrsus.com",
"canonical.org",
"foocorp.net",
"parabolagnulinux.org",
]:
if is_to_or_from(mail,address):
mail.move(".software")
return
for subject_re in [
"\[Stow-[^\]]*\].*",
]:
if mail["Subject"].matches(subject_re):
mail.move(".software")
return
for address in [
"nintendo.com",
"nintendo-news.com",
]:
if mail["From"].contains(address):
mail.move(".Nintendo")
return
for address in [
"@lpi.org",
"@pearson.com",
"CompTIA",
]:
if mail["From"].contains(address):
mail.move(".CompTIA")
return
if mail["From"].contains("@lnnorthstar.org"):
mail.move(".School.Newspaper")
return
if mail["From"].contains("susyphil@aol.com"):
mail.move(".PMCH")
for address in [
"d.farrar@comcast.net",
"dfarrar@avacoustics.net",
"@vmware.com",
]:
if is_to_or_from(mail,address):
mail.move(".Work.FAST")
return
# Sort misc newsletters
if (
False
or mail["From"].contains("newsletter")
or mail["From"].contains("auto@comicsbyemail.com")
or mail["From"].contains("oreilly.com")
or mail["Subject"].contains("newsletter")
or mail["From"].contains("Info@mailing.jamendo.com")
):
mail.move(".misc.Newsletters")
return
if (
False
or mail["From"].contains("@msdlt.k12.in.us")
or is_to_or_from(mail,"ibwhite@comcast.net")
or mail["Subject"].contains("IOA")
or mail["From"].contains("nths.org")
or mail["Subject"].contains("NTHS")
or mail["Subject"].contains("National Technical Honor Society")
or mail["Subject"].contains("NHS")
or mail["Subject"].contains("National Honor Society")
):
mail.move(".School")
return
# from college stuff
if (
False
or mail["Subject"].contains("NYLF") # National Youth Leadership Conference
or mail["Subject"].contains("NSHSS")
):
mail.move(".College.Societies")
return
if (
False
or mail["From"].contains(".edu")
or mail["From"].contains("admissions@")
or mail["From"].contains("college")
or mail["From"].contains("university")
or mail["Subject"].contains("college")
# now we get to the BS
or mail["From"].contains("@dreamitdoitindiana.com")
or mail["From"].contains("@indianatechinfo.org")
):
mail.move(".College")
return
if mail["From"].contains("@projectwonderful.com"):
mail.move(".ProjectWonderful")
return
if (
False
or mail["From"].matches("@localhost")
or mail["From"].matches("@[^,>]*\.local")
or mail["From"].matches("@[^,>]*\.lukeshu\.ath\.cx")
or mail["To"].matches("luke@")
):
mail.move(".LocalSystems")
return
if (
False
or mail["Subject"].contains("password")
or mail["Subject"].contains("account")
):
mail.move(".misc.accounts")
return
handle_mapping = {
".": handle_incoming_unknown,
".Inbox": handle_incoming_unknown,
".spam-training": handle_incoming_spam_training,
".ham-training": handle_incoming_ham_training,
".Ham": handle_incoming_ham,
}
processor.maildirs = handle_mapping.keys()
for mail in processor:
handle_mapping[mail.maildir](mail)
|