]> khamidou — GitHub mirrors - imapclient.git/commitdiff
Added is_multipart attribute to returned BODY/BODYSTRUCTURE tuples
authorMenno Smits <menno@freshfoo.com>
Mon, 8 Nov 2010 14:30:42 +0000 (14:30 +0000)
committerMenno Smits <menno@freshfoo.com>
Mon, 8 Nov 2010 14:30:42 +0000 (14:30 +0000)
imapclient/response_parser.py
livetest.py

index faef1c91850a6437d8104713505ecbd0759a3d6b..313dd37bab65662ce9b952518875b6243ff2434c 100644 (file)
@@ -79,6 +79,8 @@ def parse_fetch_response(text):
                 msg_id = _int_or_error(value, 'invalid UID')
             elif word == 'INTERNALDATE':
                 msg_data[word] = _convert_INTERNALDATE(value)
+            elif word in ('BODY', 'BODYSTRUCTURE'):
+                msg_data[word] = BodyData(value)
             else:
                 msg_data[word] = value
 
@@ -94,6 +96,13 @@ def _int_or_error(value, error_text):
         raise ParseError('%s: %s' % (error_text, repr(value)))
 
 
+class BodyData(tuple):
+
+    @property
+    def is_multipart(self):
+        return isinstance(self[0], list)
+    
+
 def _convert_INTERNALDATE(date_string):
     mo = imaplib.InternalDate.match('INTERNALDATE "%s"' % date_string)
     if not mo:
index a841032c09621fc37f62ffad3b8532f5353e4382..44060b7c368ed3134519a664adac37214d1c63e2 100755 (executable)
@@ -365,19 +365,22 @@ def test_BODYSTRUCTURE(client):
     # will return.
 
     expected = ('text', 'plain', ('charset', 'us-ascii'), None, None, '7bit', 5, 1)
-    check_BODYSTRUCTURE(expected, fetched[msgs[0]]['BODY'])
-    check_BODYSTRUCTURE(expected, fetched[msgs[0]]['BODYSTRUCTURE'])
+    check_BODYSTRUCTURE(expected, fetched[msgs[0]]['BODY'], multipart=False)
+    check_BODYSTRUCTURE(expected, fetched[msgs[0]]['BODYSTRUCTURE'], multipart=False)
 
     expected = ([('text', 'html', ('charset', 'us-ascii'), None, None, 'quoted-printable', 55, 3),
                  ('text', 'plain', ('charset', 'us-ascii'), None, None, '7bit', 26, 1),
                  ],
                 'mixed',
                 ('boundary', '===============1534046211=='))
-    check_BODYSTRUCTURE(expected, fetched[msgs[1]]['BODY'])
-    check_BODYSTRUCTURE(expected, fetched[msgs[1]]['BODYSTRUCTURE'])
+    check_BODYSTRUCTURE(expected, fetched[msgs[1]]['BODY'], multipart=True)
+    check_BODYSTRUCTURE(expected, fetched[msgs[1]]['BODYSTRUCTURE'], multipart=True)
 
 
-def check_BODYSTRUCTURE(expected, actual):
+def check_BODYSTRUCTURE(expected, actual, multipart=None):
+    if multipart is not None:
+        assert actual.is_multipart == multipart
+
     # BODYSTRUCTURE lengths can various according to the server so
     # compare up until what is returned
     for e, a in zip(expected, actual):