smtplib: missing case in handling 421 response in sendmail
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Bug report
Bug description:
The sendmail function in smtplib does a good job of handling 421 responses from SMTP servers but is missing one case. This may lead to SMTP client connections not being closed properly.
Background
SMTP servers can send 421 responses whenever they need to shut down the connection (RF 5321 3.8). Clients should take care of closing the connection when receiving a 421.
Details
The sendmail function combines the low-level SMTP commands into a full session for sending some text content via SMTP. The function needs to handle 421 responses, as any single command may return a 421 response. The function already handles almost all cases but is missing one for the call of the data function, which does its own response code checking and may raise an exception.
Test to reproduce
The test was derived from the corresponding rosetta-test SMTP test suite and adapted to the smtplib test infrastructure.
def test_421_during_data_cmd(self):
smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost',
timeout=support.LOOPBACK_TIMEOUT)
smtp.noop()
self.serv._SMTPchannel.data_response = '421 closing'
with self.assertRaises(smtplib.SMTPDataError):
smtp.sendmail('John@foo.org', ['Sally@foo.org'], 'test message')
self.assertIsNone(smtp.sock)
self.assertEqual(self.serv._SMTPchannel.rcpt_count, 0)
CPython versions tested on:
CPython main branch, 3.10, 3.12
Operating systems tested on:
Linux
Linked PRs
- gh-132797
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
检查 Lib/smtplib.py 中 sendmail 的 data 调用附近,以及 issue 中描述的数据响应检查。运行或调整 smtplib 测试基础设施中的 test_421_during_data_cmd;完成的标准是 421 情况引发 SMTPDataError、关闭 socket,并使 rcpt_count 保持为零。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- networking
- Issue 类型
- 缺陷
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 30/100