]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Patch #1464708 from William McVey: fixed handling of nested comments in mail
authorBarry Warsaw <barry@python.org>
Sun, 30 Apr 2006 21:26:41 +0000 (21:26 +0000)
committerBarry Warsaw <barry@python.org>
Sun, 30 Apr 2006 21:26:41 +0000 (21:26 +0000)
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 and forward ported to Python 2.5 for email
4.0.  (I'll do both soon)

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

index 8e6cb60bd58a7dd3781f22f535df7fe1ea94751e..14012837925aba224dee38262db83a179ce1818f 100644 (file)
@@ -360,6 +360,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 18f4894a31d0fe248928557f70e9406b50e1b0e2..1e4a510ad1d676e10bf1efe1653a64f6305195b3 100644 (file)
@@ -2212,6 +2212,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 18277d6dff4dbe080e9902d65e961623b1f8e354..1319d231e0e408d9e324dc97066b14855cec1038 100644 (file)
@@ -711,6 +711,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