From e46a768b82aa7c8b840a93c45cc0e909ee40d747 Mon Sep 17 00:00:00 2001 From: Nathan Thorpe Date: Thu, 28 Apr 2022 19:46:24 -0700 Subject: [PATCH] fix callback object on IMAPConnection --- parsedmarc/mail/imap.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/parsedmarc/mail/imap.py b/parsedmarc/mail/imap.py index 83a7598..d91707a 100644 --- a/parsedmarc/mail/imap.py +++ b/parsedmarc/mail/imap.py @@ -53,6 +53,13 @@ class IMAPConnection(MailboxConnection): Use an IDLE IMAP connection to parse incoming emails, and pass the results to a callback function """ + + # IDLE callback sends IMAPClient object, + # send back the imap connection object instead + def idle_callback_wrapper(client: IMAPClient): + self._client = client + check_callback(self) + while True: try: IMAPClient(host=self._client.host, @@ -61,7 +68,7 @@ class IMAPConnection(MailboxConnection): port=self._client.port, ssl=self._client.ssl, verify=self._verify, - idle_callback=check_callback, + idle_callback=idle_callback_wrapper, idle_timeout=check_timeout) except (timeout, IMAPClientError): logger.warning("IMAP connection timeout. Reconnecting...")