python / python/cpython

email.utils.formataddr incorrect handling of unicode names with comma

Open
#100,900 1 comment 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.