diff options
author | Piers Lauder <piers@cs.su.oz.au> | 2002-06-23 10:47:13 (GMT) |
---|---|---|
committer | Piers Lauder <piers@cs.su.oz.au> | 2002-06-23 10:47:13 (GMT) |
commit | 0c09293143630e8860e741d9e990993b5454a0ef (patch) | |
tree | 04c82cb299abd9d925900bba11123e091dcd07ad | |
parent | 723f94bd6612338eec9846750e8f5edf57170bc1 (diff) | |
download | cpython-0c09293143630e8860e741d9e990993b5454a0ef.zip cpython-0c09293143630e8860e741d9e990993b5454a0ef.tar.gz cpython-0c09293143630e8860e741d9e990993b5454a0ef.tar.bz2 |
Fix IMAP4_SSL read and send methods to take account of short data
-rw-r--r-- | Lib/imaplib.py | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/Lib/imaplib.py b/Lib/imaplib.py index 2a7630b..7afd665 100644 --- a/Lib/imaplib.py +++ b/Lib/imaplib.py @@ -18,7 +18,7 @@ Public functions: Internaldate2tuple # IMAP4_SSL contributed by Tino Lange <Tino.Lange@isg.de> March 2002. # GET/SETQUOTA contributed by Andreas Zeidler <az@kreativkombinat.de> June 2002. -__version__ = "2.52" +__version__ = "2.53" import binascii, re, socket, time, random, sys @@ -1056,11 +1056,17 @@ class IMAP4_SSL(IMAP4): def read(self, size): """Read 'size' bytes from remote.""" - return self.sslobj.read(size) + # sslobj.read() sometimes returns < size bytes + data = self.sslobj.read(size) + while len(data) < size: + data += self.sslobj.read(len(data)-size) + + return data def readline(self): """Read line from remote.""" + # NB: socket.ssl needs a "readline" method, or perhaps a "makefile" method. line = "" while 1: char = self.sslobj.read(1) @@ -1070,7 +1076,14 @@ class IMAP4_SSL(IMAP4): def send(self, data): """Send data to remote.""" - self.sslobj.write(data) + # NB: socket.ssl needs a "sendall" method to match socket objects. + bytes = len(data) + while bytes > 0: + sent = self.sslobj.write(data) + if sent == bytes: + break # avoid copy + data = data[sent:] + bytes = bytes - sent def shutdown(self): |