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
|
# -*- mode: python; indent-tabs-mode: t -*-
import os
import subprocess
processor.maildir_base = "~/Maildir.purdue"
processor.auto_reload_rcfile = True
processor.logfile = os.getenv('XDG_CACHE_HOME', "~/.cache")+"/maildirproc/purdue.log"
def is_to_or_from(mail,address):
"""
Return true if [mail] is to or from an address that contains [address].
"""
return (
mail["From"].contains(address)
or mail.target.contains(address))
def is_to_or_from_re(mail,address):
"""
Return true if [mail] is to or from an address that matches the
regex [address].
"""
return (
mail["From"].matches(address)
or mail.target.matches(address))
def piazza_topic(mail, topic):
return (
is_to_or_from(mail, topic+" on Piazza")
or mail["Subject"].contains(topic+" on Piazza"))
def my_filters(mail):
# Generic stuff ########################################################
if (
False
or mail["Subject"].contains("[PASE]")
or is_to_or_from(mail,"Purduealumni@purdue.edu")
or is_to_or_from(mail,"pase@purdue.edu")
):
mail.move("INBOX.crap.PASE")
return
if mail["Subject"].contains("[PLUG]"):
mail.move("INBOX.crap.PLUG")
return
if mail["From"].matches(".*bursar.*@purdue\.edu"):
mail.move("INBOX.tuition")
return
if mail["From"].contains("mailhub-admin@purdue.edu"):
mail.move("INBOX.crap.mailhub-admin")
return
if mail["From"].matches("pmx-.*@purdue.edu"):
mail.move("INBOX.crap.spam")
return
if is_to_or_from(mail,"linkedin.com"):
mail.move("INBOX.crap.LinkedIn")
return
if is_to_or_from(mail,"follet.com"):
mail.move("INBOX.Follet")
return
if (
False
or is_to_or_from(mail,"@edrtrust.com")
or is_to_or_from(mail,"@propertysolutions.com")
or is_to_or_from(mail,"collegestationapartments@gmail.com")
or is_to_or_from_re(mail,"collegestationca\..*@gmail.com")
):
mail.move("INBOX.housing.CollegeStation")
return
if (
False
or is_to_or_from(mail,"@hunterlp.com")
or is_to_or_from(mail, "@duke-energy.com")
or is_to_or_from(mail, "@alerts.comcast.net")
or is_to_or_from(mail, "rentpayment.com")
or is_to_or_from(mail, "@vectren.com")
):
mail.move("INBOX.housing.BeauJardin")
return
if mail["From"].matches("facebook(|mail)\.com"):
mail.move("INBOX.crap.Facebook")
return
if (
False
or is_to_or_from(mail,"@cable.comcast.com")
or is_to_or_from(mail,"@apexsystemsinc.com")
):
mail.move("INBOX.work.Comcast")
return
if (
False
or mail["Subject"].contains("[CS Opportunity Update]")
or mail["Subject"].contains("[CS Majors]")
):
mail.move("INBOX.crap.CS")
return
if (mail["From"].contains("shumakl@cs.purdue.edu") and mail["Subject"].matches("^cron:")):
mail.move("INBOX.crap.cron")
return
# Fall 2012 ############################################################
if mail["Subject"].contains("Fall-2012-SCI-21000-001:"):
mail.move("INBOX.classes.2012-2.SCI210")
if mail["Subject"].contains("fall-2012-cs-18000"):
mail.move("INBOX.classes.2012-2.CS180")
return
if piazza_topic(mail, "CS 18000"):
mail.move("INBOX.classes.2012-2.CS180.Piazza")
return
if mail["Subject"].contains("Fall-2012-SOC-10000"):
mail.move("INBOX.classes.2012-2.SOC100")
return
# Spring 2013 ##########################################################
if mail["Subject"].contains("[CS240] Submission result for"):
mail.move("INBOX.classes.2013-1.CS240.autograder")
return
if mail["Subject"].contains("[CS240]") or mail["Subject"].contains("Spring-2013-CS-24000"):
mail.move("INBOX.classes.2013-1.CS240")
return
if piazza_topic(mail, "CS 240"):
mail.move("INBOX.classes.2013-1.CS240.Piazza")
return
if mail["Subject"].matches(".*(PHYS|CHIP)\s*220.*") or is_to_or_from(mail,"srdas@purdue.edu"):
mail.move("INBOX.classes.2013-1.PHYS220")
return
if mail["Subject"].contains("Spring-2013-SOC-22000"):
mail.move("INBOX.classes.2013-1.SOC220")
return
# Fall 2013 ############################################################
if mail["Subject"].contains("Fall-2013-CS-25000"):
mail.move("INBOX.classes.2013-2.CS250")
return
if piazza_topic(mail, "CS 250") or piazza_topic(mail, "CS 250-FALL2013"):
mail.move("INBOX.classes.2013-2.CS250.Piazza")
return
if mail["Subject"].contains("Fall-2013-CS-25100"):
mail.move("INBOX.classes.2013-2.CS251")
return
if piazza_topic(mail, "CS 251"):
mail.move("INBOX.classes.2013-2.CS251.Piazza")
return
if mail["Subject"].contains("Fall-2013-SPAN-10100"):
mail.move("INBOX.classes.2013-2.SPAN101")
return
if mail["Subject"].contains("Fall-2013-MA-26100"):
mail.move("INBOX.classes.2013-2.MA261")
return
if mail["Subject"].contains("Fall-2013-MA-26500"):
mail.move("INBOX.classes.2013-2.MA265")
return
# Spring 2014 ##########################################################
# COM217
if mail["Subject"].contains("Spring-2014-COM-21700-004"):
mail.move("INBOX.classes.2014-1.COM217")
return
if mail["From"].contains("mixable") and mail["Subject"].matches("^COM 21700"):
mail.move("INBOX.classes.2014-1.COM217.Mixable")
return
# CS252
if piazza_topic(mail, "CS 25200"):
mail.move("INBOX.classes.2014-1.CS252.Piazza")
return
# CS307
if is_to_or_from(mail, "dunsmore@purdue.edu") or mail["Subject"].contains("Spring-2014-CS-30700-LE1"):
mail.move("INBOX.classes.2014-1.CS307")
return
# SPAN102
if mail["Subject"].contains("spring-2014-span-102"):
mail.move("INBOX.classes.2014-1.SPAN102")
return
# STAT350
if is_to_or_from(mail, "ssellke@purdue.edu"):
mail.move("INBOX.classes.2014-1.STAT350")
return
if piazza_topic(mail, "STAT 35000 (SELLKE)"):
mail.move("INBOX.classes.2014-1.STAT350.Piazza")
return
# Fall 2014 ############################################################
# CS334 (Graphics)
if (is_to_or_from(mail, "lin553@purdue.edu") or mail["Subject"].contains("Fall-2014-CS-33400")):
mail.move("INBOX.classes.2014-2.CS334")
return
# CS354 (OS)
# CS381 (Algo)
if piazza_topic(mail, "CS 354"):
mail.move("INBOX.classes.2014-2.CS354.Piazza")
return
if piazza_topic(mail, "CS 381"):
mail.move("INBOX.classes.2014-2.CS381.Piazza")
return
# CS456 (Programming languages)
if piazza_topic(mail, "CS 456"):
mail.move("INBOX.classes.2014-2.CS456.Piazza")
return
# MA416
if mail["Subject"].contains("Fall-2014-MA-41600"):
mail.move("INBOX.classes.2014-2.MA416")
return
# PHYS221
if (False
or is_to_or_from(mail, "cui@purdue.edu")
or is_to_or_from(mail, "shina@purdue.edu")
or is_to_or_from(mail, "ajith@purdue.edu")
):
mail.move("INBOX.classes.2014-2.PHYS221")
return
handle_mapping = {
"INBOX": my_filters,
}
processor.maildirs = handle_mapping.keys()
for mail in processor:
handle_mapping[mail.maildir](mail)
|