accounts: handle OfflineImapError severity FOLDER
Throw an OfflineImapError when SELECTing a folder is unsuccessful and bail out with a FOLDER serverity. In accounts.py catch all OfflineImapErrors and either just log the error and skip the folder or bubble it up if it's severe. Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de> Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
parent
dd82f213f0
commit
b3a383d151
@ -393,6 +393,13 @@ def syncfolder(accountname, remoterepos, remotefolder, localrepos,
|
|||||||
localrepos.restore_atime()
|
localrepos.restore_atime()
|
||||||
except (KeyboardInterrupt, SystemExit):
|
except (KeyboardInterrupt, SystemExit):
|
||||||
raise
|
raise
|
||||||
|
except OfflineImapError, e:
|
||||||
|
# bubble up severe Errors, skip folder otherwise
|
||||||
|
if e.severity > OfflineImapError.ERROR.FOLDER:
|
||||||
|
raise
|
||||||
|
else:
|
||||||
|
ui.warn("Aborting folder sync '%s' [acc: '%s']\nReason was: %s" %\
|
||||||
|
(localfolder.name, accountname, e.reason))
|
||||||
except:
|
except:
|
||||||
ui.warn("ERROR in syncfolder for %s folder %s: %s" % \
|
ui.warn("ERROR in syncfolder for %s folder %s: %s" % \
|
||||||
(accountname,remotefolder.getvisiblename(),
|
(accountname,remotefolder.getvisiblename(),
|
||||||
|
@ -43,9 +43,13 @@ class IMAPFolder(BaseFolder):
|
|||||||
|
|
||||||
def selectro(self, imapobj):
|
def selectro(self, imapobj):
|
||||||
"""Select this folder when we do not need write access.
|
"""Select this folder when we do not need write access.
|
||||||
|
|
||||||
Prefer SELECT to EXAMINE if we can, since some servers
|
Prefer SELECT to EXAMINE if we can, since some servers
|
||||||
(Courier) do not stabilize UID validity until the folder is
|
(Courier) do not stabilize UID validity until the folder is
|
||||||
selected."""
|
selected.
|
||||||
|
.. todo: Still valid? Needs verification
|
||||||
|
|
||||||
|
:returns: raises :exc:`OfflineImapError` severity FOLDER on error"""
|
||||||
try:
|
try:
|
||||||
imapobj.select(self.getfullname())
|
imapobj.select(self.getfullname())
|
||||||
except imapobj.readonly:
|
except imapobj.readonly:
|
||||||
|
@ -23,8 +23,8 @@ import time
|
|||||||
import subprocess
|
import subprocess
|
||||||
from offlineimap.ui import getglobalui
|
from offlineimap.ui import getglobalui
|
||||||
import threading
|
import threading
|
||||||
|
from offlineimap import OfflineImapError
|
||||||
from offlineimap.imaplib2 import *
|
from offlineimap.imaplib2 import *
|
||||||
|
|
||||||
# Import the symbols we need that aren't exported by default
|
# Import the symbols we need that aren't exported by default
|
||||||
from offlineimap.imaplib2 import IMAP4_PORT, IMAP4_SSL_PORT, InternalDate, Mon2num
|
from offlineimap.imaplib2 import IMAP4_PORT, IMAP4_SSL_PORT, InternalDate, Mon2num
|
||||||
|
|
||||||
@ -43,6 +43,10 @@ class UsefulIMAPMixIn:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def select(self, mailbox='INBOX', readonly=None, force = 0):
|
def select(self, mailbox='INBOX', readonly=None, force = 0):
|
||||||
|
"""Selects a mailbox on the IMAP server
|
||||||
|
|
||||||
|
:returns: 'OK' on success, nothing if the folder was already
|
||||||
|
selected or raises an :exc:`OfflineImapError`"""
|
||||||
if (not force) and self.getselectedfolder() == mailbox \
|
if (not force) and self.getselectedfolder() == mailbox \
|
||||||
and self.is_readonly == readonly:
|
and self.is_readonly == readonly:
|
||||||
# No change; return.
|
# No change; return.
|
||||||
@ -51,7 +55,11 @@ class UsefulIMAPMixIn:
|
|||||||
del self.untagged_responses[:]
|
del self.untagged_responses[:]
|
||||||
result = self.__class__.__bases__[1].select(self, mailbox, readonly)
|
result = self.__class__.__bases__[1].select(self, mailbox, readonly)
|
||||||
if result[0] != 'OK':
|
if result[0] != 'OK':
|
||||||
raise ValueError, "Error from select: %s" % str(result)
|
#in case of error, bail out with OfflineImapError
|
||||||
|
errstr = "Error SELECTing mailbox '%s', server reply:\n%s" %\
|
||||||
|
(mailbox, result)
|
||||||
|
severity = OfflineImapError.ERROR.FOLDER
|
||||||
|
raise OfflineImapError(errstr, severity)
|
||||||
if self.getstate() == 'SELECTED':
|
if self.getstate() == 'SELECTED':
|
||||||
self.selectedfolder = mailbox
|
self.selectedfolder = mailbox
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user