From 9a1f49a5a1de49496d72c1f5e184b5441183d00d Mon Sep 17 00:00:00 2001 From: VG Date: Fri, 20 May 2016 17:54:04 +0200 Subject: add a number of steps/hooks --- climl/__init__.py | 16 ++++++++++++++++ climl/interface.py | 8 ++++++++ 2 files changed, 24 insertions(+) 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 -- cgit v1.2.3