]> khamidou — GitHub mirrors - imapclient.git/commitdiff
Tokens shouldn't necessarily terminate after a "]"
authorMenno Smits <menno@freshfoo.com>
Fri, 10 Sep 2010 19:27:56 +0000 (20:27 +0100)
committerMenno Smits <menno@freshfoo.com>
Fri, 10 Sep 2010 19:27:56 +0000 (20:27 +0100)
This was breaking partial fetch response parsing.

imapclient/response_lexer.py
imapclient/test/test_response_parser.py

index cef65cbfc463638132fdce8989e709b0a3ff0d69..74eb63e77eeb599fcfb828fdeaacab35d6d86a7e 100644 (file)
@@ -81,10 +81,10 @@ class Lexer(object):
             for nextchar in stream_i:
                 if nextchar in wordchars:
                     token += nextchar
+                elif nextchar == '[':
+                    token += nextchar + read_until(stream_i, ']', escape=False)
                 else:
-                    if nextchar == '[':
-                        yield token + nextchar + read_until(stream_i, ']', escape=False)
-                    elif nextchar in whitespace:
+                    if nextchar in whitespace:
                         yield token
                     elif nextchar == '"':
                         assert not token
index 68d8078a52cc3203c28f15d6fc76baf0e3b7bcb0..1f731043bb3a85f1a497446c60383d93b5110bf8 100644 (file)
@@ -139,7 +139,7 @@ class TestParseResponse(unittest.TestCase):
     def test_square_brackets(self):
         self._test('foo[bar rrr]', 'foo[bar rrr]')
         self._test('"foo[bar rrr]"', 'foo[bar rrr]')
-        self._test('[foo bar]', '[foo bar]')  # Square brackets at start
+        self._test('[foo bar]def', '[foo bar]def')
         self._test('(foo [bar rrr])', ('foo', '[bar rrr]'))
         self._test('(foo foo[bar rrr])', ('foo', 'foo[bar rrr]'))
 
@@ -264,7 +264,15 @@ class TestParseFetchResponse(unittest.TestCase):
             [('123 (UID 31710 BODY[HEADER.FIELDS (from subject)] {57}', header_text), ')']),
             { 31710: {'BODY[HEADER.FIELDS (FROM SUBJECT)]': header_text,
                       'SEQ': 123}})
-              
+
+
+    def test_partial_fetch(self):
+        body = '01234567890123456789'
+        self.assertEquals(parse_fetch_response(
+            [('123 (UID 367 BODY[]<0> {20}', body), ')']),
+            { 367: {'BODY[]<0>': body,
+                    'SEQ': 123}})
+                    
 
     def test_INTERNALDATE(self):
         def check(date_str, expected_dt):