From b8eca3a53615541d92c2aa7040846b080cbee708 Mon Sep 17 00:00:00 2001 From: Sean Whalen Date: Thu, 29 Mar 2018 12:32:47 -0400 Subject: [PATCH] Refresh IDLE command every 10 minutes --- parsedmarc/__init__.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/parsedmarc/__init__.py b/parsedmarc/__init__.py index eb16b9e..21998f5 100644 --- a/parsedmarc/__init__.py +++ b/parsedmarc/__init__.py @@ -27,6 +27,7 @@ from email.mime.text import MIMEText from email.utils import COMMASPACE, formatdate import smtplib import ssl +from threading import Timer import publicsuffix import xmltodict @@ -1337,14 +1338,19 @@ def watch_inbox(host, username, password, callback, reports_folder="INBOX", af = archive_folder ns = nameservers dt = dns_timeout - server = imapclient.IMAPClient(host) server.login(username, password) server.select_folder(rf) - # Start IDLE mode - server.idle() + def maintain_idle(): + """Sends the IDLE command every 10 minutes to avoid being + disconnected""" + server.idle() + timer = Timer(600, maintain_idle) + timer.start() + + maintain_idle() while True: try: