Skip to content

email.message_from_binary_file creates invalid RFC2047 encodings #142424

@msapiro

Description

@msapiro

Bug report

Bug description:

The following illustrates the issue.

>>> # Here's an example file
>>> with open('badx2.eml') as fp:
...     print(fp.read())
...     
From: "Sweepstakes Alert–Dyson Vacuum" <DysonVacuumSweeps@stellaryx.space>

body

>>> # Note that the `–` above is a unicode En Dash
>>> # Make a message object
>>> from email import message_from_binary_file
>>> with open('badx2.eml', 'rb') as fp:
...     msg = message_from_binary_file(fp)
...     
>>> # and look at it
>>> print(msg.as_string())
From: =?unknown-8bit?q?=22Sweepstakes_Alert=E2=80=93Dyson_Vacuum=22_=3CDysonVacuumSweeps=40stellaryx=2Espace=3E?=

body

>>> # Note that the email address is improperly included in the encoded word

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard 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