Skip to content

Commit bc29cb9

Browse files
committed
gh-40889: Fix email.utils.parseaddr to handle routes with multiple intermediate hops
1 parent be257c5 commit bc29cb9

3 files changed

Lines changed: 10 additions & 0 deletions

File tree

Lib/email/_parseaddr.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,8 @@ def getrouteaddr(self):
349349
elif self.field[self.pos] == '@':
350350
self.pos += 1
351351
expectroute = True
352+
elif self.field[self.pos] == ',':
353+
self.pos += 1
352354
elif self.field[self.pos] == ':':
353355
self.pos += 1
354356
else:

Lib/test/test_email/test_email.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3289,6 +3289,12 @@ def test_parseaddr_preserves_spaces_in_local_part(self):
32893289
self.assertEqual(('', 'merwok.wok.wok@xample.com'),
32903290
utils.parseaddr('merwok. wok . wok@xample.com'))
32913291

3292+
def test_parseaddr_handles_obsolete_addressing(self):
3293+
self.assertEqual(('foobar', 'foo@bar.com'),
3294+
utils.parseaddr('"foobar" <@hop.org:foo@bar.com>'))
3295+
self.assertEqual(('foobar', 'foo@bar.com'),
3296+
utils.parseaddr('"foobar" <@hop1.org,@hop2.org:foo@bar.com>'))
3297+
32923298
def test_formataddr_does_not_quote_parens_in_quoted_string(self):
32933299
addr = ("'foo@example.com' (foo@example.com)",
32943300
'foo@example.com')
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix :func:`email.utils.parseaddr` to handle routes with multiple intermediate hops
2+
(see :rfc:`RFC 2822, §4.4 <2822#section-4.4>`). Patch by Ioana Tagirta.

0 commit comments

Comments
 (0)