diff --git a/Changelog.draft.rst b/Changelog.draft.rst index 778b52c..ff9fc5b 100644 --- a/Changelog.draft.rst +++ b/Changelog.draft.rst @@ -43,3 +43,7 @@ Bug Fixes * Make NOOPs to keep a server connection open more resistant against dropped connections. + +* a readonly parameter to select() was not always treated correctly, + which could result in some folders being opened read-only when we + really needed read-write. diff --git a/offlineimap/folder/IMAP.py b/offlineimap/folder/IMAP.py index 58ff633..a7b8762 100644 --- a/offlineimap/folder/IMAP.py +++ b/offlineimap/folder/IMAP.py @@ -54,7 +54,7 @@ class IMAPFolder(BaseFolder): try: imapobj.select(self.getfullname()) except imapobj.readonly: - imapobj.select(self.getfullname(), readonly = 1) + imapobj.select(self.getfullname(), readonly = True) def suggeststhreads(self): return 1 @@ -204,7 +204,7 @@ class IMAPFolder(BaseFolder): fails_left = 2 # retry on dropped connection while fails_left: try: - imapobj.select(self.getfullname(), readonly = 1) + imapobj.select(self.getfullname(), readonly = True) res_type, data = imapobj.uid('fetch', str(uid), '(BODY.PEEK[])') fails_left = 0 diff --git a/offlineimap/imaplibutil.py b/offlineimap/imaplibutil.py index 5c94592..c9a7715 100644 --- a/offlineimap/imaplibutil.py +++ b/offlineimap/imaplibutil.py @@ -34,37 +34,37 @@ except ImportError: #fails on python <2.6 pass -class UsefulIMAPMixIn: +class UsefulIMAPMixIn(object): def getselectedfolder(self): if self.state == 'SELECTED': return self.mailbox return None - def select(self, mailbox='INBOX', readonly=None, force = 0): + def select(self, mailbox='INBOX', readonly=False, 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 \ - and self.is_readonly == readonly: + if self.getselectedfolder() == mailbox and self.is_readonly == readonly \ + and not force: # No change; return. return # Wipe out all old responses, to maintain semantics with old imaplib2 del self.untagged_responses[:] try: - result = self.__class__.__bases__[1].select(self, mailbox, readonly) + result = super(UsefulIMAPMixIn, self).select(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) + raise OfflineImapError(errstr, severity) if result[0] != 'OK': #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) + raise OfflineImapError(errstr, severity) return result def _mesg(self, s, tn=None, secs=None): diff --git a/offlineimap/repository/IMAP.py b/offlineimap/repository/IMAP.py index 4c2cadd..8c29ee2 100644 --- a/offlineimap/repository/IMAP.py +++ b/offlineimap/repository/IMAP.py @@ -289,7 +289,7 @@ class IMAPRepository(BaseRepository): try: for foldername in self.folderincludes: try: - imapobj.select(foldername, readonly = 1) + imapobj.select(foldername, readonly = True) except OfflineImapError, e: # couldn't select this folderinclude, so ignore folder. if e.severity > OfflineImapError.ERROR.FOLDER: