8000 email.message generates invalid encoded header · Issue #136052 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content
email.message generates invalid encoded header #136052
@chrullrich

Description

@chrullrich

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtopic-emailtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0