From e94642bb4d591a1ea12b837daeaafb94076a9f0b Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Sat, 1 Sep 2012 02:30:46 +0200 Subject: [PATCH] Determine folder syncing on Folder initialization Rather than later when retrieving them by IMAP, we determine the "sync_this" value of a folder on Folder() initialization. This also fixes a bug where folder structure was not propagated when a folder was filtered out but included in the folderincludes list. Patch by Dave, split and modified slightly by Sebastian Signed-off-by: Sebastian Spaeth --- offlineimap/folder/Base.py | 12 ++++++++++-- offlineimap/repository/Base.py | 6 +++++- offlineimap/repository/IMAP.py | 5 ----- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/offlineimap/folder/Base.py b/offlineimap/folder/Base.py index b1f5a56..c132713 100644 --- a/offlineimap/folder/Base.py +++ b/offlineimap/folder/Base.py @@ -31,9 +31,12 @@ 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() + """Should this folder be included in syncing?""" + self._sync_this = repository.should_sync_folder(name) + if not self._sync_this: + self.ui.debug('', "Filtering out '%s'[%s] due to folderfilter" \ + % (name, repository)) # Top level dir name is always '' self.name = name if not name == self.getsep() else '' self.repository = repository @@ -57,6 +60,11 @@ class BaseFolder(object): """Account name as string""" return self.repository.accountname + @property + def sync_this(self): + """Should this folder be synced or is it e.g. filtered out?""" + return self._sync_this + def suggeststhreads(self): """Returns true if this folder suggests using threads for actions; false otherwise. Probably only IMAP will return true.""" diff --git a/offlineimap/repository/Base.py b/offlineimap/repository/Base.py index 0c41c2d..575c993 100644 --- a/offlineimap/repository/Base.py +++ b/offlineimap/repository/Base.py @@ -129,6 +129,10 @@ class BaseRepository(CustomConfig.ConfigHelperMixin, object): def getsep(self): raise NotImplementedError + def should_sync_folder(self, fname): + """Should this folder be synced?""" + return fname in self.folderincludes or self.folderfilter(fname) + def get_create_folders(self): """Is folder creation enabled on this repository? @@ -202,7 +206,7 @@ class BaseRepository(CustomConfig.ConfigHelperMixin, object): # Does nametrans back&forth lead to identical names? # 1) would src repo filter out the new folder name? In this # case don't create it on it: - if not self.folderfilter(dst_name_t): + if not self.should_sync_folder(dst_name_t): self.ui.debug('', "Not creating folder '%s' (repository '%s" "') as it would be filtered out on that repository." % (dst_name_t, self)) diff --git a/offlineimap/repository/IMAP.py b/offlineimap/repository/IMAP.py index 5ad787a..be8c858 100644 --- a/offlineimap/repository/IMAP.py +++ b/offlineimap/repository/IMAP.py @@ -287,11 +287,6 @@ class IMAPRepository(BaseRepository): foldername = imaputil.dequote(name) 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()