email.utils.formataddr incorrect handling of unicode names with comma
Open
Nobody has claimed this yet.
topic-email
type-bug
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 36k
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 558
Description
Bug report
When email.charset is configured to produce 8bit content, calling email.utils.formataddr can result in corrupted output from formataddr. Here's example code:
import email.charset
import email.utils
email.charset.add_charset('utf-8', None)
print("To: " + email.utils.formataddr(('Foo, Bar', 'foo@example.com')))
print("To: " + email.utils.formataddr(('Fôo, Bar', 'foo@example.com')))
Expected output:
To: "Foo, Bar" <foo@example.com>
To: "Fôo, Bar" <foo@example.com>
Actual output:
To: "Foo, Bar" <foo@example.com>
To: Fôo, Bar <foo@example.com>
Your environment
- CPython versions tested on: 3.11.1
- Operating system and architecture: Fedora 37 x86_64
Linked PRs
- gh-155881
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.
Research direction
Start by running the supplied email.charset and email.utils.formataddr reproduction on CPython 3.11.1, then inspect formataddr's handling of non-ASCII display names containing commas. Done means the output matches the two expected To lines and a regression test covers the configured 8bit case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100