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.ui = getglobalui()
|
||||||
|
self.messagelist = {}
|
||||||
# Save original name for folderfilter operations
|
# Save original name for folderfilter operations
|
||||||
self.ffilter_name = name
|
self.ffilter_name = name
|
||||||
# Top level dir name is always ''
|
# Top level dir name is always ''
|
||||||
@ -262,7 +263,7 @@ class BaseFolder(object):
|
|||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def ismessagelistempty(self):
|
def ismessagelistempty(self):
|
||||||
"""Empty everythings we know about messages."""
|
"""Is the list of messages empty."""
|
||||||
|
|
||||||
if len(self.messagelist.keys()) < 1:
|
if len(self.messagelist.keys()) < 1:
|
||||||
return True
|
return True
|
||||||
@ -278,7 +279,7 @@ class BaseFolder(object):
|
|||||||
|
|
||||||
You must call cachemessagelist() before calling this function!"""
|
You must call cachemessagelist() before calling this function!"""
|
||||||
|
|
||||||
raise NotImplementedError
|
return self.messagelist
|
||||||
|
|
||||||
def msglist_item_initializer(self, uid):
|
def msglist_item_initializer(self, uid):
|
||||||
"""Returns value for empty messagelist element with given UID.
|
"""Returns value for empty messagelist element with given UID.
|
||||||
|
@ -122,7 +122,7 @@ class GmailFolder(IMAPFolder):
|
|||||||
return super(GmailFolder, self).cachemessagelist(
|
return super(GmailFolder, self).cachemessagelist(
|
||||||
min_date=min_date, min_uid=min_uid)
|
min_date=min_date, min_uid=min_uid)
|
||||||
|
|
||||||
self.messagelist = {}
|
self.dropmessagelistcache()
|
||||||
|
|
||||||
self.ui.collectingdata(None, self)
|
self.ui.collectingdata(None, self)
|
||||||
imapobj = self.imapserver.acquireconnection()
|
imapobj = self.imapserver.acquireconnection()
|
||||||
|
@ -49,7 +49,6 @@ class IMAPFolder(BaseFolder):
|
|||||||
self.expunge = repository.getexpunge()
|
self.expunge = repository.getexpunge()
|
||||||
self.root = None # imapserver.root
|
self.root = None # imapserver.root
|
||||||
self.imapserver = imapserver
|
self.imapserver = imapserver
|
||||||
self.messagelist = {}
|
|
||||||
self.randomgenerator = random.Random()
|
self.randomgenerator = random.Random()
|
||||||
#self.ui is set in BaseFolder
|
#self.ui is set in BaseFolder
|
||||||
self.imap_query = ['BODY.PEEK[]']
|
self.imap_query = ['BODY.PEEK[]']
|
||||||
@ -216,7 +215,7 @@ class IMAPFolder(BaseFolder):
|
|||||||
# Interface from BaseFolder
|
# Interface from BaseFolder
|
||||||
def cachemessagelist(self, min_date=None, min_uid=None):
|
def cachemessagelist(self, min_date=None, min_uid=None):
|
||||||
self.ui.loadmessagelist(self.repository, self)
|
self.ui.loadmessagelist(self.repository, self)
|
||||||
self.messagelist = {}
|
self.dropmessagelistcache()
|
||||||
|
|
||||||
imapobj = self.imapserver.acquireconnection()
|
imapobj = self.imapserver.acquireconnection()
|
||||||
try:
|
try:
|
||||||
@ -257,9 +256,6 @@ class IMAPFolder(BaseFolder):
|
|||||||
'keywords': keywords}
|
'keywords': keywords}
|
||||||
self.ui.messagelistloaded(self.repository, self, self.getmessagecount())
|
self.ui.messagelistloaded(self.repository, self, self.getmessagecount())
|
||||||
|
|
||||||
def dropmessagelistcache(self):
|
|
||||||
self.messagelist = {}
|
|
||||||
|
|
||||||
# Interface from BaseFolder
|
# Interface from BaseFolder
|
||||||
def getvisiblename(self):
|
def getvisiblename(self):
|
||||||
vname = super(IMAPFolder, self).getvisiblename()
|
vname = super(IMAPFolder, self).getvisiblename()
|
||||||
@ -267,10 +263,6 @@ class IMAPFolder(BaseFolder):
|
|||||||
return imaputil.decode_mailbox_name(vname)
|
return imaputil.decode_mailbox_name(vname)
|
||||||
return vname
|
return vname
|
||||||
|
|
||||||
# Interface from BaseFolder
|
|
||||||
def getmessagelist(self):
|
|
||||||
return self.messagelist
|
|
||||||
|
|
||||||
# Interface from BaseFolder
|
# Interface from BaseFolder
|
||||||
def getmessage(self, uid):
|
def getmessage(self, uid):
|
||||||
"""Retrieve message with UID from the IMAP server (incl body).
|
"""Retrieve message with UID from the IMAP server (incl body).
|
||||||
|
@ -33,7 +33,6 @@ class LocalStatusFolder(BaseFolder):
|
|||||||
super(LocalStatusFolder, self).__init__(name, repository)
|
super(LocalStatusFolder, self).__init__(name, repository)
|
||||||
self.root = repository.root
|
self.root = repository.root
|
||||||
self.filename = os.path.join(self.getroot(), self.getfolderbasename())
|
self.filename = os.path.join(self.getroot(), self.getfolderbasename())
|
||||||
self.messagelist = {}
|
|
||||||
self.savelock = threading.Lock()
|
self.savelock = threading.Lock()
|
||||||
# Should we perform fsyncs as often as possible?
|
# Should we perform fsyncs as often as possible?
|
||||||
self.doautosave = self.config.getdefaultboolean(
|
self.doautosave = self.config.getdefaultboolean(
|
||||||
@ -108,12 +107,12 @@ class LocalStatusFolder(BaseFolder):
|
|||||||
# Interface from BaseFolder
|
# Interface from BaseFolder
|
||||||
def cachemessagelist(self):
|
def cachemessagelist(self):
|
||||||
if self.isnewfolder():
|
if self.isnewfolder():
|
||||||
self.messagelist = {}
|
self.dropmessagelistcache()
|
||||||
return
|
return
|
||||||
|
|
||||||
# Loop as many times as version, and update format.
|
# Loop as many times as version, and update format.
|
||||||
for i in range(1, self.cur_version + 1):
|
for i in range(1, self.cur_version + 1):
|
||||||
self.messagelist = {}
|
self.dropmessagelistcache()
|
||||||
cachefd = open(self.filename, "rt")
|
cachefd = open(self.filename, "rt")
|
||||||
line = cachefd.readline().strip()
|
line = cachefd.readline().strip()
|
||||||
|
|
||||||
@ -181,10 +180,6 @@ class LocalStatusFolder(BaseFolder):
|
|||||||
os.fsync(fd)
|
os.fsync(fd)
|
||||||
os.close(fd)
|
os.close(fd)
|
||||||
|
|
||||||
# Interface from BaseFolder
|
|
||||||
def getmessagelist(self):
|
|
||||||
return self.messagelist
|
|
||||||
|
|
||||||
# Interface from BaseFolder
|
# Interface from BaseFolder
|
||||||
def savemessage(self, uid, content, flags, rtime, mtime=0, labels=set()):
|
def savemessage(self, uid, content, flags, rtime, mtime=0, labels=set()):
|
||||||
"""Writes a new message, with the specified uid.
|
"""Writes a new message, with the specified uid.
|
||||||
|
@ -48,7 +48,6 @@ class LocalStatusSQLiteFolder(BaseFolder):
|
|||||||
super(LocalStatusSQLiteFolder, self).__init__(name, repository)
|
super(LocalStatusSQLiteFolder, self).__init__(name, repository)
|
||||||
self.root = repository.root
|
self.root = repository.root
|
||||||
self.filename = os.path.join(self.getroot(), self.getfolderbasename())
|
self.filename = os.path.join(self.getroot(), self.getfolderbasename())
|
||||||
self.messagelist = {}
|
|
||||||
|
|
||||||
self._newfolder = False # Flag if the folder is new.
|
self._newfolder = False # Flag if the folder is new.
|
||||||
|
|
||||||
@ -197,7 +196,7 @@ class LocalStatusSQLiteFolder(BaseFolder):
|
|||||||
|
|
||||||
# Interface from BaseFolder
|
# Interface from BaseFolder
|
||||||
def cachemessagelist(self):
|
def cachemessagelist(self):
|
||||||
self.messagelist = {}
|
self.dropmessagelistcache()
|
||||||
cursor = self.connection.execute('SELECT id,flags,mtime,labels from status')
|
cursor = self.connection.execute('SELECT id,flags,mtime,labels from status')
|
||||||
for row in cursor:
|
for row in cursor:
|
||||||
uid = row[0]
|
uid = row[0]
|
||||||
@ -222,9 +221,6 @@ class LocalStatusSQLiteFolder(BaseFolder):
|
|||||||
self.messagelist[uid]['labels'] = labels
|
self.messagelist[uid]['labels'] = labels
|
||||||
self.messagelist[uid]['mtime'] = row[2]
|
self.messagelist[uid]['mtime'] = row[2]
|
||||||
|
|
||||||
def dropmessagelistcache(self):
|
|
||||||
self.messagelist = {}
|
|
||||||
|
|
||||||
# Interface from LocalStatusFolder
|
# Interface from LocalStatusFolder
|
||||||
def save(self):
|
def save(self):
|
||||||
pass
|
pass
|
||||||
@ -282,11 +278,6 @@ class LocalStatusSQLiteFolder(BaseFolder):
|
|||||||
# assert False,"getmessageflags() called on non-existing message"
|
# assert False,"getmessageflags() called on non-existing message"
|
||||||
|
|
||||||
|
|
||||||
# Interface from BaseFolder
|
|
||||||
def getmessagelist(self):
|
|
||||||
return self.messagelist
|
|
||||||
|
|
||||||
|
|
||||||
# Interface from BaseFolder
|
# Interface from BaseFolder
|
||||||
def savemessage(self, uid, content, flags, rtime, mtime=0, labels=set()):
|
def savemessage(self, uid, content, flags, rtime, mtime=0, labels=set()):
|
||||||
"""Writes a new message, with the specified uid.
|
"""Writes a new message, with the specified uid.
|
||||||
|
@ -61,7 +61,6 @@ class MaildirFolder(BaseFolder):
|
|||||||
super(MaildirFolder, self).__init__(name, repository)
|
super(MaildirFolder, self).__init__(name, repository)
|
||||||
self.dofsync = self.config.getdefaultboolean("general", "fsync", True)
|
self.dofsync = self.config.getdefaultboolean("general", "fsync", True)
|
||||||
self.root = root
|
self.root = root
|
||||||
self.messagelist = {}
|
|
||||||
# check if we should use a different infosep to support Win file systems
|
# check if we should use a different infosep to support Win file systems
|
||||||
self.wincompatible = self.config.getdefaultboolean(
|
self.wincompatible = self.config.getdefaultboolean(
|
||||||
"Account "+self.accountname, "maildir-windows-compatible", False)
|
"Account "+self.accountname, "maildir-windows-compatible", False)
|
||||||
@ -244,10 +243,6 @@ class MaildirFolder(BaseFolder):
|
|||||||
min_uid=min_uid)
|
min_uid=min_uid)
|
||||||
self.ui.messagelistloaded(self.repository, self, self.getmessagecount())
|
self.ui.messagelistloaded(self.repository, self, self.getmessagecount())
|
||||||
|
|
||||||
# Interface from BaseFolder
|
|
||||||
def getmessagelist(self):
|
|
||||||
return self.messagelist
|
|
||||||
|
|
||||||
# Interface from BaseFolder
|
# Interface from BaseFolder
|
||||||
def getmessage(self, uid):
|
def getmessage(self, uid):
|
||||||
"""Return the content of the message."""
|
"""Return the content of the message."""
|
||||||
|
Loading…
Reference in New Issue
Block a user