Skip to content

Commit 8c43bf1

Browse files
bpo-27513: email.utils.getaddresses() now handles Header objects (GH-13797) (GH-27242)
getaddresses() should be able to handle a Header object if passed one. Co-authored-by: Łukasz Langa <[email protected]> (cherry picked from commit 89f4c34) Co-authored-by: Zackery Spytz <[email protected]>
1 parent 2d04920 commit 8c43bf1

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

Lib/email/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def formataddr(pair, charset='utf-8'):
109109

110110
def getaddresses(fieldvalues):
111111
"""Return a list of (REALNAME, EMAIL) for each fieldvalue."""
112-
all = COMMASPACE.join(fieldvalues)
112+
all = COMMASPACE.join(str(v) for v in fieldvalues)
113113
a = _AddressList(all)
114114
return a.addresslist
115115

Lib/test/test_email/test_email.py

+5
Original file line numberDiff line numberDiff line change
@@ -3263,6 +3263,11 @@ def test_getaddresses_embedded_comment(self):
32633263
addrs = utils.getaddresses(['User ((nested comment)) <[email protected]>'])
32643264
eq(addrs[0][1], '[email protected]')
32653265

3266+
def test_getaddresses_header_obj(self):
3267+
"""Test the handling of a Header object."""
3268+
addrs = utils.getaddresses([Header('Al Person <[email protected]>')])
3269+
self.assertEqual(addrs[0][1], '[email protected]')
3270+
32663271
def test_make_msgid_collisions(self):
32673272
# Test make_msgid uniqueness, even with multiple threads
32683273
class MsgidsThread(Thread):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:func:`email.utils.getaddresses` now accepts
2+
:class:`email.header.Header` objects along with string values.
3+
Patch by Zackery Spytz.

0 commit comments

Comments
 (0)