smtplib.quoteaddr() returns malformed angle-bracket address for input '<'
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
Bug report
Description
smtplib.quoteaddr() formats addresses for SMTP MAIL FROM: and RCPT TO: commands per RFC 821, which requires angle-bracket format (<addr>). It first delegates to email.utils.parseaddr(); when parsing succeeds, the result is correctly wrapped in <...>.
When parseaddr fails — which happens for inputs that don't resemble any recognizable email address format, like '<', '< ', or '@' — a fallback path kicks in. The fallback checks if the input starts with < and returns it verbatim, without verifying it also ends with >. This produces structurally invalid output (e.g. MAIL FROM:< instead of MAIL FROM:<>).
The existing code intentionally chooses to be lenient with unparseable input rather than raising an exception (the comment reads "use it as is and hope for the best"). Given that design choice, the output should at least be structurally valid — a half-open < with no > is neither rejecting bad input nor producing well-formed protocol output.
Reproducer
from smtplib import quoteaddr
print(repr(quoteaddr('<'))) # '<' — missing closing >
print(repr(quoteaddr('< '))) # '< ' — missing closing >
print(repr(quoteaddr('<user@example.com'))) # '<user@example.com' — missing >
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
Linked PRs
- gh-145553
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
smtplib.quoteaddr() から始め、email.utils.parseaddr() が入力を解析できない場合に使用されるフォールバックを調べてください。変更を加える前にリンクされた PR gh-145553 を確認し、その後、reproducer に示された不正な入力を対象とするテストカバレッジを追加し、返されるアドレスが構造的に有効であることを検証してください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- networking
- issue の種類
- バグ
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 35/100