folder: properly factorize initialization and dropping of self.message
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
parent
9486a0dab3
commit
657f258196
@ -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.
|
||||
|
@ -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()
|
||||
|
@ -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).
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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."""
|
||||
|
Loading…
Reference in New Issue
Block a user