mirror of
https://github.com/python/cpython.git
synced 2025-09-14 12:46:49 +00:00
Port forward from 2.4 branch:
Patch #1464708 from William McVey: fixed handling of nested comments in mail addresses. E.g. "Foo ((Foo Bar)) <foo@example.com>" Fixes for both rfc822.py and email package. This patch needs to be back ported to Python 2.3 for email 2.5.
This commit is contained in:
parent
09612281ef
commit
dbcc8d9b24
5 changed files with 24 additions and 0 deletions
|
@ -367,6 +367,7 @@ class AddrlistClass:
|
||||||
break
|
break
|
||||||
elif allowcomments and self.field[self.pos] == '(':
|
elif allowcomments and self.field[self.pos] == '(':
|
||||||
slist.append(self.getcomment())
|
slist.append(self.getcomment())
|
||||||
|
continue # have already advanced pos from getcomment
|
||||||
elif self.field[self.pos] == '\\':
|
elif self.field[self.pos] == '\\':
|
||||||
quote = True
|
quote = True
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -2215,6 +2215,12 @@ class TestMiscellaneous(TestEmailBase):
|
||||||
['foo: ;', '"Jason R. Mastaler" <jason@dom.ain>']),
|
['foo: ;', '"Jason R. Mastaler" <jason@dom.ain>']),
|
||||||
[('', ''), ('Jason R. Mastaler', 'jason@dom.ain')])
|
[('', ''), ('Jason R. Mastaler', 'jason@dom.ain')])
|
||||||
|
|
||||||
|
def test_getaddresses_embedded_comment(self):
|
||||||
|
"""Test proper handling of a nested comment"""
|
||||||
|
eq = self.assertEqual
|
||||||
|
addrs = Utils.getaddresses(['User ((nested comment)) <foo@bar.com>'])
|
||||||
|
eq(addrs[0][1], 'foo@bar.com')
|
||||||
|
|
||||||
def test_utils_quote_unquote(self):
|
def test_utils_quote_unquote(self):
|
||||||
eq = self.assertEqual
|
eq = self.assertEqual
|
||||||
msg = Message()
|
msg = Message()
|
||||||
|
|
|
@ -2221,6 +2221,12 @@ class TestMiscellaneous(TestEmailBase):
|
||||||
['foo: ;', '"Jason R. Mastaler" <jason@dom.ain>']),
|
['foo: ;', '"Jason R. Mastaler" <jason@dom.ain>']),
|
||||||
[('', ''), ('Jason R. Mastaler', 'jason@dom.ain')])
|
[('', ''), ('Jason R. Mastaler', 'jason@dom.ain')])
|
||||||
|
|
||||||
|
def test_getaddresses_embedded_comment(self):
|
||||||
|
"""Test proper handling of a nested comment"""
|
||||||
|
eq = self.assertEqual
|
||||||
|
addrs = utils.getaddresses(['User ((nested comment)) <foo@bar.com>'])
|
||||||
|
eq(addrs[0][1], 'foo@bar.com')
|
||||||
|
|
||||||
def test_utils_quote_unquote(self):
|
def test_utils_quote_unquote(self):
|
||||||
eq = self.assertEqual
|
eq = self.assertEqual
|
||||||
msg = Message()
|
msg = Message()
|
||||||
|
|
|
@ -700,6 +700,7 @@ class AddrlistClass:
|
||||||
break
|
break
|
||||||
elif allowcomments and self.field[self.pos] == '(':
|
elif allowcomments and self.field[self.pos] == '(':
|
||||||
slist.append(self.getcomment())
|
slist.append(self.getcomment())
|
||||||
|
continue # have already advanced pos from getcomment
|
||||||
elif self.field[self.pos] == '\\':
|
elif self.field[self.pos] == '\\':
|
||||||
quote = 1
|
quote = 1
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -45,6 +45,10 @@ class MessageTestCase(unittest.TestCase):
|
||||||
print 'extra parsed address:', repr(n), repr(a)
|
print 'extra parsed address:', repr(n), repr(a)
|
||||||
continue
|
continue
|
||||||
i = i + 1
|
i = i + 1
|
||||||
|
self.assertEqual(mn, n,
|
||||||
|
"Un-expected name: %s != %s" % (`mn`, `n`))
|
||||||
|
self.assertEqual(ma, a,
|
||||||
|
"Un-expected address: %s != %s" % (`ma`, `a`))
|
||||||
if mn == n and ma == a:
|
if mn == n and ma == a:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
@ -129,6 +133,12 @@ class MessageTestCase(unittest.TestCase):
|
||||||
'To: person@dom.ain (User J. Person)\n\n',
|
'To: person@dom.ain (User J. Person)\n\n',
|
||||||
[('User J. Person', 'person@dom.ain')])
|
[('User J. Person', 'person@dom.ain')])
|
||||||
|
|
||||||
|
def test_doublecomment(self):
|
||||||
|
# The RFC allows comments within comments in an email addr
|
||||||
|
self.check(
|
||||||
|
'To: person@dom.ain ((User J. Person)), John Doe <foo@bar.com>\n\n',
|
||||||
|
[('User J. Person', 'person@dom.ain'), ('John Doe', 'foo@bar.com')])
|
||||||
|
|
||||||
def test_twisted(self):
|
def test_twisted(self):
|
||||||
# This one is just twisted. I don't know what the proper
|
# This one is just twisted. I don't know what the proper
|
||||||
# result should be, but it shouldn't be to infloop, which is
|
# result should be, but it shouldn't be to infloop, which is
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue