diff --git a/Changelog.draft.rst b/Changelog.draft.rst index edc8254..c5bd8ae 100644 --- a/Changelog.draft.rst +++ b/Changelog.draft.rst @@ -33,6 +33,7 @@ Changes Bug Fixes --------- +* Fix hang because of infinite loop reading EOF. * Allow SSL connections to send keep-alive messages. * Fix regression (UIBase is no more). * Make profiling mode really enforce single-threading diff --git a/offlineimap/imaplibutil.py b/offlineimap/imaplibutil.py index 6752328..b03e80b 100644 --- a/offlineimap/imaplibutil.py +++ b/offlineimap/imaplibutil.py @@ -47,7 +47,10 @@ class IMAP4_Tunnel(IMAP4): def read(self, size): retval = '' while len(retval) < size: - retval += self.infd.read(size - len(retval)) + buf = self.infd.read(size - len(retval)) + if not buf: + break + retval += buf return retval def readline(self): @@ -204,6 +207,8 @@ class WrappedIMAP4_SSL(IMAP4_SSL): read = 0 while read < n: data = self._read_upto (n-read) + if not data: + break read += len(data) chunks.append(data) @@ -216,6 +221,8 @@ class WrappedIMAP4_SSL(IMAP4_SSL): retval = '' while 1: linebuf = self._read_upto(1024) + if not linebuf: + return retval nlindex = linebuf.find("\n") if nlindex != -1: retval += linebuf[:nlindex + 1] diff --git a/offlineimap/imapserver.py b/offlineimap/imapserver.py index 14789bc..7ead9a4 100644 --- a/offlineimap/imapserver.py +++ b/offlineimap/imapserver.py @@ -70,6 +70,8 @@ class UsefulIMAP4(UsefulIMAPMixIn, imaplibutil.WrappedIMAP4): io = StringIO() while read < size: data = imaplib.IMAP4.read (self, min(size-read, 65536)) + if not data: + break read += len(data) io.write(data) return io.getvalue()