From 4d352a528a3a74a457a6e3cd9dfdd565fee661df Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Wed, 9 Mar 2011 08:53:20 +0100 Subject: [PATCH] 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 Signed-off-by: Nicolas Sebrecht --- offlineimap/accounts.py | 6 +++--- offlineimap/folder/Base.py | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/offlineimap/accounts.py b/offlineimap/accounts.py index 35550c1..7ffdfc1 100644 --- a/offlineimap/accounts.py +++ b/offlineimap/accounts.py @@ -324,13 +324,13 @@ def syncfolder(accountname, remoterepos, remotefolder, localrepos, ui.syncingfolder(remoterepos, remotefolder, localrepos, localfolder) ui.loadmessagelist(localrepos, localfolder) 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 # 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 # 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(): ui.validityproblem(localfolder) localrepos.restore_atime() @@ -347,7 +347,7 @@ def syncfolder(accountname, remoterepos, remotefolder, localrepos, ui.loadmessagelist(remoterepos, remotefolder) remotefolder.cachemessagelist() ui.messagelistloaded(remoterepos, remotefolder, - len(remotefolder.getmessagelist().keys())) + remotefolder.getmessagecount()) # Synchronize remote changes. ui.syncingmessages(remoterepos, remotefolder, localrepos, localfolder) diff --git a/offlineimap/folder/Base.py b/offlineimap/folder/Base.py index 5c06e6e..ffbbbbb 100644 --- a/offlineimap/folder/Base.py +++ b/offlineimap/folder/Base.py @@ -139,6 +139,10 @@ class BaseFolder: You must call cachemessagelist() before calling this function!""" raise NotImplementedException + def getmessagecount(self): + """Gets the number of messages.""" + return len(self.getmessagelist()) + def getmessage(self, uid): """Returns the content of the specified message.""" raise NotImplementedException