Skip to content
Browse files

fix an issue in mod_imap.py, modified read(

  • Loading branch information...
1 parent 57907d4 commit d3f1596ddc866398d695b7d963a070db023f5e98 @gaubert committed Mar 30, 2012
Showing with 13 additions and 9 deletions.
  1. +13 −9 src/gmv/mod_imap.py
View
22 src/gmv/mod_imap.py
@@ -48,18 +48,21 @@ def activate_compression(self):
self.decompressor = zlib.decompressobj(-15)
self.compressor = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, -15)
-
+ MAX_READ = 16384
def read(self, size):
"""Read 'size' bytes from remote."""
# sslobj.read() sometimes returns < size bytes
- chunks = []
- read = 0
- while read < size:
- data = self._intern_read(min(size-read, 16384))
- read += len(data)
- chunks.append(data)
+ if size <= self.MAX_READ:
+ return self._intern_read(size)
+ else:
+ chunks = ""
+ read = 0
+ while read < size:
+ data = self._intern_read(min(size-read, self.MAX_READ))
+ read += len(data)
+ chunks += data
- return ''.join(chunks)
+ return chunks
def _intern_read(self, size):
"""
@@ -72,7 +75,8 @@ def _intern_read(self, size):
if self.decompressor.unconsumed_tail:
data = self.decompressor.unconsumed_tail
else:
- data = self.sslobj.read(8192)
+ #data = self.sslobj.read(8192)
+ data = self.sslobj.read(size)
return self.decompressor.decompress(data, size)

0 comments on commit d3f1596

Please sign in to comment.
Something went wrong with that request. Please try again.