folder: Implement helper function getmessagecount()

Rather than always having to call len(getmessagelist.keys()) as was done
before. No functional change, just nicer looking code. Also the SQLite
backend or other backends could implement more efficient implementations.

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-03-09 08:53:20 +01:00 committed by Nicolas Sebrecht
parent 5048d16913
commit 4d352a528a
2 changed files with 7 additions and 3 deletions

View File

@ -324,13 +324,13 @@ def syncfolder(accountname, remoterepos, remotefolder, localrepos,
ui.syncingfolder(remoterepos, remotefolder, localrepos, localfolder) ui.syncingfolder(remoterepos, remotefolder, localrepos, localfolder)
ui.loadmessagelist(localrepos, localfolder) ui.loadmessagelist(localrepos, localfolder)
localfolder.cachemessagelist() localfolder.cachemessagelist()
ui.messagelistloaded(localrepos, localfolder, len(localfolder.getmessagelist().keys())) ui.messagelistloaded(localrepos, localfolder, localfolder.getmessagecount())
# If either the local or the status folder has messages and there is a UID # If either the local or the status folder has messages and there is a UID
# validity problem, warn and abort. If there are no messages, UW IMAPd # validity problem, warn and abort. If there are no messages, UW IMAPd
# loses UIDVALIDITY. But we don't really need it if both local folders are # loses UIDVALIDITY. But we don't really need it if both local folders are
# empty. So, in that case, just save it off. # empty. So, in that case, just save it off.
if len(localfolder.getmessagelist()) or len(statusfolder.getmessagelist()): if localfolder.getmessagecount() or statusfolder.getmessagecount():
if not localfolder.isuidvalidityok(): if not localfolder.isuidvalidityok():
ui.validityproblem(localfolder) ui.validityproblem(localfolder)
localrepos.restore_atime() localrepos.restore_atime()
@ -347,7 +347,7 @@ def syncfolder(accountname, remoterepos, remotefolder, localrepos,
ui.loadmessagelist(remoterepos, remotefolder) ui.loadmessagelist(remoterepos, remotefolder)
remotefolder.cachemessagelist() remotefolder.cachemessagelist()
ui.messagelistloaded(remoterepos, remotefolder, ui.messagelistloaded(remoterepos, remotefolder,
len(remotefolder.getmessagelist().keys())) remotefolder.getmessagecount())
# Synchronize remote changes. # Synchronize remote changes.
ui.syncingmessages(remoterepos, remotefolder, localrepos, localfolder) ui.syncingmessages(remoterepos, remotefolder, localrepos, localfolder)

View File

@ -139,6 +139,10 @@ class BaseFolder:
You must call cachemessagelist() before calling this function!""" You must call cachemessagelist() before calling this function!"""
raise NotImplementedException raise NotImplementedException
def getmessagecount(self):
"""Gets the number of messages."""
return len(self.getmessagelist())
def getmessage(self, uid): def getmessage(self, uid):
"""Returns the content of the specified message.""" """Returns the content of the specified message."""
raise NotImplementedException raise NotImplementedException