From 0c09293143630e8860e741d9e990993b5454a0ef Mon Sep 17 00:00:00 2001 From: Piers Lauder Date: Sun, 23 Jun 2002 10:47:13 +0000 Subject: [PATCH] Fix IMAP4_SSL read and send methods to take account of short data --- Lib/imaplib.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/Lib/imaplib.py b/Lib/imaplib.py index 2a7630b24d0..7afd66535af 100644 --- a/Lib/imaplib.py +++ b/Lib/imaplib.py @@ -18,7 +18,7 @@ Public functions: Internaldate2tuple # IMAP4_SSL contributed by Tino Lange March 2002. # GET/SETQUOTA contributed by Andreas Zeidler 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):