-
Notifications
You must be signed in to change notification settings - Fork 1
/
processors.py
68 lines (53 loc) · 1.7 KB
/
processors.py
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
import email
import email.utils
class NotAuthorized(Exception):
pass
class NoSuchList(Exception):
pass
class DummyProcessor(object):
def process(self, mail):
return mail
class SingleListProcessor(object):
def __init__(self, list_email, subject_prefix, subscribers):
self.list_email = list_email
self.subject_prefix = subject_prefix
self.subscribers = subscribers
def process(self, mail):
try:
sender = mail['From']
except:
raise NotAuthorized, "empty From, rejecting"
if email.utils.parseaddr(sender)[1] not in self.subscribers:
raise NotAuthorized, sender
try: del(mail['Reply-to'])
except: pass
mail['Reply-to'] = self.list_email
try: del(mail['Sender'])
except: pass
mail['Sender'] = self.list_email
try:
subject = mail['Subject']
del(mail['Subject'])
except:
subject = "(No subject)"
if -1 == subject.find(self.subject_prefix):
subject = self.subject_prefix + subject
mail['Subject'] = subject
mail.ml_sender = sender
mail.ml_list = self.list_email
mail.ml_send_to = self.subscribers
return mail
class MoreListsProcessor(object):
def __init__(self, *args):
self.lists = {}
for list in args:
mail = email.utils.parseaddr(list.list_email)[1]
self.lists[mail] = list
def process(self, msg):
try:
to = email.utils.parseaddr(msg['To'])[1]
list = self.lists[to]
except:
raise NoSuchList
else:
return list.process(msg)