gh-66788: Add the utf-7-imap codec#153149
Merged
Merged
Conversation
Implement the modified UTF-7 encoding used for international IMAP4
mailbox names (RFC 3501, section 5.1.3). It differs from UTF-7:
"&" is the shift character ("&-" encodes a literal "&"), "," replaces
"/" in the Base64 alphabet, and all non-printable-ASCII characters are
Base64-encoded.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Documentation build overview
44 files changed ·
|
Member
IANA uses |
malemburg
approved these changes
Jul 7, 2026
malemburg
left a comment
Member
There was a problem hiding this comment.
I like Victor's suggestion of using "utf-7-imap" for this codec.
Member
Author
|
Great idea! It doesn't have particular name in RFC 2152, and on Wikipedia it is called mUTF-7, which looks too generic. |
Rename the modified-UTF-7 codec from imap4-utf-7 to utf-7-imap and register the aliases csUTF7IMAP and mUTF-7. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Convert the parametrized utf-7-imap codec tests to the subTests() decorator. Add round-trip cases for "+", "+-" (literal, unlike in UTF-7) and a "," in the Base64 run, and replace the duplicate decode-error cases with a "&" at the end of the input and an unterminated but otherwise valid Base64 sequence. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…7-imap Decode the modified Base64 with binascii.a2b_base64() and the modified alphabet directly, instead of base64.b64decode() with altchars. With strict_mode the "/" character (used by standard Base64 but not by the modified alphabet, which uses ",") is now rejected rather than accepted with a DeprecationWarning. Encoding likewise uses binascii.b2a_base64(). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add the
utf-7-imapcodec, implementing the modified UTF-7 encoding used for international IMAP4 mailbox names (RFC 3501, section 5.1.3).It differs from UTF-7 (RFC 2152):
&(not+) is the shift character, and&-encodes a literal&;,is used instead of/in the modified Base64 alphabet;&) are represented directly, so all other characters, including other controls, are Base64-encoded.The aliases
csUTF7IMAPandmUTF-7are also registered.This is the codec dependency of gh-49555 (international mailbox names in
imaplib). Automatic encoding/decoding of mailbox names inimaplibitself is a separate question, left for later — modern servers accept raw UTF-8 names viaUTF8=ACCEPT(RFC 6855), and auto-conversion has non-trivial API implications.🤖 Generated with Claude Code