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:
parent
e7ca5b25cb
commit
e94642bb4d
@ -31,9 +31,12 @@ class BaseFolder(object):
|
|||||||
:para name: Path & name of folder minus root or reference
|
:para name: Path & name of folder minus root or reference
|
||||||
:para repository: Repository() in which the folder is.
|
:para repository: Repository() in which the folder is.
|
||||||
"""
|
"""
|
||||||
self.sync_this = True
|
|
||||||
"""Should this folder be included in syncing?"""
|
|
||||||
self.ui = getglobalui()
|
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 ''
|
# Top level dir name is always ''
|
||||||
self.name = name if not name == self.getsep() else ''
|
self.name = name if not name == self.getsep() else ''
|
||||||
self.repository = repository
|
self.repository = repository
|
||||||
@ -57,6 +60,11 @@ class BaseFolder(object):
|
|||||||
"""Account name as string"""
|
"""Account name as string"""
|
||||||
return self.repository.accountname
|
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):
|
def suggeststhreads(self):
|
||||||
"""Returns true if this folder suggests using threads for actions;
|
"""Returns true if this folder suggests using threads for actions;
|
||||||
false otherwise. Probably only IMAP will return true."""
|
false otherwise. Probably only IMAP will return true."""
|
||||||
|
@ -129,6 +129,10 @@ class BaseRepository(CustomConfig.ConfigHelperMixin, object):
|
|||||||
def getsep(self):
|
def getsep(self):
|
||||||
raise NotImplementedError
|
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):
|
def get_create_folders(self):
|
||||||
"""Is folder creation enabled on this repository?
|
"""Is folder creation enabled on this repository?
|
||||||
|
|
||||||
@ -202,7 +206,7 @@ class BaseRepository(CustomConfig.ConfigHelperMixin, object):
|
|||||||
# Does nametrans back&forth lead to identical names?
|
# Does nametrans back&forth lead to identical names?
|
||||||
# 1) would src repo filter out the new folder name? In this
|
# 1) would src repo filter out the new folder name? In this
|
||||||
# case don't create it on it:
|
# 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"
|
self.ui.debug('', "Not creating folder '%s' (repository '%s"
|
||||||
"') as it would be filtered out on that repository." %
|
"') as it would be filtered out on that repository." %
|
||||||
(dst_name_t, self))
|
(dst_name_t, self))
|
||||||
|
@ -287,11 +287,6 @@ class IMAPRepository(BaseRepository):
|
|||||||
foldername = imaputil.dequote(name)
|
foldername = imaputil.dequote(name)
|
||||||
retval.append(self.getfoldertype()(self.imapserver, foldername,
|
retval.append(self.getfoldertype()(self.imapserver, foldername,
|
||||||
self))
|
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
|
# Add all folderincludes
|
||||||
if len(self.folderincludes):
|
if len(self.folderincludes):
|
||||||
imapobj = self.imapserver.acquireconnection()
|
imapobj = self.imapserver.acquireconnection()
|
||||||
|
Loading…
Reference in New Issue
Block a user