#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 08e1520..129de06 100644
--- a/Lib/imaplib.py
+++ b/Lib/imaplib.py
@@ -1147,7 +1147,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)
 
diff --git a/Misc/NEWS b/Misc/NEWS
index 4d40719..0926e7f 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -15,6 +15,9 @@
 Library
 -------
 
+- Bug #1389051: imaplib causes excessive memory fragmentation when reading
+  large messages.
+
 - Bug #1433694: minidom's .normalize() failed to set .nextSibling for
   last child element.