GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — EmailMessage bad encoding for non-ASCII localpart · Issue #122476 · python/cpython Closed Labels stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-emailtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error DescriptionBug reportBug description:The modern email package incorrectly encodes a non-ASCII email address 'local-part' (username) using an RFC 2047 encoded-word, resulting in undeliverable email: >>> from email.message import EmailMessage >>> msg = EmailMessage() >>> msg["To"] = "jö[email protected]" >>> msg.as_bytes() b'To: [email protected]\n\n' That use is prohibited by RFC 2047 section 5:
This issue is related to #83938, which covers the same problem in an email address domain. In a comment there, @bitdancer says:
Since email.policy.SMTPUTF8 allows non-ASCII addr-specs, I think the error will have to be when the header is serialized with a utf8=False policy (and not when the header is set): # Expected behavior (using `msg` from example above):
>>> msg.as_bytes()
ValueError('Non-ASCII username requires SMTPUTF8 policy')
# This already works correctly:
>>> from email.policy import SMTPUTF8
msg.as_bytes(policy=SMTPUTF8)
b'To: j\xc3\[email protected]\r\n\r\n'More info:
CPython versions tested on:3.8, 3.9, 3.10, 3.11, 3.12, 3.13, CPython main branch Operating systems tested on:Linux, macOS Activity
MetadataMetadataAssigneesLabelsstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-emailtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error ProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |