Skip to content

gh-66788: Add the utf-7-imap codec#153149

Open
serhiy-storchaka wants to merge 2 commits into
python:mainfrom
serhiy-storchaka:imap4-utf7-codec
Open

gh-66788: Add the utf-7-imap codec#153149
serhiy-storchaka wants to merge 2 commits into
python:mainfrom
serhiy-storchaka:imap4-utf7-codec

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Jul 5, 2026

Copy link
Copy Markdown
Member

Add the utf-7-imap codec, 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;
  • only printable US-ASCII characters (except &) are represented directly, so all other characters, including other controls, are Base64-encoded.

The aliases csUTF7IMAP and mUTF-7 are also registered.

This is the codec dependency of gh-49555 (international mailbox names in imaplib). Automatic encoding/decoding of mailbox names in imaplib itself is a separate question, left for later — modern servers accept raw UTF-8 names via UTF8=ACCEPT (RFC 6855), and auto-conversion has non-trivial API implications.

🤖 Generated with Claude Code

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>
@read-the-docs-community

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

Copy link
Copy Markdown

@vstinner

vstinner commented Jul 7, 2026

Copy link
Copy Markdown
Member

Add the imap4-utf-7 codec, implementing the modified UTF-7 encoding used for international IMAP4 mailbox names (RFC 3501, section 5.1.3).

IANA uses UTF-7-IMAP name for this codec. What do you think of using utf-7-imap name?

@malemburg malemburg 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 like Victor's suggestion of using "utf-7-imap" for this codec.

@serhiy-storchaka

Copy link
Copy Markdown
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>
@serhiy-storchaka serhiy-storchaka changed the title gh-66788: Add the imap4-utf-7 codec gh-66788: Add the utf-7-imap codec Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants