Implement the "createfolders" setting for repositories
By default OfflineImap propagates new folders in both directions. Sometimes this is not what you want. E.g. you might want new folders on your IMAP server to propagate to your local MailDir, but not the other way around. The 'readonly' setting on a repository will not help here, as it prevents any change from occuring on that repository. This is what the `createfolders` setting is for. By default it is `True`, meaning that new folders can be created on this repository. To prevent folders from ever being created on a repository, set this to `False`. If you set this to False on the REMOTE repository, you will not have to create the `Reverse nametrans`_ rules on the LOCAL repository. Also implement a test for this Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
This commit is contained in:
@ -129,6 +129,13 @@ class BaseRepository(CustomConfig.ConfigHelperMixin, object):
|
||||
def getsep(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def get_create_folders(self):
|
||||
"""Is folder creation enabled on this repository?
|
||||
|
||||
It is disabled by either setting the whole repository
|
||||
'readonly' or by using the 'createfolders' setting."""
|
||||
return self._readonly or self.getconfboolean('createfolders', True)
|
||||
|
||||
def makefolder(self, foldername):
|
||||
"""Create a new folder"""
|
||||
raise NotImplementedError
|
||||
@ -147,6 +154,10 @@ class BaseRepository(CustomConfig.ConfigHelperMixin, object):
|
||||
that forward and backward nametrans actually match up!
|
||||
Configuring nametrans on BOTH repositories therefore could lead
|
||||
to infinite folder creation cycles."""
|
||||
if not self.get_create_folders() and not dst_repo.get_create_folders():
|
||||
# quick exit if no folder creation is enabled on either side.
|
||||
return
|
||||
|
||||
src_repo = self
|
||||
src_folders = src_repo.getfolders()
|
||||
dst_folders = dst_repo.getfolders()
|
||||
@ -166,7 +177,7 @@ class BaseRepository(CustomConfig.ConfigHelperMixin, object):
|
||||
# Find new folders on src_repo.
|
||||
for src_name_t, src_folder in src_hash.iteritems():
|
||||
# Don't create on dst_repo, if it is readonly
|
||||
if dst_repo.getconfboolean('readonly', False):
|
||||
if not dst_repo.get_create_folders():
|
||||
break
|
||||
if src_folder.sync_this and not src_name_t in dst_folders:
|
||||
try:
|
||||
@ -181,7 +192,7 @@ class BaseRepository(CustomConfig.ConfigHelperMixin, object):
|
||||
status_repo.getsep()))
|
||||
# Find new folders on dst_repo.
|
||||
for dst_name_t, dst_folder in dst_hash.iteritems():
|
||||
if self.getconfboolean('readonly', False):
|
||||
if not src_repo.get_create_folders():
|
||||
# Don't create missing folder on readonly repo.
|
||||
break
|
||||
|
||||
|
Reference in New Issue
Block a user