summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2006-05-01 03:21:25 +0000
committerBarry Warsaw <barry@python.org>2006-05-01 03:21:25 +0000
commite3e785180b2d591304d4c817da04131442951567 (patch)
tree2278ececcaff818c0d7bfbe0913bdd433a10c927
parentdc74e34e24d01323cfb89a0a5c11416f85adebd0 (diff)
downloadcpython-git-e3e785180b2d591304d4c817da04131442951567.tar.gz
Back port 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.
-rw-r--r--Lib/email/_parseaddr.py1
-rw-r--r--Lib/email/test/test_email.py6
-rw-r--r--Lib/rfc822.py1
-rw-r--r--Lib/test/test_rfc822.py10
4 files changed, 18 insertions, 0 deletions
diff --git a/Lib/email/_parseaddr.py b/Lib/email/_parseaddr.py
index eb1051a613..635ffc397a 100644
--- a/Lib/email/_parseaddr.py
+++ b/Lib/email/_parseaddr.py
@@ -365,6 +365,7 @@ class AddrlistClass:
break
elif allowcomments and self.field[self.pos] == '(':
slist.append(self.getcomment())
+ continue # have already advanced pos from getcomment
elif self.field[self.pos] == '\\':
quote = True
else:
diff --git a/Lib/email/test/test_email.py b/Lib/email/test/test_email.py
index fb2e488a1b..44cd2e278d 100644
--- a/Lib/email/test/test_email.py
+++ b/Lib/email/test/test_email.py
@@ -2064,6 +2064,12 @@ class TestMiscellaneous(unittest.TestCase):
['foo: ;', '"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):
eq = self.assertEqual
msg = Message()
diff --git a/Lib/rfc822.py b/Lib/rfc822.py
index 4f69b22aab..85e38e6f2c 100644
--- a/Lib/rfc822.py
+++ b/Lib/rfc822.py
@@ -712,6 +712,7 @@ class AddrlistClass:
break
elif allowcomments and self.field[self.pos] == '(':
slist.append(self.getcomment())
+ continue # have already advanced pos from getcomment
elif self.field[self.pos] == '\\':
quote = 1
else:
diff --git a/Lib/test/test_rfc822.py b/Lib/test/test_rfc822.py
index c450bf97ce..75ec2c36f6 100644
--- a/Lib/test/test_rfc822.py
+++ b/Lib/test/test_rfc822.py
@@ -45,6 +45,10 @@ class MessageTestCase(unittest.TestCase):
print 'extra parsed address:', repr(n), repr(a)
continue
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:
pass
else:
@@ -129,6 +133,12 @@ class MessageTestCase(unittest.TestCase):
'To: person@dom.ain (User J. Person)\n\n',
[('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):
# This one is just twisted. I don't know what the proper
# result should be, but it shouldn't be to infloop, which is