[PATCH 2/2] Update IMAP4_Tunnel.read() and IMAP4_Tunnel.send() for imaplib2

Ethan Glasser-Camp ethan at betacantrips.com
Mon Apr 11 11:14:30 BST 2011


---
 offlineimap/imaplibutil.py |   27 +++++++++++++++++----------
 1 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/offlineimap/imaplibutil.py b/offlineimap/imaplibutil.py
index da0438c..fe692e3 100644
--- a/offlineimap/imaplibutil.py
+++ b/offlineimap/imaplibutil.py
@@ -79,19 +79,26 @@ class IMAP4_Tunnel(UsefulIMAPMixIn, IMAP4):
         self.read_fd = self.infd.fileno()
 
     def read(self, size):
-        retval = ''
-        while len(retval) < size:
-            buf = self.infd.read(size - len(retval))
-            if not buf:
-                break
-            retval += buf
-        return retval
+        """data = read(size)
+        Read at most 'size' bytes from remote."""
+
+        if self.decompressor is None:
+            return self.infd.read(size)
+
+        if self.decompressor.unconsumed_tail:
+            data = self.decompressor.unconsumed_tail
+        else:
+            data = self.infd.read(8192)
 
-    def readline(self):
-        return self.infd.readline()
+        return self.decompressor.decompress(data, size)
 
     def send(self, data):
-        self.outfd.write(data)
+        if self.compressor is not None:
+            data = self.compressor.compress(data)
+            data += self.compressor.flush(zlib.Z_SYNC_FLUSH)
+
+        self.outfd.sendall(data)
+
 
     def shutdown(self):
         self.infd.close()
-- 
1.7.1





More information about the OfflineIMAP-project mailing list