From 8ba17c5bd1610bcf242922841f9449618f9f461a Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Sun, 14 Aug 2011 13:38:13 +0200 Subject: [PATCH] add sync_this variable to all Folder() instances This variable shows if this folder should be synced or is disabled due to a folderfilter statement. This lets us distinguish between a non-existent folder and one that has been filtered out. Previously any filtered folder would simply appear to be non-existing. Signed-off-by: Sebastian Spaeth --- offlineimap/accounts.py | 16 +++++++++++++++- offlineimap/folder/Base.py | 2 ++ offlineimap/repository/IMAP.py | 12 +++++++----- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/offlineimap/accounts.py b/offlineimap/accounts.py index 5138523..13bb12e 100644 --- a/offlineimap/accounts.py +++ b/offlineimap/accounts.py @@ -274,6 +274,10 @@ class SyncableAccount(Account): # iterate through all folders on the remote repo and sync for remotefolder in remoterepos.getfolders(): + if not remotefolder.sync_this: + self.ui.debug('', "Not syncing filtered remote folder '%s'" + "[%s]" % (remotefolder, remoterepos)) + continue # Filtered out remote folder thread = InstanceLimitedThread(\ instancename = 'FOLDER_' + self.remoterepos.getname(), target = syncfolder, @@ -323,7 +327,9 @@ class SyncableAccount(Account): def syncfolder(accountname, remoterepos, remotefolder, localrepos, statusrepos, quick): """This function is called as target for the - InstanceLimitedThread invokation in SyncableAccount.""" + InstanceLimitedThread invokation in SyncableAccount. + + Filtered folders on the remote side will not invoke this function.""" ui = getglobalui() ui.registerthread(accountname) try: @@ -331,6 +337,14 @@ def syncfolder(accountname, remoterepos, remotefolder, localrepos, localfolder = localrepos.\ getfolder(remotefolder.getvisiblename().\ replace(remoterepos.getsep(), localrepos.getsep())) + + #Filtered folders on the remote side will not invoke this + #function, but we need to NOOP if the local folder is filtered + #out too: + if not localfolder.sync_this: + ui.debug('', "Not syncing filtered local folder '%s'" \ + % localfolder) + return # Write the mailboxes mbnames.add(accountname, localfolder.getvisiblename()) diff --git a/offlineimap/folder/Base.py b/offlineimap/folder/Base.py index c8ed108..3cfb18f 100644 --- a/offlineimap/folder/Base.py +++ b/offlineimap/folder/Base.py @@ -33,6 +33,8 @@ class BaseFolder(object): :para name: Path & name of folder minus root or reference :para repository: Repository() in which the folder is. """ + self.sync_this = True + """Should this folder be included in syncing?""" self.ui = getglobalui() self.name = name self.repository = repository diff --git a/offlineimap/repository/IMAP.py b/offlineimap/repository/IMAP.py index 7392655..3bd7300 100644 --- a/offlineimap/repository/IMAP.py +++ b/offlineimap/repository/IMAP.py @@ -295,12 +295,14 @@ class IMAPRepository(BaseRepository): if '\\noselect' in flaglist: continue foldername = imaputil.dequote(name) - if not self.folderfilter(foldername): - self.ui.debug('imap',"Filtering out '%s' due to folderfilter" %\ - foldername) - continue retval.append(self.getfoldertype()(self.imapserver, foldername, self)) + # filter out the folder? + if not self.folderfilter(foldername): + self.ui.debug('imap', "Filtering out '%s'[%s] due to folderfilt" + "er" % (foldername, self)) + retval[-1].sync_this = False + # Add all folderincludes if len(self.folderincludes): imapobj = self.imapserver.acquireconnection() try: @@ -322,7 +324,7 @@ class IMAPRepository(BaseRepository): retval.sort(lambda x, y: self.foldersort(x.getvisiblename(), y.getvisiblename())) self.folders = retval - return retval + return self.folders def makefolder(self, foldername): #if self.getreference() != '""':