#1389051: IMAP module tries to read entire message in one chunk.  Patch by Fredrik Lundh.
diff --git a/Lib/imaplib.py b/Lib/imaplib.py
index c05abb4..7807e8f 100644
--- a/Lib/imaplib.py
+++ b/Lib/imaplib.py
@@ -1156,7 +1156,7 @@
             chunks = []
             read = 0
             while read < size:
-                data = self.sslobj.read(size-read)
+                data = self.sslobj.read(min(size-read, 16384))
                 read += len(data)
                 chunks.append(data)