summaryrefslogtreecommitdiff
path: root/.maildirproc/purdue.rc
blob: 9a759f50fa66fc6f57a3d0b878d02a8fbe2cc6c7 (plain)
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
# -*- mode: python; -*-

import subprocess

processor.maildir_base = "~/Maildir.purdue"
processor.auto_reload_rcfile = True

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 mail["Subject"].contains("[PASE]"):
		mail.move("INBOX.PASE")
		return

	if mail["Subject"].contains("[PLUG]"):
		mail.move("INBOX.PLUG")
		return

	if is_to_or_from(mail,"linkedin.com"):
		mail.move("INBOX.LinkedIn")
		return

	if (
		False
		or mail["Subject"].contains("[CS Opportunity Update]")
		or mail["Subject"].contains("[CS Majors]")
		):
		mail.move("INBOX.CS")
		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]") 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"].contains("Spring-2013-CS-18200"):
		mail.move("INBOX.classes.2013-1.CS182")
		return

handle_mapping = {
	"INBOX":           my_filters,
	}
processor.maildirs = handle_mapping.keys()
for mail in processor:
	handle_mapping[mail.maildir](mail)