]> granicus.if.org Git - python/commitdiff
Port forward from 2.4 branch:
authorBarry Warsaw <barry@python.org>
Mon, 1 May 2006 03:03:02 +0000 (03:03 +0000)
committerBarry Warsaw <barry@python.org>
Mon, 1 May 2006 03:03:02 +0000 (03:03 +0000)
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.

Lib/email/_parseaddr.py
Lib/email/test/test_email.py
Lib/email/test/test_email_renamed.py
Lib/rfc822.py
Lib/test/test_rfc822.py

index 5821ddf09058d5a3261fe17c35df9535e2fbf93d..a08c43e7f49de6e62d9186a7597a8d507cc049be 100644 (file)
@@ -367,6 +367,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:
index d97769362be003d278f79c90d20a196c92e05390..a197a36180761b42c9ad3e26f549d275108b9c2e 100644 (file)
@@ -2215,6 +2215,12 @@ class TestMiscellaneous(TestEmailBase):
            ['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()
index 4ac2ee91da7284a9d69d48941e8e499cc540274c..95d06cb66f11e1b0b10d55152e6d69d0764b4ac7 100644 (file)
@@ -2221,6 +2221,12 @@ class TestMiscellaneous(TestEmailBase):
            ['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()
index 871a049c2192074a9c6a45d010a6fb568e78c657..d6d5e4712972e83b14c0b069a60e9baf904d4c1c 100644 (file)
@@ -700,6 +700,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:
index 0d9f28a777161ee33226bc0e51214b840d509a69..6d22825ddf6e69cb718fbb0bba5aac087141d3f0 100644 (file)
@@ -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