]> khamidou — GitHub mirrors - imapclient.git/commitdiff
Return expunge responses (#80)
authorMenno Smits <menno@freshfoo.com>
Tue, 8 Nov 2011 22:44:19 +0000 (22:44 +0000)
committerMenno Smits <menno@freshfoo.com>
Tue, 8 Nov 2011 22:44:19 +0000 (22:44 +0000)
imapclient/imapclient.py
imapclient/livetest.py

index d65c688ac98cfdf4c0b51e9306568ffdfabb39b5..6ce84f6379458cde3752ff454d9ec04c1b8d95ca 100644 (file)
@@ -726,10 +726,27 @@ class IMAPClient(object):
     def expunge(self):
         """Remove any messages from the currently selected folder that
         have the ``\\Deleted`` flag set.
+
+        The return value is the server response message
+        followed by a list of expunge responses. For example::
+
+            ('Expunge completed.',
+             [(2, 'EXPUNGE'),
+              (1, 'EXPUNGE'),
+              (0, 'RECENT')])
+
+        In this case, the responses indicate that the message with
+        sequence numbers 2 and 1 where deleted, leaving no recent
+        messages in the folder.
+
+        See `RFC 3501 section 6.4.3
+        <http://tools.ietf.org/html/rfc3501#section-6.4.3>`_ and
+        `RFC 3501 section 7.4.1
+        <http://tools.ietf.org/html/rfc3501#section-7.4.1>`_ for more
+        details.
         """
-        typ, data = self._imap.expunge()
-        self._checkok('expunge', typ, data)
-        #TODO: expunge response
+        tag = self._imap._command('EXPUNGE')
+        return self._consume_until_tagged_response(tag, 'EXPUNGE')
 
     def getacl(self, folder):
         """Returns a list of ``(who, acl)`` tuples describing the
index 7572443102b9c0780be2186a556a0c0340c8a93e..908d7f89f719d2c5c9fe00e56aef8a58beebd7ec 100644 (file)
@@ -527,6 +527,28 @@ def createLiveTestClass(conf, use_uid):
             self.assertTrue(isinstance(resps, list))
             self.assertIn((1, 'EXISTS'), resps)
 
+        def test_expunge(self):
+            self.client.select_folder('INBOX')
+
+            # Test empty mailbox
+            text, resps = self.client.expunge()
+            self.assertTrue(isinstance(text, str))
+            self.assertGreater(len(text), 0)
+            self.assertEqual(resps, [])
+
+            # Now try with a message to expunge
+            self.client.append('INBOX', SIMPLE_MESSAGE, flags=[imapclient.DELETED])
+
+            msg, resps = self.client.expunge()
+
+            self.assertTrue(isinstance(text, str))
+            self.assertGreater(len(text), 0)
+            self.assertTrue(isinstance(resps, list))
+            if not self.is_gmail():
+                # GMail has an auto-expunge feature which might be
+                # on. EXPUNGE won't return anything in this case
+                self.assertIn((1, 'EXPUNGE'), resps)
+
     return LiveTest