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
This commit is contained in:
Matthew Treinish 2016-09-29 18:48:48 -04:00
parent f391139791
commit 5ab09429a1
2 changed files with 6 additions and 1 deletions

View File

@ -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
----

View File

@ -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()