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 <Sebastian@SSpaeth.de>
This commit is contained in:
Dave Abrahams 2012-09-01 02:30:46 +02:00 committed by Sebastian Spaeth
parent e7ca5b25cb
commit e94642bb4d
3 changed files with 15 additions and 8 deletions

View File

@ -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."""

View File

@ -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))

View File

@ -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()