email as_bytes() corruption of headers with SMTPUTF8 policy
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
Research direction
Reproduce the issue with email.message_from_bytes and msg.as_bytes(policy=email.policy.SMTPUTF8) using the example in the report. Trace the email package's header parsing and serialization entry points, then add a regression test that preserves the Unicode display name and matches the expected output.
Written by the indexing model from the issue text.
Description
Bug report
Reading and then writing RFC2822 messages with SMTPUTF8 policy results in header corruption.
import email
import email.policy
odata = '''From: Unicôde Nâme <example@example.com>
To: Name One <name-one@example.com>, Name Two <name-two@example.com>, Unicôde Nàme <unicode-name@example.com>
Subject: Unicôde Subjéct
This message contains Uniçôde Çôntent.
'''
msg = email.message_from_bytes(odata.encode(), policy=email.policy.SMTPUTF8)
ndata = msg.as_bytes(policy=email.policy.SMTPUTF8)
print(ndata.decode())
Expected output:
From: Unicôde Nâme <example@example.com>
To: Name One <name-one@example.com>, Name Two <name-two@example.com>,
Unicôde Nàme <unicode-name@example.com>
Subject: Unicôde Subjéct
This message contains Uniçôde Çôntent.
Actual output:
From: Unicôde Nâme <example@example.com>
To: Name One <name-one@example.com>, Name Two <name-two@example.com>,
=?unknown-8bit?q?Unic=C3=B4de_N=C3=A0me?= <unicode-name@example.com>
Subject: Unicôde Subjéct
This message contains Uniçôde Çôntent.
Your environment
- CPython versions tested on: Python 3.11.0
- Operating system and architecture: Linux x86-64, Fedora 37
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 36k
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 558
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from python/cpython
-
docs pending
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
stdlib type-feature
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
stdlib type-feature
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
build type-bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
stdlib topic-email type-feature
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
🐛 Bug 🔔 Pending processing
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
jumpserver/jumpserver#17584 ·