The email parser class returns the wrong type for the parsed message
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 36k
- 平均合并
- 1 天 9 小时
- 30 天内合并 PR
- 558
描述
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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
运行提供的复现程序,并检查入口点 email.message_from_bytes,以及相关的 parser 和 EmailMessage 文档。确定预期的修复是更改返回类型还是更正文档,然后为所演示的行为添加覆盖测试,并验证文档化的 API 与运行时结果一致。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- backend
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 35/100