From 8ea6234b65464d8188e8cb41e5568dd7c580d1aa Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Mon, 19 Jul 2021 10:28:56 -0700 Subject: [PATCH] bpo-27513: email.utils.getaddresses() now handles Header objects (GH-13797) (#27245) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 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 Gbp-Pq: Name 0014-bpo-27513-email.utils.getaddresses-now-handles-Heade.patch --- Lib/email/utils.py | 2 +- Lib/test/test_email/test_email.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Lib/email/utils.py b/Lib/email/utils.py index 1a7719d..48d3016 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 ab68cdd..0421055 100644 --- a/Lib/test/test_email/test_email.py +++ b/Lib/test/test_email/test_email.py @@ -3262,6 +3262,11 @@ Foo 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): -- 2.30.2