From f91b4ee5448be83cff69d327e5516c7e8591d715 Mon Sep 17 00:00:00 2001 From: Akshet Pandey Date: Wed, 28 Feb 2024 14:10:01 -0800 Subject: [PATCH] supress errors during close --- django_mailbox/transports/imap.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/django_mailbox/transports/imap.py b/django_mailbox/transports/imap.py index 8ae7fa6e..5b0d2dc8 100644 --- a/django_mailbox/transports/imap.py +++ b/django_mailbox/transports/imap.py @@ -50,8 +50,12 @@ def connect(self, username, password): self.server.select() def close(self): - self.server.close() - self.server.logout() + try: + self.server.close() + self.server.logout() + except (imaplib.IMAP4.error, OSError) as e: + logger.warning(f'Failed to close IMAP connection, ignoring: {e}') + pass def _get_all_message_ids(self): # Fetch all the message uids