python / python/cpython

email.message generates invalid encoded header

オープン
#136,052 コメント 3 件 リアクション 2 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

stdlib topic-email type-bug
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、SMTP policy を使用して email.message.Message で例を再現し、header folding と RFC 2047 encoding path を調査します。完了の条件は、生成された Subject に空の encoded-text が含まれず、RFC 2047-valid のままであり、この入力に対する回帰テストのカバレッジがあることです。レポートには関連する PRs gh-136098 と gh-136099 を記載します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
backend
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。