diff options
-rw-r--r-- | climl/__init__.py | 16 | ||||
-rw-r--r-- | climl/interface.py | 8 |
2 files changed, 24 insertions, 0 deletions
diff --git a/climl/__init__.py b/climl/__init__.py index cb1f129..c16218f 100644 --- a/climl/__init__.py +++ b/climl/__init__.py @@ -4,10 +4,26 @@ from . import hooks def on_email(content): 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, + hook_validate_poster, + hook_process_subscribe_queries, + hook_generate_rcpt_list, + hook_send_all, + ) print('starting imap.main loop') try: imap.main(on_email) diff --git a/climl/interface.py b/climl/interface.py index 5a7f6ba..549eb8b 100644 --- a/climl/interface.py +++ b/climl/interface.py @@ -17,3 +17,11 @@ class HookAbortError(HookError): ''' pass + +class HookAbortError(HookError, StopIteration): + ''' + Run this if your hook declares it does not want other hooks to process + email. + ''' + + pass |