From 657f258196d44454f98ad80b5d10d534b46a488e Mon Sep 17 00:00:00 2001 From: Nicolas Sebrecht Date: Sat, 9 Apr 2016 18:12:18 +0200 Subject: [PATCH] folder: properly factorize initialization and dropping of self.message Signed-off-by: Nicolas Sebrecht --- offlineimap/folder/Base.py | 5 +++-- offlineimap/folder/Gmail.py | 2 +- offlineimap/folder/IMAP.py | 10 +--------- offlineimap/folder/LocalStatus.py | 9 ++------- offlineimap/folder/LocalStatusSQLite.py | 11 +---------- offlineimap/folder/Maildir.py | 5 ----- 6 files changed, 8 insertions(+), 34 deletions(-) diff --git a/offlineimap/folder/Base.py b/offlineimap/folder/Base.py index 14b0867..c358a51 100644 --- a/offlineimap/folder/Base.py +++ b/offlineimap/folder/Base.py @@ -35,6 +35,7 @@ class BaseFolder(object): """ self.ui = getglobalui() + self.messagelist = {} # Save original name for folderfilter operations self.ffilter_name = name # Top level dir name is always '' @@ -262,7 +263,7 @@ class BaseFolder(object): raise NotImplementedError def ismessagelistempty(self): - """Empty everythings we know about messages.""" + """Is the list of messages empty.""" if len(self.messagelist.keys()) < 1: return True @@ -278,7 +279,7 @@ class BaseFolder(object): You must call cachemessagelist() before calling this function!""" - raise NotImplementedError + return self.messagelist def msglist_item_initializer(self, uid): """Returns value for empty messagelist element with given UID. diff --git a/offlineimap/folder/Gmail.py b/offlineimap/folder/Gmail.py index ee52aed..970d836 100644 --- a/offlineimap/folder/Gmail.py +++ b/offlineimap/folder/Gmail.py @@ -122,7 +122,7 @@ class GmailFolder(IMAPFolder): return super(GmailFolder, self).cachemessagelist( min_date=min_date, min_uid=min_uid) - self.messagelist = {} + self.dropmessagelistcache() self.ui.collectingdata(None, self) imapobj = self.imapserver.acquireconnection() diff --git a/offlineimap/folder/IMAP.py b/offlineimap/folder/IMAP.py index 5a26051..c105b72 100644 --- a/offlineimap/folder/IMAP.py +++ b/offlineimap/folder/IMAP.py @@ -49,7 +49,6 @@ class IMAPFolder(BaseFolder): self.expunge = repository.getexpunge() self.root = None # imapserver.root self.imapserver = imapserver - self.messagelist = {} self.randomgenerator = random.Random() #self.ui is set in BaseFolder self.imap_query = ['BODY.PEEK[]'] @@ -216,7 +215,7 @@ class IMAPFolder(BaseFolder): # Interface from BaseFolder def cachemessagelist(self, min_date=None, min_uid=None): self.ui.loadmessagelist(self.repository, self) - self.messagelist = {} + self.dropmessagelistcache() imapobj = self.imapserver.acquireconnection() try: @@ -257,9 +256,6 @@ class IMAPFolder(BaseFolder): 'keywords': keywords} self.ui.messagelistloaded(self.repository, self, self.getmessagecount()) - def dropmessagelistcache(self): - self.messagelist = {} - # Interface from BaseFolder def getvisiblename(self): vname = super(IMAPFolder, self).getvisiblename() @@ -267,10 +263,6 @@ class IMAPFolder(BaseFolder): return imaputil.decode_mailbox_name(vname) return vname - # Interface from BaseFolder - def getmessagelist(self): - return self.messagelist - # Interface from BaseFolder def getmessage(self, uid): """Retrieve message with UID from the IMAP server (incl body). diff --git a/offlineimap/folder/LocalStatus.py b/offlineimap/folder/LocalStatus.py index 78f2134..2a16e0b 100644 --- a/offlineimap/folder/LocalStatus.py +++ b/offlineimap/folder/LocalStatus.py @@ -33,7 +33,6 @@ class LocalStatusFolder(BaseFolder): super(LocalStatusFolder, self).__init__(name, repository) self.root = repository.root self.filename = os.path.join(self.getroot(), self.getfolderbasename()) - self.messagelist = {} self.savelock = threading.Lock() # Should we perform fsyncs as often as possible? self.doautosave = self.config.getdefaultboolean( @@ -108,12 +107,12 @@ class LocalStatusFolder(BaseFolder): # Interface from BaseFolder def cachemessagelist(self): if self.isnewfolder(): - self.messagelist = {} + self.dropmessagelistcache() return # Loop as many times as version, and update format. for i in range(1, self.cur_version + 1): - self.messagelist = {} + self.dropmessagelistcache() cachefd = open(self.filename, "rt") line = cachefd.readline().strip() @@ -181,10 +180,6 @@ class LocalStatusFolder(BaseFolder): os.fsync(fd) os.close(fd) - # Interface from BaseFolder - def getmessagelist(self): - return self.messagelist - # Interface from BaseFolder def savemessage(self, uid, content, flags, rtime, mtime=0, labels=set()): """Writes a new message, with the specified uid. diff --git a/offlineimap/folder/LocalStatusSQLite.py b/offlineimap/folder/LocalStatusSQLite.py index 64adcd1..6eb549f 100644 --- a/offlineimap/folder/LocalStatusSQLite.py +++ b/offlineimap/folder/LocalStatusSQLite.py @@ -48,7 +48,6 @@ class LocalStatusSQLiteFolder(BaseFolder): super(LocalStatusSQLiteFolder, self).__init__(name, repository) self.root = repository.root self.filename = os.path.join(self.getroot(), self.getfolderbasename()) - self.messagelist = {} self._newfolder = False # Flag if the folder is new. @@ -197,7 +196,7 @@ class LocalStatusSQLiteFolder(BaseFolder): # Interface from BaseFolder def cachemessagelist(self): - self.messagelist = {} + self.dropmessagelistcache() cursor = self.connection.execute('SELECT id,flags,mtime,labels from status') for row in cursor: uid = row[0] @@ -222,9 +221,6 @@ class LocalStatusSQLiteFolder(BaseFolder): self.messagelist[uid]['labels'] = labels self.messagelist[uid]['mtime'] = row[2] - def dropmessagelistcache(self): - self.messagelist = {} - # Interface from LocalStatusFolder def save(self): pass @@ -282,11 +278,6 @@ class LocalStatusSQLiteFolder(BaseFolder): # assert False,"getmessageflags() called on non-existing message" - # Interface from BaseFolder - def getmessagelist(self): - return self.messagelist - - # Interface from BaseFolder def savemessage(self, uid, content, flags, rtime, mtime=0, labels=set()): """Writes a new message, with the specified uid. diff --git a/offlineimap/folder/Maildir.py b/offlineimap/folder/Maildir.py index 77a774b..d97b0d3 100644 --- a/offlineimap/folder/Maildir.py +++ b/offlineimap/folder/Maildir.py @@ -61,7 +61,6 @@ class MaildirFolder(BaseFolder): super(MaildirFolder, self).__init__(name, repository) self.dofsync = self.config.getdefaultboolean("general", "fsync", True) self.root = root - self.messagelist = {} # check if we should use a different infosep to support Win file systems self.wincompatible = self.config.getdefaultboolean( "Account "+self.accountname, "maildir-windows-compatible", False) @@ -244,10 +243,6 @@ class MaildirFolder(BaseFolder): min_uid=min_uid) self.ui.messagelistloaded(self.repository, self, self.getmessagecount()) - # Interface from BaseFolder - def getmessagelist(self): - return self.messagelist - # Interface from BaseFolder def getmessage(self, uid): """Return the content of the message."""