blob: e8652546215f0f75c2da2fb697234902bdec17fa (
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
|
from . import imap
from . import interface
from . import hooks
def on_email(content, hooks):
print('on_email:', content)
context = {}
try:
for hook in hooks:
context, content = hook(context, content)
except interface.HookStopIteration():
pass
print('now, raising exception')
raise interface.HookAbortError()
def main():
# TODO: how to load hooks with a dependency tree and sort them accordingly
# to generate hooks list ?
# now try a fixed list ?
hooks = (
hook_check_ml_restrictions, # open/private ml
hook_validate_poster,
hook_process_subscribe_queries,
hook_generate_rcpt_list,
hook_send_all,
)
print('starting imap.main loop')
try:
imap.main(lambda content: on_mail(content, hooks))
except KeyboardInterrupt:
pass
print('end of main imap loop')
|