From fc8b6c8e1885224038093fd8e76e633756ceb4e7 Mon Sep 17 00:00:00 2001 From: Stefan Zetzsche Date: Sun, 22 Feb 2026 14:55:34 +0000 Subject: [PATCH 1/3] gh-XXXXX: Fix smtplib.quoteaddr() returning malformed address for '<' Input starting with '<' but missing closing '>' was returned verbatim. Ensure the result always ends with '>'. --- Lib/smtplib.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/smtplib.py b/Lib/smtplib.py index 72093f7f8b0f2d..e33f72efa98754 100644 --- a/Lib/smtplib.py +++ b/Lib/smtplib.py @@ -150,7 +150,9 @@ def quoteaddr(addrstring): if (displayname, addr) == ('', ''): # parseaddr couldn't parse it, use it as is and hope for the best. if addrstring.strip().startswith('<'): - return addrstring + if addrstring.strip().endswith('>'): + return addrstring + return addrstring.strip() + '>' return "<%s>" % addrstring return "<%s>" % addr From 660ee1217b44d401d57d4df6a6b1e3a46baf0154 Mon Sep 17 00:00:00 2001 From: Stefan Zetzsche Date: Thu, 5 Mar 2026 15:03:48 +0000 Subject: [PATCH 2/3] test(smtplib): Add tests for quoteaddr angle-bracket handling Add testQuoteAddr for basic quoteaddr behavior and testQuoteAddrMalformedAngleBracket for inputs starting with '<' but missing closing '>'. The latter fails without the fix. --- Lib/test/test_smtplib.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Lib/test/test_smtplib.py b/Lib/test/test_smtplib.py index b8aac8c20202a2..fac8323d75953c 100644 --- a/Lib/test/test_smtplib.py +++ b/Lib/test/test_smtplib.py @@ -77,6 +77,26 @@ def testQuoteData(self): expected = "abc\r\n..jkl\r\nfoo\r\n...blue" self.assertEqual(expected, smtplib.quotedata(teststr)) + def testQuoteAddr(self): + # Standard address is wrapped in angle brackets. + self.assertEqual(smtplib.quoteaddr('user@example.com'), + '') + # Already angle-bracketed and valid. + self.assertEqual(smtplib.quoteaddr(''), + '') + # Empty string produces empty angle brackets. + self.assertEqual(smtplib.quoteaddr(''), '<>') + + def testQuoteAddrMalformedAngleBracket(self): + # Inputs starting with '<' but missing closing '>' must still + # produce output that ends with '>'. + result = smtplib.quoteaddr('<') + self.assertTrue(result.startswith('<') and result.endswith('>'), result) + result = smtplib.quoteaddr('< ') + self.assertTrue(result.startswith('<') and result.endswith('>'), result) + result = smtplib.quoteaddr(''), result) + def testBasic1(self): mock_socket.reply_with(b"220 Hola mundo") # connects From a95680f113d42332f9a53ab294793b08095ab3bd Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Thu, 5 Mar 2026 15:20:19 +0000 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2026-03-05-15-20-18.gh-issue-145552.80p_Cr.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2026-03-05-15-20-18.gh-issue-145552.80p_Cr.rst diff --git a/Misc/NEWS.d/next/Library/2026-03-05-15-20-18.gh-issue-145552.80p_Cr.rst b/Misc/NEWS.d/next/Library/2026-03-05-15-20-18.gh-issue-145552.80p_Cr.rst new file mode 100644 index 00000000000000..8c074d08e79380 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-03-05-15-20-18.gh-issue-145552.80p_Cr.rst @@ -0,0 +1 @@ +Fix ``smtplib.quoteaddr()`` to ensure the returned address always has a closing ``>`` when the input starts with ``<`` but ``email.utils.parseaddr()`` fails to parse it.