Skip to content

GH-78319: Stop sending the UTF8 marker when appending messages - #107290

Open
arnt wants to merge 1 commit into
python:mainfrom
arnt:imap4rev2-utf8accept-append
Open

GH-78319: Stop sending the UTF8 marker when appending messages#107290
arnt wants to merge 1 commit into
python:mainfrom
arnt:imap4rev2-utf8accept-append

Conversation

@arnt

@arnt arnt commented Jul 26, 2023

Copy link
Copy Markdown

The UTF8 marker is defined in RFC 6855 and tells the server that the message being appended contains UTF8 addresses, an unencoded UTF8 subject, etc. However, if a client appends a message containing UTF8 addresses but without that marker, the bytes can only be parsed as UTF8 because that's the only RFC-compliant way to parse those bytes.

RFC 6855 says clients MUST send the UTF8 marker.

Due to an accidental discrepancy, RFC 9051 (IMAP4rev2) does not contain that marker. IMAP4rev2 was intended to be upwardly compatible with RFC 6855, but this problem broke that. This has no ill effects, since the marker does not change the message's meaning.

While investigating the problem, I noticed that Python uses the marker incorrectly: Python uses it to mark ALL messages if UTF8=ACCEPT support has been enabled, not just ones that contain UTF8 addresses.

The best way forward appear to be using the syntax defined in RFC 9051 and publishing a revision to RFC 6855, so this change modifies imaplib to match RFC 9051.

FWIW JMAP is like IMAP4rev2 in this case; UTF8 is just there, without any marker. Also, neither UTF8=ACCEPT, IMAP4rev2 or JMAP provide any way to learn whether a message was stored with or without the marker.

This quasi-accidentally solves #78319 by removing the case that broke.

…to a mailbox.

The UTF8 marker is defined in RFC 6855 and tells the server that the
message being appended contains UTF8 addresses, an unencoded UTF8 subject,
etc.  However, if a client appends a message containing UTF8 addresses but
without that marker, the bytes can only be parsed as UTF8 because that's
the only RFC-compliant way to parse those bytes.

RFC 6855 says clients MUST send the UTF8 marker.

Due to an accidental discrepancy, RFC 9051 (IMAP4rev2) does not contain
that marker. IMAP4rev2 was intended to be upwardly compatible with RFC
6855, but this problem broke that. This has no ill effects, since the
marker does not change the message's meaning.

While investigating the problem, I noticed that Python uses the marker
incorrectly: Python uses it to mark ALL messages if UTF8=ACCEPT support
has been enabled, not just ones that contain UTF8 addresses.

The best way forward appear to be using the syntax defined in RFC 9051 and
publishing a revision to RFC 6855, so this change modifies imaplib to
match RFC 9051.

FWIW JMAP is like IMAP4rev2 in this case; UTF8 is just there, without any
marker. Also, neither UTF8=ACCEPT, IMAP4rev2 or JMAP provide any way to
learn whether a message was stored with or without the marker.

This quasi-accidentally solves python#78319 by removing the case that broke.
@arnt
arnt requested a review from a team as a code owner July 26, 2023 11:25
@bedevere-bot

Copy link
Copy Markdown

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

@arnt

arnt commented Jul 26, 2023

Copy link
Copy Markdown
Author

This seems small enough to not require a NEWS entry, I'd say.

@arnt

arnt commented Jul 26, 2023

Copy link
Copy Markdown
Author

I submitted the internet-draft to supersede RFC 6855 now and expect to get it to RFC fairly quickly.

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 13, 2026
@serhiy-storchaka

Copy link
Copy Markdown
Member

Fixed by #9436.

@arnt

arnt commented Aug 14, 2026

Copy link
Copy Markdown
Author

@serhiy-storchaka FYI #9436 doesn't fix this. #9436 makes python send "UTF8" even for messages that only use ASCII. That's a bug.

The code in this PR is correct, and conforms to the APPEND rules in both RFC 9051 and RFC 9755.

@serhiy-storchaka

Copy link
Copy Markdown
Member

You are right, I closed this too quickly. #9436 implements the RFC 6855 syntax that RFC 9755 removed.

But imaplib cannot tell the two kinds of server apart: RFC 6855 requires the marker for UTF-8 headers, RFC 9755 removes it, and both advertise UTF8=ACCEPT. imaplib does not support IMAP4rev2 yet (gh-122953).

What do deployed RFC 6855 servers do with an APPEND whose literal8 has UTF-8 headers and no marker — accept it, or reply NO? Would sending the marker only for messages with 8-bit headers be any better?

The RFC 6855 syntax is already released in 3.13.8+ and 3.14.1+, so removing it needs backports.

I can reopen this PR; it needs a rebase and a NEWS entry.

cc @svarshavchik, who reported gh-78319 and implements RFC 6855 in Courier-IMAP.

@bedevere-app

bedevere-app Bot commented Aug 15, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@serhiy-storchaka serhiy-storchaka removed the stale Stale PR or inactive for long period of time. label Aug 15, 2026
@svarshavchik

Copy link
Copy Markdown

Courier was coded for RFC-6855, and it rejects messages with UTF-8 headers if the APPEND command did not send a UTF-8 marker.

This mess is yet another prize-winner from the IETF. I cannot think of a single good reason for the change in RFC 9755. What a clusterfark.

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.

4 participants