Permalink
Browse files

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>
  • Loading branch information...
1 parent 644b9f0 commit 0752c123f518a10b0dfe0786248dfe2af1c8f603 @spaetz committed May 8, 2012
Showing with 66 additions and 2 deletions.
  1. +1 −0 Changelog.rst
  2. +16 −0 docs/doc-src/nametrans.rst
  3. +8 −0 offlineimap.conf
  4. +13 −2 offlineimap/repository/Base.py
  5. +28 −0 test/tests/test_01_basic.py
View
@@ -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)
* Document that '%' needs encoding as '%%' in *.conf
* 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)
=================================
View
@@ -65,6 +65,22 @@ have filtered out everything starting with "debian" in your folderfilter
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
----------
View
@@ -504,6 +504,14 @@ remoteuser = username
# one. For example:
# 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.
# This affects order of synchronization and mbnames. The expression
# should return -1, 0, or 1, as the default Python cmp() does. The two
@@ -129,6 +129,13 @@ def forgetfolders(self):
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 @@ def sync_folder_structure(self, dst_repo, status_repo):
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 @@ def sync_folder_structure(self, dst_repo, status_repo):
# 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 @@ def sync_folder_structure(self, dst_repo, status_repo):
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
@@ -105,6 +105,7 @@ def test_03_nametransmismatch(self):
# Write out default config file again
OLITestLib.write_config_file()
+
def test_04_createmail(self):
"""Create mail in OLItest 1, sync, wipe folder sync
@@ -127,3 +128,30 @@ def test_04_createmail(self):
self.assertFalse (None in uids, msg = "All mails should have been "+ \
"assigned the IMAP's UID number, but {} messages had no valid ID "\
.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))

0 comments on commit 0752c12

Please sign in to comment.