email.parser.Parser dropping headers into payload if space between header name and colon
还没有人认领这个 Issue。
评估
调研方向
从提供的 email.parser.BytesParser reproducer 开始,并将解析后的 headers 与 get_payload() 进行比较。查看已链接的 PR gh-93176,了解已经在进行的工作;当冒号前带有空白的 headers 仍保持为 headers,且不会被移入 payload 时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
In some cases, I have seen the standard library email message parser (invoked via email.parser.BytesParser) losing headers, in cases where a message has a header line where a space appears between the header name and the delimiting colon following.
Sample which reproduces this:
Subject: test-ignore
To: someone@somedomain.com
x-fred :dead
Date: Fri, 20 May 2022 18:13:19 +1200
From: sender@somedomain.com
Hello, this is a test message
When this is parsed in email.parser.BytesParser, the resulting EmailMessage object has these headers, as dumped by calling .items():
[('Subject', 'test-ignore'),
('To', ': someone@somedomain.com;')
]
Meanwhile, the dropped headers end up in the message payload, as seen from calling .get_payload():
x-fred :dead
Date: Fri, 20 May 2022 18:13:19 +1200
From: sender@somedomain.com
Hello, this is a test message
This failure to gracefully cope with a non-compliant header puts Python3's standard library email parser in breach of RFC5322, Section 4.5: ...any amount of white space is allowed [in the header] before the ":" at the end of the [header] field name...
To cope with email.parser.Parser's failure to cope with this archaic header format, I've had to implement a crude workaround of detecting if any expected headers are absent in the resulting email.message.EmailMessage object, and if so, manually 'massaging' the headers part of the raw message, then re-submitting it to the Parser.
However, I'd suggest this really does need to be fixed within Python's standard library module.
Linked PRs
- gh-93176
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 36k
- 平均合并
- 1 天 9 小时
- 30 天内合并 PR
- 558
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 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
难度 2/5 1-3 小时 新手友好度 86/100
zostera/django-bootstrap4#894 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
use-agent-os/agent-os#3276 ·
-
难度 2/5 1-3 小时 新手友好度 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
难度 2/5 1-3 小时 新手友好度 88/100
NousResearch/hermes-agent#117848 ·
-
难度 2/5 1-3 小时 新手友好度 82/100
zilliztech/memsearch#759 ·