Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Lib/email/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
CRLF = '\r\n'
TICK = "'"

specialsre = re.compile(r'[][\\()<>@,:;".]')
# These are used by formataddr() to understand what characters require a name
# field to be quoted and what characters within that must be \escaped.
specialsre = re.compile(r'[][\\()<>@,:;". ]')
escapesre = re.compile(r'[\\"]')


Expand Down
8 changes: 7 additions & 1 deletion Lib/test/test_email/test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -3227,7 +3227,7 @@ def test_parseaddr_multiple_domains(self):
def test_noquote_dump(self):
self.assertEqual(
utils.formataddr(('A Silly Person', '[email protected]')),
'A Silly Person <[email protected]>')
'"A Silly Person" <[email protected]>')

def test_escape_dump(self):
self.assertEqual(
Expand All @@ -3248,6 +3248,12 @@ def test_escape_backslashes(self):
b = '[email protected]'
self.assertEqual(utils.parseaddr(utils.formataddr((a, b))), (a, b))

def test_parseaddr_formataddr_inverse(self):
# gh-91400
identity = '"foo bar" <[email protected]>'
single = utils.formataddr(utils.parseaddr(identity))
self.assertEqual(identity, single)

def test_quotes_unicode_names(self):
# issue 1690608. email.utils.formataddr() should be rfc2047 aware.
name = "H\u00e4ns W\u00fcrst"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Make :func:`email.utils.formataddr` "quote" the name portion of an email address if
it contains spaces.
Loading