https://github.com/python/cpython/commit/9317d52169d2d845a74a082e2df86ce3978832f3 commit: 9317d52169d2d845a74a082e2df86ce3978832f3 branch: 3.15 author: Miss Islington (bot) <[email protected]> committer: serhiy-storchaka <[email protected]> date: 2026-07-02T13:25:34Z summary:
[3.15] gh-88574: Skip a spurious blank line after a literal in imaplib (GH-152751) (GH-152884) Some IMAP servers send an extra blank line after the data of a literal. imaplib mistook it for the response trailer and failed on the next command. Such a blank line is now skipped. (cherry picked from commit 53ff1a28ccfa69925c3c452cfc003970640fa65b) Co-authored-by: Serhiy Storchaka <[email protected]> Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]> files: A Misc/NEWS.d/next/Library/2026-07-01-10-00-00.gh-issue-88574.Kz3wQm.rst M Lib/imaplib.py M Lib/test/test_imaplib.py diff --git a/Lib/imaplib.py b/Lib/imaplib.py index ca2ae40726b2d1..e444abb4f1f77c 100644 --- a/Lib/imaplib.py +++ b/Lib/imaplib.py @@ -1295,6 +1295,10 @@ def _get_response(self, start_timeout=False): dat = self._get_line() + # Skip a blank line that some servers send after a literal. + if dat == b'': + dat = self._get_line() + self._append_untagged(typ, dat) # Bracketed response information? diff --git a/Lib/test/test_imaplib.py b/Lib/test/test_imaplib.py index cb62aef1ff52d4..f734ebfaa1a009 100644 --- a/Lib/test/test_imaplib.py +++ b/Lib/test/test_imaplib.py @@ -849,6 +849,23 @@ def test_lsub(self): self.assertEqual(typ, 'OK') self.assertEqual(server.args, ['~/Mail/', '%']) + def test_extra_blank_line_after_literal(self): + # Some buggy servers send an extra blank line after the counted + # literal data. imaplib should skip it instead of failing. + class BlankLineHandler(SimpleIMAPHandler): + def cmd_FETCH(self, tag, args): + self._send(b'* 1 FETCH (BODY[HEADER] {13}\r\n') + self._send(b'Subject: test') # 13-byte literal + self._send(b'\r\n)\r\n') # stray blank line, then ')' + self._send_tagged(tag, 'OK', 'FETCH completed') + client, _ = self._setup(BlankLineHandler) + client.login('user', 'pass') + client.select() + typ, data = client.fetch('1', '(BODY[HEADER])') + self.assertEqual(typ, 'OK') + self.assertEqual(data, [(b'1 (BODY[HEADER] {13}', b'Subject: test'), + b')']) + def test_unselect(self): client, server = self._setup(SimpleIMAPHandler) client.login('user', 'pass') diff --git a/Misc/NEWS.d/next/Library/2026-07-01-10-00-00.gh-issue-88574.Kz3wQm.rst b/Misc/NEWS.d/next/Library/2026-07-01-10-00-00.gh-issue-88574.Kz3wQm.rst new file mode 100644 index 00000000000000..8d95bbbb5a15e4 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-07-01-10-00-00.gh-issue-88574.Kz3wQm.rst @@ -0,0 +1,2 @@ +:mod:`imaplib` no longer fails when a server sends a spurious blank line +after the counted data of a literal. Such a blank line is now skipped. _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3//lists/python-checkins.python.org Member address: [email protected]
