diff --git a/offlineimap/head/offlineimap/accounts.py b/offlineimap/head/offlineimap/accounts.py index cdfd505..3fdd386 100644 --- a/offlineimap/head/offlineimap/accounts.py +++ b/offlineimap/head/offlineimap/accounts.py @@ -15,7 +15,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -from offlineimap import imapserver, repository, threadutil +from offlineimap import imapserver, repository, threadutil, mbnames from offlineimap.ui import UIBase from offlineimap.threadutil import InstanceLimitedThread, ExitNotifyThread from threading import Event @@ -128,6 +128,7 @@ class AccountSynchronizationMixin: thread.start() folderthreads.append(thread) threadutil.threadsreset(folderthreads) + mbnames.write() if not self.hold: server.close() finally: @@ -146,8 +147,7 @@ def syncfolder(accountname, remoterepos, remotefolder, localrepos, getfolder(remotefolder.getvisiblename().\ replace(remoterepos.getsep(), localrepos.getsep())) # Write the mailboxes - mailboxes.append({'accountname': accountname, - 'foldername': localfolder.getvisiblename()}) + mbnames.add(accountname, localfolder.getvisiblename()) # Load local folder ui.syncingfolder(remoterepos, remotefolder, localrepos, localfolder) ui.loadmessagelist(localrepos, localfolder) diff --git a/offlineimap/head/offlineimap/mbnames.py b/offlineimap/head/offlineimap/mbnames.py index 0d510be..42f5e54 100644 --- a/offlineimap/head/offlineimap/mbnames.py +++ b/offlineimap/head/offlineimap/mbnames.py @@ -19,7 +19,30 @@ import os.path import re # for folderfilter -def genmbnames(config, boxlist): +boxes = {} +config = None +accounts = None + +def init(conf, accts): + global config, accounts + config = conf + accounts = accts + +def add(accountname, foldername): + if not accountname in boxes: + boxes[accountname] = [] + if not foldername in boxes[accountname]: + boxes[accountname].append(foldername) + +def write(): + # See if we're ready to write it out. + for account in accounts: + if account not in boxes: + return + + genmbnames() + +def genmbnames(): """Takes a configparser object and a boxlist, which is a list of hashes containing 'accountname' and 'foldername' keys.""" localeval = config.getlocaleval() @@ -31,9 +54,13 @@ def genmbnames(config, boxlist): if config.has_option("mbnames", "folderfilter"): folderfilter = localeval.eval(config.get("mbnames", "folderfilter"), {'re': re}) - itemlist = [localeval.eval(config.get("mbnames", "peritem", raw=1)) % item\ - for item in boxlist \ - if folderfilter(item['accountname'], item['foldername'])] + itemlist = [] + for accountname in boxes.keys(): + for foldername in boxes[accountname]: + if folderfilter(accountname, foldername): + itemlist.append(config.get("mbnames", "peritem", raw=1) % \ + {'accountname': accountname, + 'foldername': foldername}) file.write(localeval.eval(config.get("mbnames", "sep")).join(itemlist)) file.write(localeval.eval(config.get("mbnames", "footer"))) file.close() diff --git a/offlineimap/head/offlineimap/syncmaster.py b/offlineimap/head/offlineimap/syncmaster.py index 8aa65dc..4c720aa 100644 --- a/offlineimap/head/offlineimap/syncmaster.py +++ b/offlineimap/head/offlineimap/syncmaster.py @@ -38,9 +38,8 @@ def syncitall(accounts, config): currentThread().setExitMessage('SYNC_WITH_TIMER_TERMINATE') ui = UIBase.getglobalui() threads = threadutil.threadlist() - offlineimap.accounts.mailboxes = [] # Reset. + mbnames.init(config, accounts) for accountname in accounts: syncaccount(threads, config, accountname) # Wait for the threads to finish. threads.reset() - mbnames.genmbnames(config, offlineimap.accounts.mailboxes)