Skip to content

EmailMessage bad encoding for international domain #83938

Description

@Julien00859
BPO 39757
Nosy @warsaw, @bitdancer, @Julien00859, @iritkatriel
PRs
  • bpo-39757: Use IDNA to encode domain part in email address #18667
  • 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 = None
    closed_at = None
    created_at = <Date 2020-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 = <Date 2021-12-13.17:50:29.456>
    user = 'https://github.com/Julien00859'

    bugs.python.org fields:

    activity = <Date 2021-12-13.17:50:29.456>
    actor = 'iritkatriel'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['email']
    creation = <Date 2020-02-26.09:36:15.270>
    creator = 'Julien Castiaux'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 39757
    keywords = ['patch']
    message_count = 5.0
    messages = ['362687', '362801', '362802', '362906', '408472']
    nosy_count = 4.0
    nosy_names = ['barry', 'r.david.murray', 'Julien Castiaux', 'iritkatriel']
    pr_nums = ['18667']
    priority = 'normal'
    resolution = None
    stage = 'needs patch'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue39757'
    versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

    Linked PRs

    Activity

    1. Julien00859 commented on Feb 26, 2020

      Julien00859mannequin
      MannequinAuthor

      Affected python version: 3.5 and above (did test them all except 3.9)

      Steps to reproduce:

        from mail.message import EmailMessage
        from mail.policy import SMTP
      
        msg = EmailMessage(policy=SMTP)
        msg['To'] = 'Joe <joe@examplé.com>'  # notice the é in the domain
        print(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.

    2. Julien00859 commented on Feb 27, 2020

      Julien00859mannequin
      MannequinAuthor
    3. Julien00859 commented on Feb 27, 2020

      Julien00859mannequin
      MannequinAuthor

      Woops wrong copie/paste, here is the correct link: https://bugs.python.org/issue11783

    4. bitdancer commented on Feb 28, 2020

      @bitdancer
      Member

      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.

    5. changed the title [-]EmailMessage wrong encoding for international domain[/-] [+]EmailMessage bad encoding for international domain[/+] on Feb 28, 2020
    6. iritkatriel commented on Dec 13, 2021

      @iritkatriel
      Member

      Reproduced on 3.11.

    7. transferred this issue fromon Apr 10, 2022
    8. added
      stdlibStandard Library Python modules in the Lib/ directory
      on Nov 23, 2023
    9. added a commit that references this issue on May 1, 2026
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.10 (EOL)end of life3.11only security fixes3.9 (EOL)end of lifestdlibStandard Library Python modules in the Lib/ directorytopic-emailtype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions