Skip to content

Commit 9ac8485

Browse files
gh-153494: Add What's New entry and clarify the charset docs
Document that str search criteria are encoded to the declared charset only when a charset is given; under UTF8=ACCEPT the charset is None and criteria are sent using the connection encoding. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 3e07edc commit 9ac8485

3 files changed

Lines changed: 28 additions & 14 deletions

File tree

Doc/library/imaplib.rst

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -610,10 +610,12 @@ An :class:`IMAP4` instance has the following methods:
610610
If *uid* is true, the message numbers in the response are UIDs
611611
(``UID SEARCH``).
612612

613-
A criterion passed as :class:`str` is encoded to *charset* (which must name
614-
a codec known to Python); pass :class:`bytes` to send a criterion that is
615-
already encoded, for example when *charset* is one that Python does not
616-
support.
613+
A criterion passed as :class:`str` is encoded to *charset*
614+
(which must name a codec known to Python);
615+
pass :class:`bytes` to send a criterion that is already encoded,
616+
for example when *charset* is one that Python does not support.
617+
When *charset* is ``None`` (as it must be under ``UTF8=ACCEPT``),
618+
the criterion is sent using the connection's encoding instead.
617619

618620
Example::
619621

@@ -690,8 +692,9 @@ An :class:`IMAP4` instance has the following methods:
690692

691693
If *uid* is true, the message numbers in the response are UIDs (``UID SORT``).
692694

693-
As with :meth:`search`, a *search_criterion* passed as :class:`str` is
694-
encoded to *charset*; pass :class:`bytes` to send one already encoded.
695+
As with :meth:`search`,
696+
a *search_criterion* passed as :class:`str` is encoded to *charset*;
697+
pass :class:`bytes` to send one already encoded.
695698

696699
This is an ``IMAP4rev1`` extension command.
697700

@@ -786,8 +789,9 @@ An :class:`IMAP4` instance has the following methods:
786789
If *uid* is true, the message numbers in the response are UIDs
787790
(``UID THREAD``).
788791

789-
As with :meth:`search`, a *search_criterion* passed as :class:`str` is
790-
encoded to *charset*; pass :class:`bytes` to send one already encoded.
792+
As with :meth:`search`,
793+
a *search_criterion* passed as :class:`str` is encoded to *charset*;
794+
pass :class:`bytes` to send one already encoded.
791795

792796
This is an ``IMAP4rev1`` extension command.
793797

Doc/whatsnew/3.16.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,14 @@ imaplib
276276
:meth:`~imaplib.IMAP4.uid`.
277277
(Contributed by Serhiy Storchaka in :gh:`153502`.)
278278

279+
* :meth:`~imaplib.IMAP4.search`, :meth:`~imaplib.IMAP4.sort`
280+
and :meth:`~imaplib.IMAP4.thread` (and the corresponding ``uid`` commands)
281+
now encode :class:`str` search criteria to the declared *charset*,
282+
so international search text can be passed as an ordinary :class:`str`.
283+
When *charset* is ``None`` (as it must be under ``UTF8=ACCEPT``),
284+
the criteria are sent using the connection encoding instead.
285+
(Contributed by Serhiy Storchaka in :gh:`153494`.)
286+
279287

280288
ipaddress
281289
---------
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
:meth:`imaplib.IMAP4.search`, :meth:`~imaplib.IMAP4.sort` and
2-
:meth:`~imaplib.IMAP4.thread` (and the corresponding ``uid`` commands) now
3-
encode :class:`str` search criteria to the declared *charset*, so
4-
international search text can be passed as ordinary :class:`str`. A criterion
5-
passed as :class:`bytes` is sent unchanged, for use with a charset that Python
6-
has no codec for.
1+
:meth:`imaplib.IMAP4.search`, :meth:`~imaplib.IMAP4.sort`
2+
and :meth:`~imaplib.IMAP4.thread` (and the corresponding ``uid`` commands)
3+
now encode :class:`str` search criteria to the declared *charset*,
4+
so international search text can be passed as ordinary :class:`str`.
5+
When *charset* is ``None`` (as it must be under ``UTF8=ACCEPT``),
6+
the criteria are sent using the connection encoding instead.
7+
A criterion passed as :class:`bytes` is sent unchanged,
8+
for use with a charset that Python has no codec for.

0 commit comments

Comments
 (0)