Merged revisions 76726-76727 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

The merge adds a test with an invalid rather than a missing line end, since
the py3K code passed the original issue 5949 test.  New test also by Scott
Dial.

........
  r76726 | r.david.murray | 2009-12-09 10:15:31 -0500 (Wed, 09 Dec 2009) | 6 lines

  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.
........
  r76727 | r.david.murray | 2009-12-09 11:41:39 -0500 (Wed, 09 Dec 2009) | 2 lines

  Skip new imaplib SSL tests if ssl is not available.
........
diff --git a/Lib/imaplib.py b/Lib/imaplib.py
index df35cb1..f803a5c 100644
--- a/Lib/imaplib.py
+++ b/Lib/imaplib.py
@@ -1023,6 +1023,8 @@
             raise self.abort('socket error: EOF')
 
         # Protocol mandates all lines terminated by CRLF
+        if not line.endswith(b'\r\n'):
+            raise self.abort('socket error: unterminated line')
 
         line = line[:-2]
         if __debug__: