Open
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