1
0
mirror of https://github.com/OfflineIMAP/offlineimap.git synced 2024-07-08 09:20:52 +02:00

Merge branch 'ss/protect-select-for-idle' into next

This commit is contained in:
Nicolas Sebrecht 2011-09-06 19:01:11 +02:00
commit ff9b941f42
3 changed files with 27 additions and 7 deletions

View File

@ -5,11 +5,12 @@ class OfflineImapError(Exception):
"""Severity level of an Exception """Severity level of an Exception
* **MESSAGE**: Abort the current message, but continue with folder * **MESSAGE**: Abort the current message, but continue with folder
* **FOLDER_RETRY**: Error syncing folder, but do retry
* **FOLDER**: Abort folder sync, but continue with next folder * **FOLDER**: Abort folder sync, but continue with next folder
* **REPO**: Abort repository sync, continue with next account * **REPO**: Abort repository sync, continue with next account
* **CRITICAL**: Immediately exit offlineimap * **CRITICAL**: Immediately exit offlineimap
""" """
MESSAGE, FOLDER, REPO, CRITICAL = 0, 10, 20, 30 MESSAGE, FOLDER_RETRY, FOLDER, REPO, CRITICAL = 0, 10, 15, 20, 30
def __init__(self, reason, severity, errcode=None): def __init__(self, reason, severity, errcode=None):
""" """

View File

@ -49,7 +49,14 @@ class UsefulIMAPMixIn:
return return
# Wipe out all old responses, to maintain semantics with old imaplib2 # Wipe out all old responses, to maintain semantics with old imaplib2
del self.untagged_responses[:] del self.untagged_responses[:]
try:
result = self.__class__.__bases__[1].select(self, mailbox, readonly) result = self.__class__.__bases__[1].select(self, mailbox, readonly)
except self.abort, e:
# self.abort is raised when we are supposed to retry
errstr = "Server '%s' closed connection, error on SELECT '%s'. Ser"\
"ver said: %s" % (self.host, mailbox, e.args[0])
severity = OfflineImapError.ERROR.FOLDER_RETRY
raise OfflineImapError(errstr, severity)
if result[0] != 'OK': if result[0] != 'OK':
#in case of error, bail out with OfflineImapError #in case of error, bail out with OfflineImapError
errstr = "Error SELECTing mailbox '%s', server reply:\n%s" %\ errstr = "Error SELECTing mailbox '%s', server reply:\n%s" %\

View File

@ -26,7 +26,7 @@ import socket
import base64 import base64
import time import time
import errno import errno
from sys import exc_info
from socket import gaierror from socket import gaierror
try: try:
from ssl import SSLError, cert_time_to_seconds from ssl import SSLError, cert_time_to_seconds
@ -456,6 +456,7 @@ class IdleThread(object):
self.parent = parent self.parent = parent
self.folder = folder self.folder = folder
self.event = Event() self.event = Event()
self.ui = getglobalui()
if folder is None: if folder is None:
self.thread = Thread(target=self.noop) self.thread = Thread(target=self.noop)
else: else:
@ -505,13 +506,24 @@ class IdleThread(object):
self.imapaborted = True self.imapaborted = True
self.stop() self.stop()
success = False # successfully selected FOLDER?
while not success:
imapobj = self.parent.acquireconnection() imapobj = self.parent.acquireconnection()
try:
imapobj.select(self.folder) imapobj.select(self.folder)
except OfflineImapError, e:
if e.severity == OfflineImapError.ERROR.FOLDER_RETRY:
# Connection closed, release connection and retry
self.ui.error(e, exc_info()[2])
self.parent.releaseconnection(imapobj)
else:
raise e
else:
success = True
if "IDLE" in imapobj.capabilities: if "IDLE" in imapobj.capabilities:
imapobj.idle(callback=callback) imapobj.idle(callback=callback)
else: else:
ui = getglobalui() self.ui.warn("IMAP IDLE not supported on connection to %s."
ui.warn("IMAP IDLE not supported on connection to %s."
"Falling back to old behavior: sleeping until next" "Falling back to old behavior: sleeping until next"
"refresh cycle." "refresh cycle."
%(imapobj.identifier,)) %(imapobj.identifier,))