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:
parent
644b9f0bb9
commit
0752c123f5
@ -13,6 +13,7 @@ WIP (add new stuff for the next release)
|
|||||||
* Curses UI, don't use colors after we shut down curses already (C.Höger)
|
* Curses UI, don't use colors after we shut down curses already (C.Höger)
|
||||||
* Document that '%' needs encoding as '%%' in *.conf
|
* Document that '%' needs encoding as '%%' in *.conf
|
||||||
* Fix crash when IMAP.quickchanged() led to an Error (reported by sharat87)
|
* Fix crash when IMAP.quickchanged() led to an Error (reported by sharat87)
|
||||||
|
* Implement the createfolders setting to disable folder propagation (see docs)
|
||||||
|
|
||||||
OfflineIMAP v6.5.3.1 (2012-04-03)
|
OfflineIMAP v6.5.3.1 (2012-04-03)
|
||||||
=================================
|
=================================
|
||||||
|
@ -65,6 +65,22 @@ have filtered out everything starting with "debian" in your folderfilter
|
|||||||
settings.
|
settings.
|
||||||
|
|
||||||
|
|
||||||
|
createfolders
|
||||||
|
-------------
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
|
||||||
nametrans
|
nametrans
|
||||||
----------
|
----------
|
||||||
|
|
||||||
|
@ -504,6 +504,14 @@ remoteuser = username
|
|||||||
# one. For example:
|
# one. For example:
|
||||||
# folderincludes = ['debian.user', 'debian.personal']
|
# folderincludes = ['debian.user', 'debian.personal']
|
||||||
|
|
||||||
|
|
||||||
|
# If you do not want to have any folders created on this repository,
|
||||||
|
# set the createfolders variable to False, the default is True. Using
|
||||||
|
# this feature you can e.g. disable the propagation of new folders to
|
||||||
|
# the new repository.
|
||||||
|
#createfolders = True
|
||||||
|
|
||||||
|
|
||||||
# You can specify 'foldersort' to determine how folders are sorted.
|
# You can specify 'foldersort' to determine how folders are sorted.
|
||||||
# This affects order of synchronization and mbnames. The expression
|
# This affects order of synchronization and mbnames. The expression
|
||||||
# should return -1, 0, or 1, as the default Python cmp() does. The two
|
# should return -1, 0, or 1, as the default Python cmp() does. The two
|
||||||
|
@ -129,6 +129,13 @@ class BaseRepository(CustomConfig.ConfigHelperMixin, object):
|
|||||||
def getsep(self):
|
def getsep(self):
|
||||||
raise NotImplementedError
|
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):
|
def makefolder(self, foldername):
|
||||||
"""Create a new folder"""
|
"""Create a new folder"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
@ -147,6 +154,10 @@ class BaseRepository(CustomConfig.ConfigHelperMixin, object):
|
|||||||
that forward and backward nametrans actually match up!
|
that forward and backward nametrans actually match up!
|
||||||
Configuring nametrans on BOTH repositories therefore could lead
|
Configuring nametrans on BOTH repositories therefore could lead
|
||||||
to infinite folder creation cycles."""
|
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_repo = self
|
||||||
src_folders = src_repo.getfolders()
|
src_folders = src_repo.getfolders()
|
||||||
dst_folders = dst_repo.getfolders()
|
dst_folders = dst_repo.getfolders()
|
||||||
@ -166,7 +177,7 @@ class BaseRepository(CustomConfig.ConfigHelperMixin, object):
|
|||||||
# Find new folders on src_repo.
|
# Find new folders on src_repo.
|
||||||
for src_name_t, src_folder in src_hash.iteritems():
|
for src_name_t, src_folder in src_hash.iteritems():
|
||||||
# Don't create on dst_repo, if it is readonly
|
# Don't create on dst_repo, if it is readonly
|
||||||
if dst_repo.getconfboolean('readonly', False):
|
if not dst_repo.get_create_folders():
|
||||||
break
|
break
|
||||||
if src_folder.sync_this and not src_name_t in dst_folders:
|
if src_folder.sync_this and not src_name_t in dst_folders:
|
||||||
try:
|
try:
|
||||||
@ -181,7 +192,7 @@ class BaseRepository(CustomConfig.ConfigHelperMixin, object):
|
|||||||
status_repo.getsep()))
|
status_repo.getsep()))
|
||||||
# Find new folders on dst_repo.
|
# Find new folders on dst_repo.
|
||||||
for dst_name_t, dst_folder in dst_hash.iteritems():
|
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.
|
# Don't create missing folder on readonly repo.
|
||||||
break
|
break
|
||||||
|
|
||||||
|
@ -105,6 +105,7 @@ class TestBasicFunctions(unittest.TestCase):
|
|||||||
# Write out default config file again
|
# Write out default config file again
|
||||||
OLITestLib.write_config_file()
|
OLITestLib.write_config_file()
|
||||||
|
|
||||||
|
|
||||||
def test_04_createmail(self):
|
def test_04_createmail(self):
|
||||||
"""Create mail in OLItest 1, sync, wipe folder sync
|
"""Create mail in OLItest 1, sync, wipe folder sync
|
||||||
|
|
||||||
@ -127,3 +128,30 @@ class TestBasicFunctions(unittest.TestCase):
|
|||||||
self.assertFalse (None in uids, msg = "All mails should have been "+ \
|
self.assertFalse (None in uids, msg = "All mails should have been "+ \
|
||||||
"assigned the IMAP's UID number, but {} messages had no valid ID "\
|
"assigned the IMAP's UID number, but {} messages had no valid ID "\
|
||||||
.format(len([None for x in uids if x==None])))
|
.format(len([None for x in uids if x==None])))
|
||||||
|
|
||||||
|
def test_05_createfolders(self):
|
||||||
|
"""Test if createfolders works as expected
|
||||||
|
|
||||||
|
Create a local Maildir, then sync with remote "createfolders"
|
||||||
|
disabled. Delete local Maildir and sync. We should have no new
|
||||||
|
local maildir then. TODO: Rewrite this test to directly test
|
||||||
|
and count the remote folders when the helper functions have
|
||||||
|
been written"""
|
||||||
|
config = OLITestLib.get_default_config()
|
||||||
|
config.set('Repository IMAP', 'createfolders',
|
||||||
|
'False' )
|
||||||
|
OLITestLib.write_config_file(config)
|
||||||
|
|
||||||
|
# delete all remote and local testfolders
|
||||||
|
OLITestLib.delete_remote_testfolders()
|
||||||
|
OLITestLib.delete_maildir('')
|
||||||
|
OLITestLib.create_maildir('INBOX.OLItest')
|
||||||
|
code, res = OLITestLib.run_OLI()
|
||||||
|
#logging.warn("%s %s "% (code, res))
|
||||||
|
self.assertEqual(res, "")
|
||||||
|
OLITestLib.delete_maildir('INBOX.OLItest')
|
||||||
|
code, res = OLITestLib.run_OLI()
|
||||||
|
boxes, mails = OLITestLib.count_maildir_mails('')
|
||||||
|
self.assertTrue((boxes, mails)==(0,0), msg="Expected 0 folders and 0 "
|
||||||
|
"mails, but sync led to {} folders and {} mails".format(
|
||||||
|
boxes, mails))
|
||||||
|
Loading…
Reference in New Issue
Block a user