email.message generates invalid encoded header
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 36k
- PR merge metrics
- PR metrics pending
Description
Bug report
Bug description:
A message header generated by email.message.Message can contain invalid RFC 2047 encoded-words.
import sys
from email.message import Message
from email.policy import SMTP
msg = Message(policy=SMTP)
msg["Subject"] = "Re: some few filler words here RE: Routeraustausch und übriggebliebene Glasfaser"
sys.stdout.buffer.write(msg.as_bytes())
Result:
Subject: Re: some few filler words here RE: Routeraustausch und =?utf-8?q??=
=?utf-8?q?=C3=BCbriggebliebene?= Glasfaser
The encoded-word in the first line is invalid. Per RFC 2047 the "encoded-text" must not be empty:
encoded-word = "=?" charset "?" encoding "?" encoded-text "?="
encoded-text = 1*<Any printable ASCII character other than "?"
or SPACE>
The error does not appear in this case with the default policy because the header value is split up entirely differently.
CPython versions tested on:
3.13, 3.12
Operating systems tested on:
Windows, Other
Linked PRs
- gh-136098
- gh-136099
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 reproducing the example using email.message.Message with the SMTP policy and inspect the header folding and RFC 2047 encoding path. Done means the generated Subject contains no empty encoded-text and remains RFC 2047-valid, with regression coverage for this input; the report lists linked PRs gh-136098 and gh-136099.
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
- 25/100