]> khamidou — GitHub mirrors - imapclient.git/commitdiff
Fixed problem when literal is followed by a non-literal (#33)
authorMenno Smits <menno@freshfoo.com>
Tue, 5 Jan 2010 13:42:35 +0000 (13:42 +0000)
committerMenno Smits <menno@freshfoo.com>
Tue, 5 Jan 2010 13:42:35 +0000 (13:42 +0000)
This problem manifested itself with GMail's IMAP. Patch based on what
Fergal sent in with the bug report.

THANKS
imapclient/imapclient.py
imapclient/test/test_FetchParser.py

diff --git a/THANKS b/THANKS
index a9003ac56dc5502ab538e53a5bcfa149c31665bf..67414b1c1005b370c4e7a4b14d94a9ce084a0adf 100644 (file)
--- a/THANKS
+++ b/THANKS
@@ -22,6 +22,7 @@ Bug Reports
 ------------
 Brian Jackson
 Neil Martinsen-Burrell
+Fergal (fergal _AT_ esatclear.ie)
 
 
 The project was partially developed while the author was working at NetBox Blue
index 8f1724cece1f7e351437fc53dbc72056e6e66b36..c77dce1f991ece420705bcf7df96817e026579ca 100644 (file)
@@ -598,6 +598,7 @@ class FetchParser(object):
             raise ValueError("don't know how to handle %r" % data)
 
         data = data.lstrip()
+        msgid = None
         if data[0].isdigit():
             # Get message ID
             msgid, data = data.split(None, 1)
@@ -605,11 +606,9 @@ class FetchParser(object):
 
             assert data.startswith('('), data
             data = data[1:]
-            if data.endswith(')'):
-                data = data[:-1]
 
-        else:
-            msgid = None
+        if data.endswith(')'):
+            data = data[:-1]
 
         for name, item in FetchTokeniser().process_pairs(data):
             name = name.upper()
index 3af6e13f76222756f45073c90259c8e41213c6af..5dbc4aa3f64bc045a423fa1ffcafb7287e5c3859 100644 (file)
@@ -179,20 +179,19 @@ class TestFetchParser(unittest.TestCase):
             )
 
     def testMultiTypesWithLiteral(self):
-        self._parse_test(
-            [
-                ('1 (INTERNALDATE " 9-Feb-2007 17:08:08 +0100" RFC822 {21}',
-                      'Subject: test\r\n\r\nbody'),
-                ')'
-                ],
-            {1: {
-                    'INTERNALDATE': datetime_to_native(datetime.datetime(2007, 2, 9,
-                                                                         17, 8, 8, 0,
-                                                                         FixedOffset(60))),
-                    'RFC822': 'Subject: test\r\n\r\nbody',
+        expected = {1: {'INTERNALDATE': datetime_to_native(datetime.datetime(2007, 2, 9,
+                                                                             17, 8, 8, 0,
+                                                                             FixedOffset(60))),
+                        'RFC822': 'Subject: test\r\n\r\nbody'}
                     }
-                }
-            )
+        self._parse_test([('1 (INTERNALDATE " 9-Feb-2007 17:08:08 +0100" RFC822 {21}',
+                           'Subject: test\r\n\r\nbody'), ')'],
+                         expected)
+
+        # Also test where there literal comes back first
+        self._parse_test([('1 (RFC822 {21}', 'Subject: test\r\n\r\nbody'),
+                           'INTERNALDATE " 9-Feb-2007 17:08:08 +0100")'],
+                           expected)
 
     def testLiteralsWithSections(self):
         self._parse_test(