From 395b74adedf3afb59d6681ffb1af1e22dde4974c Mon Sep 17 00:00:00 2001 From: "v.kaukin" Date: Tue, 29 Sep 2020 15:13:19 +0500 Subject: [PATCH] Fixed MailBox._fetch_in_bulk bug --- docs/release_notes.rst | 1 + imap_tools/mailbox.py | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/release_notes.rst b/docs/release_notes.rst index c768cf1..c63d1a2 100644 --- a/docs/release_notes.rst +++ b/docs/release_notes.rst @@ -1,6 +1,7 @@ 0.24.0 ====== * Added MailBox.__init__ starttls argument for using STARTTLS +* Fixed MailBox._fetch_in_bulk bug for empty self.search result 0.23.0 ====== diff --git a/imap_tools/mailbox.py b/imap_tools/mailbox.py index 14dc8e3..0ec029e 100644 --- a/imap_tools/mailbox.py +++ b/imap_tools/mailbox.py @@ -58,7 +58,10 @@ def _fetch_by_one(self, message_nums: [str], message_parts: str) -> iter: yield fetch_result[1] def _fetch_in_bulk(self, message_nums: [str], message_parts: str) -> iter: - fetch_result = self.box.fetch(','.join(message_nums), message_parts) + message_nums_str = ','.join(message_nums) + if not message_nums_str: + raise StopIteration() + fetch_result = self.box.fetch(message_nums_str, message_parts) check_command_status(fetch_result, MailboxFetchError) for built_fetch_item in grouper(fetch_result[1], 2): yield built_fetch_item