Skip to content

gh-40038: Quote imaplib command arguments when necessary#152703

Open
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:imaplib-quote-args
Open

gh-40038: Quote imaplib command arguments when necessary#152703
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:imaplib-quote-args

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Jun 30, 2026

Copy link
Copy Markdown
Member

Argument quoting in imaplib was inadvertently disabled when the module
was ported to Python 3 (bpo-1210, bpo-9638), so since Python 3.0 commands
silently fail for arguments containing protocol-sensitive characters,
such as a mailbox name with a space.

Quoting is restored and reimplemented per the :rfc:3501 grammar:
arguments that need quoting are escaped and quoted, while flags, sequence
sets and list wildcards are left intact. For backward compatibility, an
argument already enclosed in double quotes is left unchanged, so code that
quotes arguments itself keeps working.

This supersedes #6395 and also resolves #92835, #58148, #90378 and
#148770.

I had almost finished this work about 1.5 years ago, but stopped,
exhausted, after writing roughly 30% of the tests — there are a lot of
them, they are wordy, and they require strict focus. I was finally able
to complete them now with the help of AI.

Argument quoting was inadvertently disabled when imaplib was ported to
Python 3 (bpo-1210 commented out the ``_checkquote()`` call, bpo-9638
then removed it), so since Python 3.0 commands failed for arguments
containing protocol-sensitive characters, such as a space in a mailbox
name.

Quoting is restored and reimplemented per the RFC 3501 grammar, so that
arguments that need quoting are escaped and quoted, while flags, sequence
sets and list wildcards are left intact.

For backward compatibility, an argument already enclosed in double quotes
is left unchanged, so code that quotes arguments itself keeps working.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@serhiy-storchaka serhiy-storchaka requested a review from a team as a code owner June 30, 2026 17:23
@serhiy-storchaka serhiy-storchaka added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Jun 30, 2026
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #33378518 | 📁 Comparing 455004a against main (c393ab6)

  🔍 Preview build  

2 files changed
± library/imaplib.html
± whatsnew/changelog.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

imaplib support for quoting arguments accidentally removed

1 participant