From 1dc11eb465ff70ea51452326935208a40c2b49bf Mon Sep 17 00:00:00 2001 From: VG Date: Thu, 19 May 2016 17:28:42 +0200 Subject: Add interface: hook can do non-critical exception --- climl/imap.py | 8 +++++++- climl/interface.py | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 climl/interface.py diff --git a/climl/imap.py b/climl/imap.py index 68a6e9b..034c77a 100644 --- a/climl/imap.py +++ b/climl/imap.py @@ -7,6 +7,8 @@ import backports.ssl as ssl import socket import time +from . import interface + def conf_boolean_postprocess(src): src = src.lower().strip() if src == 'true' or src == 'on' or src == '1': @@ -143,7 +145,11 @@ def main(callback=None): response = connection.fetch([oneid], ['RFC822']) data = response[oneid][b'RFC822'] print('calling callback...') - callback('mail: ' + str(oneid) + ': ' + str(data)) + try: + callback('mail: ' + str(oneid) + ': ' + str(data)) + connection.add_flags([oneid], ['\Seen']) + except interface.HookAbortError: + pass data = None while True: imap_waiter(connection) diff --git a/climl/interface.py b/climl/interface.py new file mode 100644 index 0000000..5a7f6ba --- /dev/null +++ b/climl/interface.py @@ -0,0 +1,19 @@ +''' +This file defines symbols used to make communication between +hooks/plugins/extensions and core of climl. +''' + +class HookError(Exception): + ''' + Base class for hooks exception, they should not use this directly + ''' + + pass + +class HookAbortError(HookError): + ''' + This exception is used to indicate to core of climl it should not mark + email \Seen for now. + ''' + + pass -- cgit v1.2.3