Handle abort messages from GMail

Without this patch, we try to NOOP on a bad connection and crash messily.

Signed-off-by: Tom Lawton <tlawton@gmx.de>
Signed-off-by: Ethan Glasser-Camp <ethan@betacantrips.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
Tom Lawton 2011-05-19 15:02:31 -04:00 committed by Nicolas Sebrecht
parent 2cc2ead503
commit da36c5c1e7

View File

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