correctly reraise errors with six
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
parent
69c0080323
commit
7945e10a76
@ -16,9 +16,8 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
from sys import exc_info
|
|
||||||
|
|
||||||
import six
|
import six
|
||||||
|
from sys import exc_info
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from ConfigParser import SafeConfigParser, Error
|
from ConfigParser import SafeConfigParser, Error
|
||||||
@ -77,8 +76,10 @@ class CustomConfigParser(SafeConfigParser):
|
|||||||
val = self.get(section, option).strip()
|
val = self.get(section, option).strip()
|
||||||
return re.split(separator_re, val)
|
return re.split(separator_re, val)
|
||||||
except re.error as e:
|
except re.error as e:
|
||||||
six.reraise(Error("Bad split regexp '%s': %s" % \
|
six.reraise(Error,
|
||||||
(separator_re, e)), None, exc_info()[2])
|
Error("Bad split regexp '%s': %s"%
|
||||||
|
(separator_re, e)),
|
||||||
|
exc_info()[2])
|
||||||
|
|
||||||
def getdefaultlist(self, section, option, default, separator_re):
|
def getdefaultlist(self, section, option, default, separator_re):
|
||||||
"""Same as getlist, but returns the value of `default`
|
"""Same as getlist, but returns the value of `default`
|
||||||
|
@ -228,9 +228,12 @@ class SyncableAccount(Account):
|
|||||||
pass
|
pass
|
||||||
except IOError:
|
except IOError:
|
||||||
self._lockfd.close()
|
self._lockfd.close()
|
||||||
six.reraise(OfflineImapError("Could not lock account %s. Is another "
|
six.reraise(OfflineImapError,
|
||||||
"instance using this account?"% self,
|
OfflineImapError(
|
||||||
OfflineImapError.ERROR.REPO), None, exc_info()[2])
|
"Could not lock account %s. Is another "
|
||||||
|
"instance using this account?"% self,
|
||||||
|
OfflineImapError.ERROR.REPO),
|
||||||
|
exc_info()[2])
|
||||||
|
|
||||||
def _unlock(self):
|
def _unlock(self):
|
||||||
"""Unlock the account, deleting the lock file"""
|
"""Unlock the account, deleting the lock file"""
|
||||||
@ -552,10 +555,12 @@ def syncfolder(account, remotefolder, quick):
|
|||||||
localstart = localfolder.getstartdate()
|
localstart = localfolder.getstartdate()
|
||||||
remotestart = remotefolder.getstartdate()
|
remotestart = remotefolder.getstartdate()
|
||||||
if (maxage != None) + (localstart != None) + (remotestart != None) > 1:
|
if (maxage != None) + (localstart != None) + (remotestart != None) > 1:
|
||||||
six.reraise(OfflineImapError("You can set at most one of the "
|
six.reraise(OfflineImapError,
|
||||||
"following: maxage, startdate (for the local folder), "
|
OfflineImapError("You can set at most one of the "
|
||||||
"startdate (for the remote folder)",
|
"following: maxage, startdate (for the local "
|
||||||
OfflineImapError.ERROR.REPO), None, exc_info()[2])
|
"folder), startdate (for the remote folder)",
|
||||||
|
OfflineImapError.ERROR.REPO),
|
||||||
|
exc_info()[2])
|
||||||
if (maxage != None or localstart or remotestart) and quick:
|
if (maxage != None or localstart or remotestart) and quick:
|
||||||
# IMAP quickchanged isn't compatible with options that
|
# IMAP quickchanged isn't compatible with options that
|
||||||
# involve restricting the messagelist, since the "quick"
|
# involve restricting the messagelist, since the "quick"
|
||||||
|
@ -139,10 +139,14 @@ class GmailFolder(IMAPFolder):
|
|||||||
res_type, response = imapobj.fetch("'%s'"% msgsToFetch,
|
res_type, response = imapobj.fetch("'%s'"% msgsToFetch,
|
||||||
'(FLAGS X-GM-LABELS UID)')
|
'(FLAGS X-GM-LABELS UID)')
|
||||||
if res_type != 'OK':
|
if res_type != 'OK':
|
||||||
six.reraise(OfflineImapError("FETCHING UIDs in folder [%s]%s failed. " % \
|
six.reraise(OfflineImapError,
|
||||||
(self.getrepository(), self) + \
|
OfflineImapError(
|
||||||
"Server responded '[%s] %s'" % \
|
"FETCHING UIDs in folder [%s]%s failed. "%
|
||||||
(res_type, response), OfflineImapError.ERROR.FOLDER), None, exc_info()[2])
|
(self.getrepository(), self) +
|
||||||
|
"Server responded '[%s] %s'"%
|
||||||
|
(res_type, response),
|
||||||
|
OfflineImapError.ERROR.FOLDER),
|
||||||
|
exc_info()[2])
|
||||||
finally:
|
finally:
|
||||||
self.imapserver.releaseconnection(imapobj)
|
self.imapserver.releaseconnection(imapobj)
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# Maildir folder support with labels
|
# Maildir folder support with labels
|
||||||
# Copyright (C) 2002 - 2016 John Goerzen & contributors
|
# Copyright (C) 2002-2016 John Goerzen & contributors.
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
@ -176,8 +176,11 @@ class GmailMaildirFolder(MaildirFolder):
|
|||||||
try:
|
try:
|
||||||
os.rename(tmppath, filepath)
|
os.rename(tmppath, filepath)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
six.reraise(OfflineImapError("Can't rename file '%s' to '%s': %s" % \
|
six.reraise(OfflineImapError,
|
||||||
(tmppath, filepath, e[1]), OfflineImapError.ERROR.FOLDER), None, exc_info()[2])
|
OfflineImapError("Can't rename file '%s' to '%s': %s"%
|
||||||
|
(tmppath, filepath, e[1]),
|
||||||
|
OfflineImapError.ERROR.FOLDER),
|
||||||
|
exc_info()[2])
|
||||||
|
|
||||||
# if utime_from_header=true, we don't want to change the mtime.
|
# if utime_from_header=true, we don't want to change the mtime.
|
||||||
if self.utime_from_header and mtime:
|
if self.utime_from_header and mtime:
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# IMAP folder support
|
# IMAP folder support
|
||||||
# Copyright (C) 2002-2016 John Goerzen & contributors
|
# Copyright (C) 2002-2016 John Goerzen & contributors.
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
@ -84,8 +84,11 @@ class IMAPFolder(BaseFolder):
|
|||||||
def getmaxage(self):
|
def getmaxage(self):
|
||||||
if self.config.getdefault("Account %s"%
|
if self.config.getdefault("Account %s"%
|
||||||
self.accountname, "maxage", None):
|
self.accountname, "maxage", None):
|
||||||
six.reraise(OfflineImapError("maxage is not supported on IMAP-IMAP sync",
|
six.reraise(OfflineImapError,
|
||||||
OfflineImapError.ERROR.REPO), None, exc_info()[2])
|
OfflineImapError(
|
||||||
|
"maxage is not supported on IMAP-IMAP sync",
|
||||||
|
OfflineImapError.ERROR.REPO),
|
||||||
|
exc_info()[2])
|
||||||
|
|
||||||
# Interface from BaseFolder
|
# Interface from BaseFolder
|
||||||
def getinstancelimitnamespace(self):
|
def getinstancelimitnamespace(self):
|
||||||
@ -613,11 +616,13 @@ class IMAPFolder(BaseFolder):
|
|||||||
self.imapserver.releaseconnection(imapobj, True)
|
self.imapserver.releaseconnection(imapobj, True)
|
||||||
imapobj = self.imapserver.acquireconnection()
|
imapobj = self.imapserver.acquireconnection()
|
||||||
if not retry_left:
|
if not retry_left:
|
||||||
six.reraise(OfflineImapError("Saving msg (%s) in folder '%s', "
|
six.reraise(OfflineImapError,
|
||||||
"repository '%s' failed (abort). Server responded: %s\n"
|
OfflineImapError("Saving msg (%s) in folder '%s', "
|
||||||
"Message content was: %s"%
|
"repository '%s' failed (abort). Server responded: %s\n"
|
||||||
(msg_id, self, self.getrepository(), str(e), dbg_output),
|
"Message content was: %s"%
|
||||||
OfflineImapError.ERROR.MESSAGE), None, exc_info()[2])
|
(msg_id, self, self.getrepository(), str(e), dbg_output),
|
||||||
|
OfflineImapError.ERROR.MESSAGE),
|
||||||
|
exc_info()[2])
|
||||||
# XXX: is this still needed?
|
# XXX: is this still needed?
|
||||||
self.ui.error(e, exc_info()[2])
|
self.ui.error(e, exc_info()[2])
|
||||||
except imapobj.error as e: # APPEND failed
|
except imapobj.error as e: # APPEND failed
|
||||||
@ -626,10 +631,12 @@ class IMAPFolder(BaseFolder):
|
|||||||
# drop conn, it might be bad.
|
# drop conn, it might be bad.
|
||||||
self.imapserver.releaseconnection(imapobj, True)
|
self.imapserver.releaseconnection(imapobj, True)
|
||||||
imapobj = None
|
imapobj = None
|
||||||
six.reraise(OfflineImapError("Saving msg (%s) folder '%s', repo '%s'"
|
six.reraise(OfflineImapError,
|
||||||
"failed (error). Server responded: %s\nMessage content was: "
|
OfflineImapError("Saving msg (%s) folder '%s', repo '%s'"
|
||||||
"%s" % (msg_id, self, self.getrepository(), str(e), dbg_output),
|
"failed (error). Server responded: %s\nMessage content was: "
|
||||||
OfflineImapError.ERROR.MESSAGE), None, exc_info()[2])
|
"%s"% (msg_id, self, self.getrepository(), str(e), dbg_output),
|
||||||
|
OfflineImapError.ERROR.MESSAGE),
|
||||||
|
exc_info()[2])
|
||||||
# Checkpoint. Let it write out stuff, etc. Eg searches for
|
# Checkpoint. Let it write out stuff, etc. Eg searches for
|
||||||
# just uploaded messages won't work if we don't do this.
|
# just uploaded messages won't work if we don't do this.
|
||||||
(typ,dat) = imapobj.check()
|
(typ,dat) = imapobj.check()
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# Local status cache virtual folder
|
# Local status cache virtual folder
|
||||||
# Copyright (C) 2002-2016 John Goerzen & contributors
|
# Copyright (C) 2002-2016 John Goerzen & contributors.
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
@ -75,7 +75,7 @@ class LocalStatusFolder(BaseFolder):
|
|||||||
errstr = ("Corrupt line '%s' in cache file '%s'"%
|
errstr = ("Corrupt line '%s' in cache file '%s'"%
|
||||||
(line, self.filename))
|
(line, self.filename))
|
||||||
self.ui.warn(errstr)
|
self.ui.warn(errstr)
|
||||||
six.reraise(ValueError(errstr), None, exc_info()[2])
|
six.reraise(ValueError, ValueError(errstr), exc_info()[2])
|
||||||
self.messagelist[uid] = self.msglist_item_initializer(uid)
|
self.messagelist[uid] = self.msglist_item_initializer(uid)
|
||||||
self.messagelist[uid]['flags'] = flags
|
self.messagelist[uid]['flags'] = flags
|
||||||
|
|
||||||
@ -98,7 +98,7 @@ class LocalStatusFolder(BaseFolder):
|
|||||||
errstr = "Corrupt line '%s' in cache file '%s'"% \
|
errstr = "Corrupt line '%s' in cache file '%s'"% \
|
||||||
(line, self.filename)
|
(line, self.filename)
|
||||||
self.ui.warn(errstr)
|
self.ui.warn(errstr)
|
||||||
six.reraise(ValueError(errstr), None, exc_info()[2])
|
six.reraise(ValueError, ValueError(errstr), exc_info()[2])
|
||||||
self.messagelist[uid] = self.msglist_item_initializer(uid)
|
self.messagelist[uid] = self.msglist_item_initializer(uid)
|
||||||
self.messagelist[uid]['flags'] = flags
|
self.messagelist[uid]['flags'] = flags
|
||||||
self.messagelist[uid]['mtime'] = mtime
|
self.messagelist[uid]['mtime'] = mtime
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# Local status cache virtual folder: SQLite backend
|
# Local status cache virtual folder: SQLite backend
|
||||||
# Copyright (C) 2009-2016 Stewart Smith and contributors
|
# Copyright (C) 2009-2016 Stewart Smith and contributors.
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
@ -67,10 +67,13 @@ class LocalStatusSQLiteFolder(BaseFolder):
|
|||||||
self.connection = sqlite.connect(self.filename, check_same_thread=False)
|
self.connection = sqlite.connect(self.filename, check_same_thread=False)
|
||||||
except sqlite.OperationalError as e:
|
except sqlite.OperationalError as e:
|
||||||
# Operation had failed.
|
# Operation had failed.
|
||||||
six.reraise(UserWarning("cannot open database file '%s': %s.\nYou might "
|
six.reraise(UserWarning,
|
||||||
"want to check the rights to that file and if it cleanly opens "
|
UserWarning(
|
||||||
"with the 'sqlite<3>' command."%
|
"cannot open database file '%s': %s.\nYou might "
|
||||||
(self.filename, e)), None, exc_info()[2])
|
"want to check the rights to that file and if it "
|
||||||
|
"cleanly opens with the 'sqlite<3>' command."%
|
||||||
|
(self.filename, e)),
|
||||||
|
exc_info()[2])
|
||||||
|
|
||||||
# Make sure sqlite is in multithreading SERIALIZE mode.
|
# Make sure sqlite is in multithreading SERIALIZE mode.
|
||||||
assert sqlite.threadsafety == 1, 'Your sqlite is not multithreading safe.'
|
assert sqlite.threadsafety == 1, 'Your sqlite is not multithreading safe.'
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# Maildir folder support
|
# Maildir folder support
|
||||||
# Copyright (C) 2002-2016 John Goerzen & contributors
|
# Copyright (C) 2002-2016 John Goerzen & contributors.
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
@ -22,8 +22,6 @@ import os
|
|||||||
import six
|
import six
|
||||||
from sys import exc_info
|
from sys import exc_info
|
||||||
from threading import Lock
|
from threading import Lock
|
||||||
from .Base import BaseFolder
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from hashlib import md5
|
from hashlib import md5
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@ -34,6 +32,7 @@ except NameError:
|
|||||||
from sets import Set as set
|
from sets import Set as set
|
||||||
|
|
||||||
from offlineimap import OfflineImapError, emailutil
|
from offlineimap import OfflineImapError, emailutil
|
||||||
|
from .Base import BaseFolder
|
||||||
|
|
||||||
# Find the UID in a message filename
|
# Find the UID in a message filename
|
||||||
re_uidmatch = re.compile(',U=(\d+)')
|
re_uidmatch = re.compile(',U=(\d+)')
|
||||||
@ -318,8 +317,11 @@ class MaildirFolder(BaseFolder):
|
|||||||
time.sleep(0.23)
|
time.sleep(0.23)
|
||||||
continue
|
continue
|
||||||
severity = OfflineImapError.ERROR.MESSAGE
|
severity = OfflineImapError.ERROR.MESSAGE
|
||||||
six.reraise(OfflineImapError("Unique filename %s already exists."%
|
six.reraise(OfflineImapError,
|
||||||
filename, severity), None, exc_info()[2])
|
OfflineImapError(
|
||||||
|
"Unique filename %s already exists."%
|
||||||
|
filename, severity),
|
||||||
|
exc_info()[2])
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
@ -439,9 +441,12 @@ class MaildirFolder(BaseFolder):
|
|||||||
os.rename(os.path.join(self.getfullname(), oldfilename),
|
os.rename(os.path.join(self.getfullname(), oldfilename),
|
||||||
os.path.join(self.getfullname(), newfilename))
|
os.path.join(self.getfullname(), newfilename))
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
six.reraise(OfflineImapError("Can't rename file '%s' to '%s': %s" % (
|
six.reraise(OfflineImapError,
|
||||||
oldfilename, newfilename, e[1]),
|
OfflineImapError(
|
||||||
OfflineImapError.ERROR.FOLDER), None, exc_info()[2])
|
"Can't rename file '%s' to '%s': %s"%
|
||||||
|
(oldfilename, newfilename, e[1]),
|
||||||
|
OfflineImapError.ERROR.FOLDER),
|
||||||
|
exc_info()[2])
|
||||||
|
|
||||||
self.messagelist[uid]['flags'] = flags
|
self.messagelist[uid]['flags'] = flags
|
||||||
self.messagelist[uid]['filename'] = newfilename
|
self.messagelist[uid]['filename'] = newfilename
|
||||||
@ -519,10 +524,12 @@ class MaildirFolder(BaseFolder):
|
|||||||
try:
|
try:
|
||||||
os.rename(filename, newfilename)
|
os.rename(filename, newfilename)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
six.reraise(OfflineImapError(
|
six.reraise(OfflineImapError,
|
||||||
"Can't rename file '%s' to '%s': %s" % (
|
OfflineImapError(
|
||||||
filename, newfilename, e[1]),
|
"Can't rename file '%s' to '%s': %s"%
|
||||||
OfflineImapError.ERROR.FOLDER), None, exc_info()[2])
|
(filename, newfilename, e[1]),
|
||||||
|
OfflineImapError.ERROR.FOLDER),
|
||||||
|
exc_info()[2])
|
||||||
elif match.group(1) != self._foldermd5:
|
elif match.group(1) != self._foldermd5:
|
||||||
self.ui.warn(("Inconsistent FMD5 for file `%s':"
|
self.ui.warn(("Inconsistent FMD5 for file `%s':"
|
||||||
" Neither `%s' nor `%s' found")
|
" Neither `%s' nor `%s' found")
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# Base folder support
|
# Base folder support
|
||||||
# Copyright (C) 2002-2015 John Goerzen & contributors
|
# Copyright (C) 2002-2016 John Goerzen & contributors.
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
@ -15,13 +15,14 @@
|
|||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
from sys import exc_info
|
import six
|
||||||
from threading import Lock
|
from threading import Lock
|
||||||
from offlineimap import OfflineImapError
|
from sys import exc_info
|
||||||
from .IMAP import IMAPFolder
|
|
||||||
import os.path
|
import os.path
|
||||||
|
|
||||||
import six
|
from offlineimap import OfflineImapError
|
||||||
|
from .IMAP import IMAPFolder
|
||||||
|
|
||||||
|
|
||||||
class MappedIMAPFolder(IMAPFolder):
|
class MappedIMAPFolder(IMAPFolder):
|
||||||
"""IMAP class to map between Folder() instances where both side assign a uid
|
"""IMAP class to map between Folder() instances where both side assign a uid
|
||||||
@ -63,8 +64,11 @@ class MappedIMAPFolder(IMAPFolder):
|
|||||||
try:
|
try:
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
except ValueError:
|
except ValueError:
|
||||||
six.reraise(Exception("Corrupt line '%s' in UID mapping file '%s'"%
|
six.reraise(Exception,
|
||||||
(line, mapfilename)), None, exc_info()[2])
|
Exception(
|
||||||
|
"Corrupt line '%s' in UID mapping file '%s'"%
|
||||||
|
(line, mapfilename)),
|
||||||
|
exc_info()[2])
|
||||||
(str1, str2) = line.split(':')
|
(str1, str2) = line.split(':')
|
||||||
loc = int(str1)
|
loc = int(str1)
|
||||||
rem = int(str2)
|
rem = int(str2)
|
||||||
@ -90,10 +94,14 @@ class MappedIMAPFolder(IMAPFolder):
|
|||||||
try:
|
try:
|
||||||
return [mapping[x] for x in items]
|
return [mapping[x] for x in items]
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
six.reraise(OfflineImapError("Could not find UID for msg '{0}' (f:'{1}'."
|
six.reraise(OfflineImapError,
|
||||||
" This is usually a bad thing and should be reported on the ma"
|
OfflineImapError(
|
||||||
"iling list.".format(e.args[0], self),
|
"Could not find UID for msg '{0}' (f:'{1}'."
|
||||||
OfflineImapError.ERROR.MESSAGE), None, exc_info()[2])
|
" This is usually a bad thing and should be "
|
||||||
|
"reported on the mailing list.".format(
|
||||||
|
e.args[0], self),
|
||||||
|
OfflineImapError.ERROR.MESSAGE),
|
||||||
|
exc_info()[2])
|
||||||
|
|
||||||
# Interface from BaseFolder
|
# Interface from BaseFolder
|
||||||
def cachemessagelist(self, min_date=None, min_uid=None):
|
def cachemessagelist(self, min_date=None, min_uid=None):
|
||||||
|
@ -18,16 +18,16 @@ import os
|
|||||||
import fcntl
|
import fcntl
|
||||||
import time
|
import time
|
||||||
import subprocess
|
import subprocess
|
||||||
from sys import exc_info
|
|
||||||
import threading
|
import threading
|
||||||
from hashlib import sha1
|
|
||||||
import socket
|
import socket
|
||||||
import errno
|
import errno
|
||||||
import zlib
|
import zlib
|
||||||
import six
|
import six
|
||||||
|
from sys import exc_info
|
||||||
|
from hashlib import sha1
|
||||||
|
|
||||||
from offlineimap.ui import getglobalui
|
|
||||||
from offlineimap import OfflineImapError
|
from offlineimap import OfflineImapError
|
||||||
|
from offlineimap.ui import getglobalui
|
||||||
from offlineimap.virtual_imaplib2 import IMAP4, IMAP4_SSL, InternalDate, Mon2num
|
from offlineimap.virtual_imaplib2 import IMAP4, IMAP4_SSL, InternalDate, Mon2num
|
||||||
|
|
||||||
|
|
||||||
@ -58,7 +58,9 @@ class UsefulIMAPMixIn(object):
|
|||||||
errstr = "Server '%s' closed connection, error on SELECT '%s'. Ser"\
|
errstr = "Server '%s' closed connection, error on SELECT '%s'. Ser"\
|
||||||
"ver said: %s" % (self.host, mailbox, e.args[0])
|
"ver said: %s" % (self.host, mailbox, e.args[0])
|
||||||
severity = OfflineImapError.ERROR.FOLDER_RETRY
|
severity = OfflineImapError.ERROR.FOLDER_RETRY
|
||||||
six.reraise(OfflineImapError(errstr, severity), None, exc_info()[2])
|
six.reraise(OfflineImapError,
|
||||||
|
OfflineImapError(errstr, severity),
|
||||||
|
exc_info()[2])
|
||||||
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" %\
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# IMAP server support
|
# IMAP server support
|
||||||
# Copyright (C) 2002 - 2016 John Goerzen & contributors
|
# Copyright (C) 2002-2016 John Goerzen & contributors.
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
@ -15,24 +15,22 @@
|
|||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
from threading import Lock, BoundedSemaphore, Thread, Event, currentThread
|
|
||||||
import hmac
|
import hmac
|
||||||
import socket
|
import socket
|
||||||
import base64
|
import base64
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import urllib
|
import urllib
|
||||||
|
|
||||||
import socket
|
import socket
|
||||||
import time
|
import time
|
||||||
import errno
|
import errno
|
||||||
|
import six
|
||||||
from sys import exc_info
|
from sys import exc_info
|
||||||
from socket import gaierror
|
from socket import gaierror
|
||||||
from ssl import SSLError, cert_time_to_seconds
|
from ssl import SSLError, cert_time_to_seconds
|
||||||
import six
|
from threading import Lock, BoundedSemaphore, Thread, Event, currentThread
|
||||||
|
|
||||||
from offlineimap import imaplibutil, imaputil, threadutil, OfflineImapError
|
|
||||||
import offlineimap.accounts
|
import offlineimap.accounts
|
||||||
|
from offlineimap import imaplibutil, imaputil, threadutil, OfflineImapError
|
||||||
from offlineimap.ui import getglobalui
|
from offlineimap.ui import getglobalui
|
||||||
|
|
||||||
|
|
||||||
@ -574,7 +572,9 @@ class IMAPServer(object):
|
|||||||
"'%s'. Make sure you have configured the ser"\
|
"'%s'. Make sure you have configured the ser"\
|
||||||
"ver name correctly and that you are online."%\
|
"ver name correctly and that you are online."%\
|
||||||
(self.hostname, self.repos)
|
(self.hostname, self.repos)
|
||||||
six.reraise(OfflineImapError(reason, severity), None, exc_info()[2])
|
six.reraise(OfflineImapError,
|
||||||
|
OfflineImapError(reason, severity),
|
||||||
|
exc_info()[2])
|
||||||
|
|
||||||
elif isinstance(e, SSLError) and e.errno == errno.EPERM:
|
elif isinstance(e, SSLError) and e.errno == errno.EPERM:
|
||||||
# SSL unknown protocol error
|
# SSL unknown protocol error
|
||||||
@ -587,7 +587,9 @@ class IMAPServer(object):
|
|||||||
reason = "Unknown SSL protocol connecting to host '%s' for "\
|
reason = "Unknown SSL protocol connecting to host '%s' for "\
|
||||||
"repository '%s'. OpenSSL responded:\n%s"\
|
"repository '%s'. OpenSSL responded:\n%s"\
|
||||||
% (self.hostname, self.repos, e)
|
% (self.hostname, self.repos, e)
|
||||||
six.reraise(OfflineImapError(reason, severity), None, exc_info()[2])
|
six.reraise(OfflineImapError,
|
||||||
|
OfflineImapError(reason, severity),
|
||||||
|
exc_info()[2])
|
||||||
|
|
||||||
elif isinstance(e, socket.error) and e.args[0] == errno.ECONNREFUSED:
|
elif isinstance(e, socket.error) and e.args[0] == errno.ECONNREFUSED:
|
||||||
# "Connection refused", can be a non-existing port, or an unauthorized
|
# "Connection refused", can be a non-existing port, or an unauthorized
|
||||||
@ -596,14 +598,19 @@ class IMAPServer(object):
|
|||||||
"refused. Make sure you have the right host and port "\
|
"refused. Make sure you have the right host and port "\
|
||||||
"configured and that you are actually able to access the "\
|
"configured and that you are actually able to access the "\
|
||||||
"network."% (self.hostname, self.port, self.repos)
|
"network."% (self.hostname, self.port, self.repos)
|
||||||
six.reraise(OfflineImapError(reason, severity), None, exc_info()[2])
|
six.reraise(OfflineImapError,
|
||||||
|
OfflineImapError(reason, severity),
|
||||||
|
exc_info()[2])
|
||||||
# Could not acquire connection to the remote;
|
# Could not acquire connection to the remote;
|
||||||
# socket.error(last_error) raised
|
# socket.error(last_error) raised
|
||||||
if str(e)[:24] == "can't open socket; error":
|
if str(e)[:24] == "can't open socket; error":
|
||||||
six.reraise(OfflineImapError("Could not connect to remote server '%s' "\
|
six.reraise(OfflineImapError,
|
||||||
"for repository '%s'. Remote does not answer."
|
OfflineImapError(
|
||||||
% (self.hostname, self.repos),
|
"Could not connect to remote server '%s' "
|
||||||
OfflineImapError.ERROR.REPO), None, exc_info()[2])
|
"for repository '%s'. Remote does not answer."%
|
||||||
|
(self.hostname, self.repos),
|
||||||
|
OfflineImapError.ERROR.REPO),
|
||||||
|
exc_info()[2])
|
||||||
else:
|
else:
|
||||||
# re-raise all other errors
|
# re-raise all other errors
|
||||||
raise
|
raise
|
||||||
|
@ -110,8 +110,12 @@ class IMAPRepository(BaseRepository):
|
|||||||
try:
|
try:
|
||||||
host = self.localeval.eval(host)
|
host = self.localeval.eval(host)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
six.reraise(OfflineImapError("remotehosteval option for repository "
|
six.reraise(OfflineImapError,
|
||||||
"'%s' failed:\n%s"% (self, e), OfflineImapError.ERROR.REPO), None, exc_info()[2])
|
OfflineImapError(
|
||||||
|
"remotehosteval option for repository "
|
||||||
|
"'%s' failed:\n%s"% (self, e),
|
||||||
|
OfflineImapError.ERROR.REPO),
|
||||||
|
exc_info()[2])
|
||||||
if host:
|
if host:
|
||||||
self._host = host
|
self._host = host
|
||||||
return self._host
|
return self._host
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
# Copyright (C) 2002-2007 John Goerzen <jgoerzen@complete.org>
|
# Copyright (C) 2002-2016 John Goerzen & contributors.
|
||||||
# 2010 Sebastian Spaeth <Sebastian@SSpaeth.de> and contributors
|
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
@ -15,9 +14,8 @@
|
|||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
from sys import exc_info
|
|
||||||
|
|
||||||
import six
|
import six
|
||||||
|
from sys import exc_info
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from configparser import NoSectionError
|
from configparser import NoSectionError
|
||||||
@ -70,14 +68,18 @@ class Repository(object):
|
|||||||
except NoSectionError as e:
|
except NoSectionError as e:
|
||||||
errstr = ("Could not find section '%s' in configuration. Required "
|
errstr = ("Could not find section '%s' in configuration. Required "
|
||||||
"for account '%s'." % ('Repository %s' % name, account))
|
"for account '%s'." % ('Repository %s' % name, account))
|
||||||
six.reraise(OfflineImapError(errstr, OfflineImapError.ERROR.REPO), None, exc_info()[2])
|
six.reraise(OfflineImapError,
|
||||||
|
OfflineImapError(errstr, OfflineImapError.ERROR.REPO),
|
||||||
|
exc_info()[2])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
repo = typemap[repostype]
|
repo = typemap[repostype]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
errstr = "'%s' repository not supported for '%s' repositories."% \
|
errstr = "'%s' repository not supported for '%s' repositories."% \
|
||||||
(repostype, reqtype)
|
(repostype, reqtype)
|
||||||
six.reraise(OfflineImapError(errstr, OfflineImapError.ERROR.REPO), None, exc_info()[2])
|
six.reraise(OfflineImapError,
|
||||||
|
OfflineImapError(errstr, OfflineImapError.ERROR.REPO),
|
||||||
|
exc_info()[2])
|
||||||
|
|
||||||
return repo(name, account)
|
return repo(name, account)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user