From bf600e1c3ccfdb5308b0be88bec0296a3e1e773b Mon Sep 17 00:00:00 2001 From: Zackery Spytz Date: Mon, 3 Jun 2019 23:58:32 -0600 Subject: [PATCH 1/2] bpo-27513: email.utils.getaddresses() now handles Header objects getaddresses() should be able to handle a Header object if passed one. --- Lib/email/utils.py | 2 +- Lib/test/test_email/test_email.py | 6 ++++++ .../next/Library/2019-06-03-23-53-25.bpo-27513.qITN7d.rst | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2019-06-03-23-53-25.bpo-27513.qITN7d.rst diff --git a/Lib/email/utils.py b/Lib/email/utils.py index a8e46a761bf922..cfdfeb3f1a86e4 100644 --- a/Lib/email/utils.py +++ b/Lib/email/utils.py @@ -109,7 +109,7 @@ def formataddr(pair, charset='utf-8'): def getaddresses(fieldvalues): """Return a list of (REALNAME, EMAIL) for each fieldvalue.""" - all = COMMASPACE.join(fieldvalues) + all = COMMASPACE.join(str(v) for v in fieldvalues) a = _AddressList(all) return a.addresslist diff --git a/Lib/test/test_email/test_email.py b/Lib/test/test_email/test_email.py index eed60142b19e3b..237705f34bead5 100644 --- a/Lib/test/test_email/test_email.py +++ b/Lib/test/test_email/test_email.py @@ -3263,6 +3263,12 @@ def test_getaddresses_embedded_comment(self): addrs = utils.getaddresses(['User ((nested comment)) ']) eq(addrs[0][1], 'foo@bar.com') + def test_getaddresses_header_obj(self): + """Test the handling of a Header object.""" + eq = self.assertEqual + addrs = utils.getaddresses([Header('Al Person ')]) + eq(addrs[0][1], 'aperson@dom.ain') + def test_make_msgid_collisions(self): # Test make_msgid uniqueness, even with multiple threads class MsgidsThread(Thread): diff --git a/Misc/NEWS.d/next/Library/2019-06-03-23-53-25.bpo-27513.qITN7d.rst b/Misc/NEWS.d/next/Library/2019-06-03-23-53-25.bpo-27513.qITN7d.rst new file mode 100644 index 00000000000000..9c14ae9fa06301 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-06-03-23-53-25.bpo-27513.qITN7d.rst @@ -0,0 +1,2 @@ +:func:`email.charset.getaddresses` can now handle +:class:`~email.header.Header` objects. From 1c792769242e379e656a2a81bc4f1fad02096cdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Langa?= Date: Mon, 19 Jul 2021 16:55:52 +0200 Subject: [PATCH 2/2] Respond to review --- Lib/test/test_email/test_email.py | 3 +-- .../next/Library/2019-06-03-23-53-25.bpo-27513.qITN7d.rst | 5 +++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_email/test_email.py b/Lib/test/test_email/test_email.py index 237705f34bead5..0154bbad1f63f4 100644 --- a/Lib/test/test_email/test_email.py +++ b/Lib/test/test_email/test_email.py @@ -3265,9 +3265,8 @@ def test_getaddresses_embedded_comment(self): def test_getaddresses_header_obj(self): """Test the handling of a Header object.""" - eq = self.assertEqual addrs = utils.getaddresses([Header('Al Person ')]) - eq(addrs[0][1], 'aperson@dom.ain') + self.assertEqual(addrs[0][1], 'aperson@dom.ain') def test_make_msgid_collisions(self): # Test make_msgid uniqueness, even with multiple threads diff --git a/Misc/NEWS.d/next/Library/2019-06-03-23-53-25.bpo-27513.qITN7d.rst b/Misc/NEWS.d/next/Library/2019-06-03-23-53-25.bpo-27513.qITN7d.rst index 9c14ae9fa06301..90d49bb2a993f1 100644 --- a/Misc/NEWS.d/next/Library/2019-06-03-23-53-25.bpo-27513.qITN7d.rst +++ b/Misc/NEWS.d/next/Library/2019-06-03-23-53-25.bpo-27513.qITN7d.rst @@ -1,2 +1,3 @@ -:func:`email.charset.getaddresses` can now handle -:class:`~email.header.Header` objects. +:func:`email.utils.getaddresses` now accepts +:class:`email.header.Header` objects along with string values. +Patch by Zackery Spytz.