From 0300d8f86bb472b0685f03a5c9dc7b71b076f3ab Mon Sep 17 00:00:00 2001 From: Menno Smits Date: Tue, 5 Jan 2010 13:42:35 +0000 Subject: [PATCH] Fixed problem when literal is followed by a non-literal (#33) This problem manifested itself with GMail's IMAP. Patch based on what Fergal sent in with the bug report. --- THANKS | 1 + imapclient/imapclient.py | 7 +++---- imapclient/test/test_FetchParser.py | 25 ++++++++++++------------- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/THANKS b/THANKS index a9003ac..67414b1 100644 --- 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 diff --git a/imapclient/imapclient.py b/imapclient/imapclient.py index 8f1724c..c77dce1 100644 --- a/imapclient/imapclient.py +++ b/imapclient/imapclient.py @@ -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() diff --git a/imapclient/test/test_FetchParser.py b/imapclient/test/test_FetchParser.py index 3af6e13..5dbc4aa 100644 --- a/imapclient/test/test_FetchParser.py +++ b/imapclient/test/test_FetchParser.py @@ -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( -- 2.43.0