Skip to content

Commit f576aab

Browse files
committed
gh-40889: Fix email.utils.parseaddr on multiple intermediate route hops
1 parent d54c2d8 commit f576aab

3 files changed

Lines changed: 12 additions & 0 deletions

File tree

‎Lib/email/_parseaddr.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,8 @@ def getrouteaddr(self):
352352
elif self.field[self.pos] == '@':
353353
self.pos += 1
354354
expectroute = True
355+
elif self.field[self.pos] == ',':
356+
self.pos += 1
355357
elif self.field[self.pos] == ':':
356358
self.pos += 1
357359
else:

‎Lib/test/test_email/test_email.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3344,6 +3344,14 @@ def test_parseaddr_preserves_spaces_in_local_part(self):
33443344
self.assertEqual(('', 'merwok.wok.wok@xample.com'),
33453345
utils.parseaddr('merwok. wok . wok@xample.com'))
33463346

3347+
def test_parseaddr_handles_obsolete_addressing(self):
3348+
self.assertEqual(('foobar', 'foo@bar.com'),
3349+
utils.parseaddr('"foobar" <@hop.org:foo@bar.com>'))
3350+
self.assertEqual(('foobar', 'foo@bar.com'),
3351+
utils.parseaddr('"foobar" <@hop1.org,@hop2.org:foo@bar.com>'))
3352+
self.assertEqual(('foobar', 'foo@bar.com'),
3353+
utils.parseaddr('"foobar" <@hop1.org, @hop2.org, @hop3.org:foo@bar.com>'))
3354+
33473355
def test_formataddr_does_not_quote_parens_in_quoted_string(self):
33483356
addr = ("'foo@example.com' (foo@example.com)",
33493357
'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, Section 4.4 <2822#section-4.4>`).

0 commit comments

Comments
 (0)