diff options
Diffstat (limited to 'climl/__init__.py')
-rw-r--r-- | climl/__init__.py | 53 |
1 files changed, 42 insertions, 11 deletions
diff --git a/climl/__init__.py b/climl/__init__.py index e865254..bfbe4fc 100644 --- a/climl/__init__.py +++ b/climl/__init__.py @@ -1,34 +1,65 @@ from . import imap from . import interface from . import hooks +import confparser +import os -def on_email(content, hooks): - print('on_email:', content) - context = {} +def on_email(content, hooks, conf): + #print('on_email:', content) + + class Context(dict): + def __init__(self): + self.conf = conf + + context = Context() try: for hook in hooks: + print('on_email, calling hook {}'.format(hook.__name__)) context, content = hook(context, content) - except interface.HookStopIteration(): + except interface.HookStopIteration: pass print('now, raising exception') raise interface.HookAbortError() +def conf_boolean_postprocess(src): + src = src.lower().strip() + if src == 'true' or src == 'on' or src == '1': + return True + return False + + +def conf_postprocess(conf): + d = { + 'imap.tls': conf_boolean_postprocess, + 'imap.start_tls': conf_boolean_postprocess, + 'imap.tls_nocheck_hostname': conf_boolean_postprocess, + 'imap.tls_nocheck_ca': conf_boolean_postprocess, + } + return {key: d[key](value) if key in d else value + for key, value in conf.items()} + + def main(): + confpath = os.path.expanduser('~/.config/climl/climl.cfg') + conf = conf_postprocess(confparser.read_conf(confpath)) + # 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, + hooksfuncs = ( + hooks.hook_extract_listname, + hooks.hook_check_ml_restrictions, # open/private ml + hooks.hook_validate_poster, + hooks.hook_process_subscribe_queries, + hooks.hook_generate_rcpt_list, + hooks.hook_send_all, ) print('starting imap.main loop') try: - imap.main(lambda content: on_mail(content, hooks)) + imap.main(lambda content: on_email(content, hooksfuncs, conf), + conf=conf) except KeyboardInterrupt: pass print('end of main imap loop') |