The email parser class returns the wrong type for the parsed message
まだ誰も着手していません。
評価
調査の方向性
提供された再現コードを実行し、リンクされている parser と EmailMessage のドキュメントとともに、エントリポイント email.message_from_bytes を調査してください。意図された修正が返される型の変更なのか、ドキュメントの修正なのかを判断し、その後、実証された動作をカバーするテストを追加して、ドキュメント化された API と実行時の結果が一致することを確認してください。
索引モデルが issue の本文から書いたものです。
説明
Summary
According to the documentation,
The email package provides a standard parser that understands most email document structures, including MIME documents. You can pass the parser a bytes, string or file object, and the parser will return to you the root EmailMessage instance of the object structure.
In fact, the parser returns an object of the legacy Message class. Code which takes the documentation at face value will blow up if it attempts to invoke methods which the newer class has but the older class does not.
Environment
Python 3.11.1 (v3.11.1:a7a450f84a, Dec 6 2022, 15:24:06) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Repro
Here is a small program which demonstrates the problem.
Code
#!/usr/bin/env python3
import email
message_bytes = (
b'Content-type: multipart/form-data; boundary=------abracadabra\r\n'
b'\r\n'
b'------abracadabra\r\n'
b'Content-Disposition: form-data; name="f"; filename="f1"\r\n'
b'Content-Type: application/octet-stream\r\n'
b'\r\n'
b'\x01\r\n'
b'------abracadabra--\r\n'
)
message = email.message_from_bytes(message_bytes)
print(f'type of message is {type(message)}')
print('have get_content()?', hasattr(message, 'get_content'))
Output
% ./email-message-repro.py
type of message is <class 'email.message.Message'>
have get_content()? False
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 36k
- 平均マージ
- 1日 9時間
- マージ済み PR(30日)
- 558
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
python/cpython のほかの issue
-
docs pending
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
stdlib type-feature
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
stdlib type-feature
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
build type-bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
stdlib topic-email type-feature
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
似ている issue
-
🐛 Bug 🔔 Pending processing
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
jumpserver/jumpserver#17584 ·
-
link-check link-check:sphinx-theme
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 90/100
modelscope/DiffSynth-Studio#1702 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
OpenHands/extensions#626 · コメント 1 件 ·