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

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

Co-authored-by: Łukasz Langa <lukasz@langa.pl>
This commit is contained in:
Zackery Spytz 2021-07-19 09:07:54 -07:00 committed by GitHub
parent 1e651c6ada
commit 89f4c34797
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 1 deletions

View File

@ -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

View File

@ -3263,6 +3263,11 @@ Foo
addrs = utils.getaddresses(['User ((nested comment)) <foo@bar.com>'])
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 <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
class MsgidsThread(Thread):

View File

@ -0,0 +1,3 @@
:func:`email.utils.getaddresses` now accepts
:class:`email.header.Header` objects along with string values.
Patch by Zackery Spytz.