Skip to content

Commit

Permalink
bpo-27513: email.utils.getaddresses() now handles Header objects (pyt…
Browse files Browse the repository at this point in the history
…honGH-13797)

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

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

Co-authored-by: Zackery Spytz <zspytz@gmail.com>
  • Loading branch information
ZackerySpytz authored and miss-islington committed Jul 19, 2021
1 parent 2f643b1 commit a98b81b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Lib/email/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions Lib/test/test_email/test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -3262,6 +3262,11 @@ def test_getaddresses_embedded_comment(self):
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):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:func:`email.utils.getaddresses` now accepts
:class:`email.header.Header` objects along with string values.
Patch by Zackery Spytz.

0 comments on commit a98b81b

Please sign in to comment.