Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gh-153521: Support structured arguments in imaplib commands - #153522

Merged
serhiy-storchaka merged 6 commits into
python:mainfrom
serhiy-storchaka:imaplib-structured-args
Jul 17, 2026
Merged

gh-153521: Support structured arguments in imaplib commands#153522
serhiy-storchaka merged 6 commits into
python:mainfrom
serhiy-storchaka:imaplib-structured-args

Conversation

@serhiy-storchaka

Copy link
Copy Markdown
Member

imaplib command methods now accept structured arguments, so the module takes care of quoting and the caller no longer has to preformat and quote strings by hand. This matters not only because hand-quoting is error-prone, but because a pre-quoted string cannot represent every value: one containing a newline or NUL, binary data, or a value too large for a single line must be sent as a literal or literal8, which the caller cannot express in a plain string. Owning the value keeps that door open for future literal support.

Two things change:

  • A message_set and lists of flags or other atoms can be passed as sequences instead of preformatted parenthesized strings. A message set may be an integer, or a sequence of integers, (start, stop) ranges (with None or '*' meaning the last message) and range objects.

  • The search, fetch, sort, thread and uid methods gain a keyword-only params argument that substitutes and quotes ? placeholders in their value-bearing arguments, in the manner of sqlite3 parameter substitution. ?f substitutes a flag or list of flags, ?s a structured message set, and ?? a literal ?. Substitution runs only when params is given, so existing calls that contain a literal ? are unaffected.

Both preformatted strings and the pre-existing behaviour continue to work, so the change is backward compatible.

Command methods now accept a structured *message_set* (an integer, or a
sequence of integers, (start, stop) ranges and range objects) and lists of
flags or other atoms in place of preformatted parenthesized strings.

The search, fetch, sort, thread and uid methods gain a keyword-only *params*
argument that substitutes and quotes '?' placeholders in their value-bearing
arguments, in the manner of sqlite3 parameter substitution.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@read-the-docs-community

read-the-docs-community Bot commented Jul 10, 2026

Copy link
Copy Markdown

@bitdancer bitdancer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've only reviewed the docs (so far? ;)

Comment thread Doc/library/imaplib.rst Outdated
Comment thread Doc/library/imaplib.rst Outdated
Comment thread Doc/library/imaplib.rst Outdated
Comment thread Doc/library/imaplib.rst Outdated
Comment thread Doc/library/imaplib.rst Outdated
Comment thread Doc/library/imaplib.rst
Comment thread Doc/library/imaplib.rst Outdated
Comment thread Doc/library/imaplib.rst Outdated
Comment thread Doc/library/imaplib.rst Outdated
@bedevere-app

bedevere-app Bot commented Jul 11, 2026

Copy link
Copy Markdown

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

serhiy-storchaka and others added 3 commits July 11, 2026 18:41
GitHub could only attach each suggestion to a line within the PR diff,
so David's multi-line suggestions landed next to the nearest changed
line and left the original prose duplicated.  Merge each into clean
text, wrap to the line limit with semantic line breaks, and move the
substitution note into the versionadded directive.

Co-authored-by: R. David Murray <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Keep every changed line within the 79-character limit and break at
clause boundaries, without splitting into overly short fragments.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@serhiy-storchaka

Copy link
Copy Markdown
Member Author

Thank you David. I have made the requested changes; please review again.

@bedevere-app

bedevere-app Bot commented Jul 11, 2026

Copy link
Copy Markdown

Thanks for making the requested changes!

@bitdancer: please review the changes made to this pull request.

@bedevere-app
bedevere-app Bot requested a review from bitdancer July 11, 2026 16:06
Comment thread Lib/test/test_imaplib.py Outdated
Comment thread Lib/test/test_imaplib.py
Comment thread Lib/test/test_imaplib.py
Comment thread Lib/imaplib.py
Comment thread Lib/imaplib.py
Comment thread Lib/imaplib.py
@bedevere-app

bedevere-app Bot commented Jul 11, 2026

Copy link
Copy Markdown

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

@serhiy-storchaka

Copy link
Copy Markdown
Member Author

Initially I considered different design for structural search criteria: ['FROM', '[email protected]'], ['SUBJECT', 'trip report'] or {'FROM': '[email protected]', 'SUBJECT': 'trip report'}. But it would be more complicated with OR, NOT and parens. We can still add an alternative interface in addition or in replacement of the current idea.

serhiy-storchaka and others added 2 commits July 11, 2026 19:50
Let _format_astring() fall through to the generic TypeError for a bool
value instead of a special-case message (suggested by David Murray),
and move the substitution note back into the body rather than the
versionadded directive.

Co-authored-by: R. David Murray <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]>

@bitdancer bitdancer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@serhiy-storchaka

Copy link
Copy Markdown
Member Author

Thank you for your review @bitdancer. Soon I'll present the next stage -- structural results.

@serhiy-storchaka
serhiy-storchaka merged commit 456f3a7 into python:main Jul 17, 2026
54 of 55 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants