From 882bf2c85e027cecd2d5ff6cf1c27f33b0b80e72 Mon Sep 17 00:00:00 2001 From: Forest Date: Sun, 22 Sep 2024 13:33:14 -0700 Subject: [PATCH] imaplib: elaborate in idle context manager comment --- Lib/imaplib.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Lib/imaplib.py b/Lib/imaplib.py index 25c3e017fe4b..718c53483e3b 100644 --- a/Lib/imaplib.py +++ b/Lib/imaplib.py @@ -1416,8 +1416,13 @@ class _Idler: imap._idle_capture = True self._tag = imap._command('IDLE') - # Process responses until the server requests continuation - while resp := imap._get_response(): # Returns None on continuation + # As with any command, the server is allowed to send us unrelated, + # untagged responses before acting on IDLE. These lines will be + # returned by _get_response(). When the server is ready, it will + # send an IDLE continuation request, indicated by _get_response() + # returning None. We therefore process responses in a loop until + # this occurs. + while resp := imap._get_response(): if imap.tagged_commands[self._tag]: raise imap.abort(f'unexpected status response: {resp}') -- 2.47.3