[PATCH 4/8] Create new folders on srcrepo if needed
Sebastian Spaeth
Sebastian at SSpaeth.de
Mon Aug 29 15:00:13 BST 2011
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 at SSpaeth.de>
---
Changelog.draft.rst | 5 +++-
offlineimap/repository/Base.py | 51 +++++++++++++++++++++++----------------
2 files changed, 34 insertions(+), 22 deletions(-)
diff --git a/Changelog.draft.rst b/Changelog.draft.rst
index 74b6368..a116553 100644
--- a/Changelog.draft.rst
+++ b/Changelog.draft.rst
@@ -16,7 +16,10 @@ New Features
* When a message upload/download fails, we do not abort the whole folder
synchronization, but only skip that message, informing the user at the
end of the sync run.
-
+
+* Folders will now also be automatically created on the REMOTE side of
+ an account if they exist on the local side.
+
Changes
-------
diff --git a/offlineimap/repository/Base.py b/offlineimap/repository/Base.py
index 184bc9a..5c54afc 100644
--- a/offlineimap/repository/Base.py
+++ b/offlineimap/repository/Base.py
@@ -18,8 +18,10 @@
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):
def __init__(self, reposname, account):
@@ -117,7 +119,11 @@ class BaseRepository(object, CustomConfig.ConfigHelperMixin):
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()
@@ -132,31 +138,34 @@ class BaseRepository(object, CustomConfig.ConfigHelperMixin):
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:
+ 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
--
1.7.4.1
More information about the OfflineIMAP-project
mailing list