[PATCH 6/6] Handle abort messages from GMail

Ethan Glasser-Camp ethan at betacantrips.com
Wed May 18 13:48:57 BST 2011


From: Tom Lawton <tlawton at gmx.de>

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

Signed-off-by: Tom Lawton <tlawton at gmx.de>
Signed-off-by: Ethan Glasser-Camp <ethan at betacantrips.com>
---
 offlineimap/imapserver.py |   19 +++++++++++++++----
 1 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/offlineimap/imapserver.py b/offlineimap/imapserver.py
index 5f697b7..b24f355 100644
--- a/offlineimap/imapserver.py
+++ b/offlineimap/imapserver.py
@@ -406,10 +406,17 @@ 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()
+                if args[2] 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:
@@ -418,7 +425,11 @@ class IdleThread(object):
                 imapobj.noop()
             self.event.wait()
             if self.event.isSet():
-                imapobj.noop()
+                if not self.imapaborted:
+                    # Can't NOOP on a bad connection.
+                    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()
-- 
1.7.4.1





More information about the OfflineIMAP-project mailing list