You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
EmailMessage bad encoding for international domain #83938
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=Nonecreated_at=<Date2020-02-26.09:36:15.270>labels= ['3.11', 'type-bug', 'expert-email', '3.10', '3.9']
title='EmailMessage bad encoding for international domain'updated_at=<Date2021-12-13.17:50:29.456>user='https://github.com/Julien00859'
Affected python version: 3.5 and above (did test them all except 3.9)
Steps to reproduce:
frommail.messageimportEmailMessagefrommail.policyimportSMTPmsg=EmailMessage(policy=SMTP)
msg['To'] ='Joe <joe@examplé.com>'# notice the é in the domainprint(msg.as_string())
It prints
To: "Joe <joe@=?utf-8?q?exampl=C3=A9?=.com>"
But it should be
To: "Joe <joe@xn--exampl-gva.com>"
While b64/qp can be used to encode most non-ascii headers, the domain part of an email address is an exception. According to IDNA2008 (rfc5890 , rfc5891), non-ascii domain should be encoded using the punycode algorithm and the ACE prefix.
This is not actually a duplicate of 11783. Rereading (parts of) that issue, we decided we currently have no good way to do automatic conversion between unicode and internationalized domains, so the user of the library has to do it themselves. This means that the bug *here* is that the new email API is *wrongly* encoding the non-ascii in the domain by using an encoded word. I'm surprised at that; I thought I'd guarded against it.
What should be happening here is that an error should be raised when that header is set (or possibly when it is accessed/serialized, but when set would be better I think) saying that there is non-ascii in the domain part.
Activity
Julien00859 commentedon Feb 26, 2020
Affected python version: 3.5 and above (did test them all except 3.9)
Steps to reproduce:
It prints
But it should be
While b64/qp can be used to encode most non-ascii headers, the domain part of an email address is an exception. According to IDNA2008 (rfc5890 , rfc5891), non-ascii domain should be encoded using the punycode algorithm and the ACE prefix.
Julien00859 commentedon Feb 27, 2020
Duplicate of https://bugs.python.org/issue39757
Julien00859 commentedon Feb 27, 2020
Woops wrong copie/paste, here is the correct link: https://bugs.python.org/issue11783
bitdancer commentedon Feb 28, 2020
This is not actually a duplicate of 11783. Rereading (parts of) that issue, we decided we currently have no good way to do automatic conversion between unicode and internationalized domains, so the user of the library has to do it themselves. This means that the bug *here* is that the new email API is *wrongly* encoding the non-ascii in the domain by using an encoded word. I'm surprised at that; I thought I'd guarded against it.
What should be happening here is that an error should be raised when that header is set (or possibly when it is accessed/serialized, but when set would be better I think) saying that there is non-ascii in the domain part.
[-]EmailMessage wrong encoding for international domain[/-][+]EmailMessage bad encoding for international domain[/+]iritkatriel commentedon Dec 13, 2021
Reproduced on 3.11.
gh-83938, gh-122476: Stop incorrectly RFC 2047 encoding non-ASCII ema…