Skip to content

Commit 580b5ff

Browse files
committed
gh-122953: applied reviewed fixes - retaining removed documentation, space added accidently in test, inlining one use helper functions, adding whats new and fixing ci failure
1 parent e9adcbc commit 580b5ff

5 files changed

Lines changed: 20 additions & 32 deletions

File tree

Doc/library/imaplib.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515

1616
This module defines three classes, :class:`IMAP4`, :class:`IMAP4_SSL` and
1717
:class:`IMAP4_stream`, which encapsulate a connection to an IMAP4 server and
18-
implement IMAP4rev1 and IMAP4rev2 client protocol features. It is backward
19-
compatible with IMAP4 (:rfc:`1730`) servers, but note that the ``STATUS``
20-
command is not supported in IMAP4.
18+
implement a large subset of the IMAP4rev1 client protocol as defined in
19+
:rfc:`2060` and adds support for IMAP4rev2 client protocol as defined in
20+
:rfc:`9051`. It is backward compatible with IMAP4 (:rfc:`1730`) servers, but
21+
note that the ``STATUS`` command is not supported in IMAP4.
2122

2223
.. include:: ../includes/wasm-notavail.rst
2324

Doc/whatsnew/3.16.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ gzip
9494
which is passed on to the constructor of the :class:`~gzip.GzipFile` class.
9595
(Contributed by Marin Misur in :gh:`91372`.)
9696

97+
imaplib
98+
-------
99+
100+
* Add support for IMAP4rev2.
101+
97102
os
98103
--
99104

Lib/imaplib.py

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -270,54 +270,36 @@ def _connect(self):
270270

271271
def _set_protocol_version(self):
272272

273-
if self._should_use_rev1_mode_for_dual_support():
274-
self._activate_rev1_mode()
273+
if 'IMAP4REV2' in self.capabilities and 'IMAP4REV1' in self.capabilities:
274+
self.PROTOCOL_VERSION = 'IMAP4REV1'
275+
self._mode_ascii()
275276
return
276277

277278
for version in AllowedVersions:
278279
if not version in self.capabilities:
279280
continue
280281
if version == 'IMAP4REV2':
281-
self._activate_rev2_mode()
282+
self.PROTOCOL_VERSION = 'IMAP4REV2'
283+
self._mode_utf8()
282284
else:
283285
self.PROTOCOL_VERSION = version
284286
return
285287

286288
raise self.error('server not IMAP4 compliant')
287289

288-
def _supports_rev2(self):
289-
return 'IMAP4REV2' in self.capabilities
290-
291-
def _supports_dual_rev1_rev2(self):
292-
return self._supports_rev2() and 'IMAP4REV1' in self.capabilities
293-
294-
def _is_using_rev2(self):
295-
return self.PROTOCOL_VERSION == 'IMAP4REV2'
296-
297290
def _is_capability_available(self, capability):
298291
capability = capability.upper()
299-
if self._is_using_rev2() and capability in IMAP4REV2_BUILTIN_COMMANDS:
292+
if self.PROTOCOL_VERSION == 'IMAP4REV2' and capability in IMAP4REV2_BUILTIN_COMMANDS:
300293
return True
301294
return capability in self.capabilities
302295

303-
def _should_use_rev1_mode_for_dual_support(self):
304-
return self._supports_dual_rev1_rev2()
305-
306-
def _activate_rev1_mode(self):
307-
self.PROTOCOL_VERSION = 'IMAP4REV1'
308-
self._mode_ascii()
309-
310-
def _activate_rev2_mode(self):
311-
self.PROTOCOL_VERSION = 'IMAP4REV2'
312-
self._mode_utf8()
313-
314296
def _handle_enable_success(self, capability):
315297
capability = capability.upper()
316298
if 'UTF8=ACCEPT' in capability:
317299
self._mode_utf8()
318300
if 'IMAP4REV2' in capability:
319-
self._activate_rev2_mode()
320-
301+
self.PROTOCOL_VERSION = 'IMAP4REV2'
302+
self._mode_utf8()
321303

322304
def __getattr__(self, attr):
323305
# Allow UPPERCASE variants of IMAP4 command methods.
@@ -888,7 +870,7 @@ def search(self, charset, *criteria):
888870
"""
889871
name = 'SEARCH'
890872
if charset:
891-
if self.utf8_enabled and not self._is_using_rev2():
873+
if self.utf8_enabled and not self.PROTOCOL_VERSION == 'IMAP4REV2':
892874
raise IMAP4.error("Non-None charset not valid in UTF8 mode")
893875
typ, dat = self._simple_command(name, 'CHARSET', charset, *criteria)
894876
else:

Lib/test/test_imaplib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def _send_textline(self, message):
138138
def _send_tagged(self, tag, code, message):
139139
self._send_textline(' '.join((tag, code, message)))
140140

141-
def handle(self):
141+
def handle(self):
142142
# Send a welcome message.
143143
self._send_textline(f'* OK {self.welcome}')
144144
while 1:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
Update the :mod:`imaplib` module to support IMAP4rev2 following :rfc:`9501`, with backward compatibility with IMAP4rev1
2-
(outlined in :rfc:`9051#appendix-A`) and IMAP4rev1 extensions folded into IMAP4rev2 (outlined in :rfc:`9051#appendix-E`).
2+
(outlined in :rfc:`9051#appendix-A`) and IMAP4rev1 extensions folded into IMAP4rev2 (outlined in :rfc:`9051#appendix-E`).

0 commit comments

Comments
 (0)