Fix caching inconsistencies in getselectedfolder()

getselectedfolder was using a cached variable that we were setting in
select(), but sometimes the IMAP4 instance got into the SELECTED state
without explicitely select()ing, it seems, and our variable was unset.

Let us just use the self.mailbox variable that imaplib2 is setting when
select()ing rather than doing our own caching. Also remove the part
where we were setting the cache.

Just access self.state rather than looking up self.state via
self.getstate() every time, it is just an unnecessary layer of
redirection.

Original-patch-by: Arnaud Fontaine <arnau@debian.org>
Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
Sebastian Spaeth 2011-07-06 23:15:33 +02:00 committed by Nicolas Sebrecht
parent 09ba269576
commit c293e64119

View File

@ -33,11 +33,9 @@ except ImportError:
pass pass
class UsefulIMAPMixIn: class UsefulIMAPMixIn:
def getstate(self):
return self.state
def getselectedfolder(self): def getselectedfolder(self):
if self.getstate() == 'SELECTED': if self.state == 'SELECTED':
return self.selectedfolder return self.mailbox
return None return None
def select(self, mailbox='INBOX', readonly=None, force = 0): def select(self, mailbox='INBOX', readonly=None, force = 0):
@ -58,10 +56,6 @@ class UsefulIMAPMixIn:
(mailbox, result) (mailbox, result)
severity = OfflineImapError.ERROR.FOLDER severity = OfflineImapError.ERROR.FOLDER
raise OfflineImapError(errstr, severity) raise OfflineImapError(errstr, severity)
if self.getstate() == 'SELECTED':
self.selectedfolder = mailbox
else:
self.selectedfolder = None
return result return result
def _mesg(self, s, tn=None, secs=None): def _mesg(self, s, tn=None, secs=None):