]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Back port from 2.4 branch:
authorBarry Warsaw <barry@python.org>
Mon, 1 May 2006 03:21:25 +0000 (03:21 +0000)
committerBarry Warsaw <barry@python.org>
Mon, 1 May 2006 03:21:25 +0000 (03:21 +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.

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

index eb1051a61308993133c7d633b7971ca094ae4dbb..635ffc397ae4c726d68cc7af94eeb083b538f199 100644 (file)
@@ -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:
index fb2e488a1b9e23bb23ee53572abf34f56ff77960..44cd2e278deba40818483c19e4c5f7ae7ad34f7a 100644 (file)
@@ -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()
index 4f69b22aabdeb6506433d7b9baa808d2fc00c2e1..85e38e6f2cb759b0f8c25364a95ad94eca34a220 100644 (file)
@@ -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:
index c450bf97ce09e4a37747a8920cafee5bd59d14bb..75ec2c36f6e2e8864a681e537fa1ac3a070735b6 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