From 5ab09429a170a52f13ddb07a17251a13db216949 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Thu, 29 Sep 2016 18:48:48 -0400 Subject: [PATCH] Add config option to set the imap idle timeout This commit adds a new config option to the imap section, idle-timeout, which is used to set the timeout duration for the idle call. By default imaplib2 sets this to 29mins. This if far too long especially on an imap server that doesn't have imap idle configured properly. What ends up happening is that all the lp events get bunched together and pushed to mqtt at once every 29mins. This isn't really useful as an event stream. So this makes it configurable and decreases the default setting to 1 min which seems like a much more useful default value, albeit at the cost of more imap traffic to fetch messages. Change-Id: I98fc9778f0adc548d28e7bbd8600f05ff4946ba2 --- README.rst | 1 + lpmqtt/daemon.py | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index a6e2eff..6530a42 100644 --- a/README.rst +++ b/README.rst @@ -51,6 +51,7 @@ configuration of the imap server you're connecting to: * **delete-old** - Set this to *True* to have lpmqtt delete messages after it finishes processing them. By default it will just mark them as read. + * **idle-timeout** - The number of seconds to use for the idle timeout MQTT ---- diff --git a/lpmqtt/daemon.py b/lpmqtt/daemon.py index f009da0..304c956 100644 --- a/lpmqtt/daemon.py +++ b/lpmqtt/daemon.py @@ -111,6 +111,10 @@ def main(): imap_delete = config.getboolean('imap', 'delete-old') else: imap_delete = False + if config.has_option('imap', 'imap-timeout'): + imap_idle_timeout = config.getint('imap', 'idle-timeout') + else: + imap_idle_timeout = 60 launchpad = lp.LPImapWatcher(imap_server, imap_user, imap_password, folder=imap_folder, ssl=imap_ssl, @@ -120,7 +124,7 @@ def main(): for event in events: msg, topic = process_event(event, base_topic) mqttqueue.publish_single(topic, msg) - launchpad.imap.idle() + launchpad.imap.idle(timeout=imap_idle_timeout) if __name__ == "__main__": main()