Issue 5949: fixed IMAP4_SSL hang when the IMAP server response is
missing proper end-of-line termination. Patch and tests by
Scott Dial. The new tests include a test harness which will
make it easier to add additional tests.
diff --git a/Lib/imaplib.py b/Lib/imaplib.py
index f13350e..5a45845 100644
--- a/Lib/imaplib.py
+++ b/Lib/imaplib.py
@@ -1001,6 +1001,8 @@
raise self.abort('socket error: EOF')
# Protocol mandates all lines terminated by CRLF
+ if not line.endswith('\r\n'):
+ raise self.abort('socket error: unterminated line')
line = line[:-2]
if __debug__:
@@ -1167,7 +1169,7 @@
while 1:
char = self.sslobj.read(1)
line.append(char)
- if char == "\n": return ''.join(line)
+ if char in ("\n", ""): return ''.join(line)
def send(self, data):