From ff346cc9ff7239805d52f522a27fe8bf255ddfac Mon Sep 17 00:00:00 2001 From: Zackery Spytz Date: Mon, 19 Jul 2021 09:07:54 -0700 Subject: [PATCH] bpo-27513: email.utils.getaddresses() now handles Header objects (GH-13797) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit getaddresses() should be able to handle a Header object if passed one. Co-authored-by: Ɓukasz Langa (cherry picked from commit 89f4c34797de2f0e5045da2b97c1c8cbbb42fbb2) Co-authored-by: Zackery Spytz --- Lib/email/utils.py | 2 +- Lib/test/test_email/test_email.py | 5 +++++ .../next/Library/2019-06-03-23-53-25.bpo-27513.qITN7d.rst | 3 +++ 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..0154bbad1f63f4 100644 --- a/Lib/test/test_email/test_email.py +++ b/Lib/test/test_email/test_email.py @@ -3263,6 +3263,11 @@ 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.""" + addrs = utils.getaddresses([Header('Al Person ')]) + self.assertEqual(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..90d49bb2a993f1 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-06-03-23-53-25.bpo-27513.qITN7d.rst @@ -0,0 +1,3 @@ +:func:`email.utils.getaddresses` now accepts +:class:`email.header.Header` objects along with string values. +Patch by Zackery Spytz.