[Python-checkins] bpo-27513: email.utils.getaddresses() now handles Header objects (GH-13797) (#27245)

ambv webhook-mailer at python.org
Mon Jul 19 13:29:00 EDT 2021


https://github.com/python/cpython/commit/9ee12cf325d4da2c07919e5e56545feb7e005e08
commit: 9ee12cf325d4da2c07919e5e56545feb7e005e08
branch: 3.9
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: ambv <lukasz at langa.pl>
date: 2021-07-19T19:28:56+02:00
summary:

bpo-27513: email.utils.getaddresses() now handles Header objects (GH-13797) (#27245)

getaddresses() should be able to handle a Header object if passed
one.

Co-authored-by: Łukasz Langa <lukasz at langa.pl>
(cherry picked from commit 89f4c34797de2f0e5045da2b97c1c8cbbb42fbb2)

Co-authored-by: Zackery Spytz <zspytz at gmail.com>

files:
A Misc/NEWS.d/next/Library/2019-06-03-23-53-25.bpo-27513.qITN7d.rst
M Lib/email/utils.py
M Lib/test/test_email/test_email.py

diff --git a/Lib/email/utils.py b/Lib/email/utils.py
index 1a7719dbc4898f..48d30160aa6ea0 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 ab68cdd8b5aed1..0421055ccfde9d 100644
--- a/Lib/test/test_email/test_email.py
+++ b/Lib/test/test_email/test_email.py
@@ -3262,6 +3262,11 @@ def test_getaddresses_embedded_comment(self):
         addrs = utils.getaddresses(['User ((nested comment)) <foo at bar.com>'])
         eq(addrs[0][1], 'foo at bar.com')
 
+    def test_getaddresses_header_obj(self):
+        """Test the handling of a Header object."""
+        addrs = utils.getaddresses([Header('Al Person <aperson at dom.ain>')])
+        self.assertEqual(addrs[0][1], 'aperson at 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.



More information about the Python-checkins mailing list