Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Create new folders on srcrepo if needed

This will ignore any nametrans rules, so we might want to limit this
only to cases where no nametrans has been specified, or we might want to
use the nametrans setting of the dest repo.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
  • Loading branch information...
commit fd6261a50f039c21895d4fa9780d00bd0db19474 1 parent 6b2ec95
@spaetz spaetz authored
Showing with 49 additions and 20 deletions.
  1. +7 −0 Changelog.draft.rst
  2. +42 −20 offlineimap/repository/Base.py
View
7 Changelog.draft.rst
@@ -24,6 +24,13 @@ New Features
attempt a plaintext login but the server has explicitly disabled
plaintext logins rather than crashing.
+* Folders will now also be automatically created on the REMOTE side of
+ an account if they exist on the local side. Use the folderfilters
+ setting on the local side to prevent some folders from migrating to
+ the remote side. Also, if you have a nametrans setting on the remote
+ repository, you might need a nametrans setting on the local repository
+ that leads to the original name (reverse nametrans).
+
Changes
-------
View
62 offlineimap/repository/Base.py
@@ -19,8 +19,10 @@
import re
import os.path
import traceback
+from sys import exc_info
from offlineimap import CustomConfig
from offlineimap.ui import getglobalui
+from offlineimap.error import OfflineImapError
class BaseRepository(object, CustomConfig.ConfigHelperMixin):
@@ -134,7 +136,11 @@ def getfolder(self, foldername):
def syncfoldersto(self, dst_repo, status_repo):
"""Syncs the folders in this repository to those in dest.
- It does NOT sync the contents of those folders."""
+ It does NOT sync the contents of those folders. nametrans rules
+ in both directions will be honored, but there are NO checks yet
+ that forward and backward nametrans actually match up!
+ Configuring nametrans on BOTH repositories therefore could lead
+ to infinite folder creation cycles."""
src_repo = self
src_folders = src_repo.getfolders()
dst_folders = dst_repo.getfolders()
@@ -149,31 +155,47 @@ def syncfoldersto(self, dst_repo, status_repo):
for folder in dst_folders:
dst_hash[folder.getvisiblename()] = folder
- #
- # Find new folders.
- for key in src_hash.keys():
- if not key in dst_hash:
+ # Find new folders on src_repo.
+ for src_name, src_folder in src_hash.iteritems():
+ if src_folder.sync_this and not src_name in dst_hash:
try:
- dst_repo.makefolder(key)
- status_repo.makefolder(key.replace(dst_repo.getsep(),
- status_repo.getsep()))
- except (KeyboardInterrupt):
+ dst_repo.makefolder(src_name)
+ except OfflineImapError, e:
+ self.ui.error(e, exc_info()[2],
+ "Creating folder %s on repository %s" %\
+ (src_name, dst_repo))
raise
- except:
- self.ui.warn("ERROR Attempting to create folder " \
- + key + ":" +traceback.format_exc())
+ status_repo.makefolder(src_name.replace(dst_repo.getsep(),
+ status_repo.getsep()))
+ # Find new folders on dst_repo.
+ for dst_name, dst_folder in dst_hash.iteritems():
+ if dst_folder.sync_this and not dst_name in src_hash:
+ # Check that back&forth nametrans lead to identical names
+ #src_name is the unmodified full src_name
+ newsrc_name = dst_name.replace(dst_repo.getsep(),
+ src_repo.getsep())
+ folder = self.getfolder(newsrc_name)
+ newdst_name = folder.getvisiblename().replace(
+ src_repo.getsep(), dst_repo.getsep())
+ if newsrc_name == newdst_name:
+ assert False, "newdstname %s equals newsrcname %s %s %s" % (newdst_name, newsrc_name, dst_name, folder)
+ else:
+ assert False, "newdstname %s Does not equal newsrcname %s %s %s" % (newdst_name, newsrc_name, dst_name, folder)
+ # end sanity check, actually create the folder
- #
+ try:
+ src_repo.makefolder(dst_name.replace(
+ dst_repo.getsep(), src_repo.getsep()))
+ except OfflineImapError, e:
+ self.ui.error(e, exc_info()[2],
+ "Creating folder %s on repository %s" %\
+ (src_name, dst_repo))
+ raise
+ status_repo.makefolder(dst_name.replace(
+ dst_repo.getsep(), status_repo.getsep()))
# Find deleted folders.
- #
# We don't delete folders right now.
- #for key in desthash.keys():
- # if not key in srchash:
- # dest.deletefolder(key)
-
- ##### Keepalive
-
def startkeepalive(self):
"""The default implementation will do nothing."""
pass
Please sign in to comment.
Something went wrong with that request. Please try again.