diff --git a/offlineimap/imapserver.py b/offlineimap/imapserver.py index 96e8d23..147e84b 100644 --- a/offlineimap/imapserver.py +++ b/offlineimap/imapserver.py @@ -405,10 +405,18 @@ class IdleThread(object): if self.event.isSet(): return self.needsync = False + self.imapaborted = False def callback(args): - if not self.event.isSet(): - self.needsync = True - self.event.set() + result, cb_arg, exc_data = args + if exc_data is None: + if not self.event.isSet(): + self.needsync = True + self.event.set() + else: + # We got an "abort" signal. + self.imapaborted = True + self.stop() + imapobj = self.parent.acquireconnection() imapobj.select(self.folder) if "IDLE" in imapobj.capabilities: @@ -422,7 +430,11 @@ class IdleThread(object): imapobj.noop() self.event.wait() if self.event.isSet(): - imapobj.noop() + # Can't NOOP on a bad connection. + if not self.imapaborted: + imapobj.noop() + # We don't do event.clear() so that we'll fall out + # of the loop next time around. self.parent.releaseconnection(imapobj) if self.needsync: self.event.clear()