[PATCH v2] True 1-way sync

Sebastian Spaeth Sebastian at SSpaeth.de
Tue Mar 29 01:33:18 BST 2011


This commit enables true 1-way syncing between repositories. This has
often been demanded for backup purposes where you do not want to cause
accidental modifications of your backup to mess up the main IMAP
server.

This has been implemented by allowing to configure a Repository as
'readonly'. It will then not be changed during the sync. For most use
cases users will want to set the remote repository to read-only,
although the local one could be set readonly too. (If both are set
read-only, the sync will not modify anything)

Signed-off-by: Sebastian Spaeth <Sebastian at SSpaeth.de>
---
Adressed Nicolas comments. We log the localrepository debug() statement
now to category 'maildir' although it could be an UIDMapped server too.

 Changelog.draft.rst     |    5 +++++
 offlineimap.conf        |   16 ++++++++++++++--
 offlineimap/accounts.py |   24 +++++++++++++++++-------
 3 files changed, 36 insertions(+), 9 deletions(-)

diff --git a/Changelog.draft.rst b/Changelog.draft.rst
index 79006fd..c4fae4e 100644
--- a/Changelog.draft.rst
+++ b/Changelog.draft.rst
@@ -13,6 +13,11 @@ others.
 New Features
 ------------
 
+* Enable 1-way synchronization by settting a [Repository ...] to
+  readonly = True. When using offlineimap for backup purposes you can
+  thus make sure that no changes in your backup trickle back into the
+  main IMAP server.
+
 Changes
 -------
 
diff --git a/offlineimap.conf b/offlineimap.conf
index c0ff8d7..cb9bf97 100644
--- a/offlineimap.conf
+++ b/offlineimap.conf
@@ -1,6 +1,5 @@
 # Sample configuration file
-# Copyright (C) 2002-2005 John Goerzen
-# <jgoerzen at complete.org>
+# Copyright (C) 2002-2011 John Goerzen & contributors
 #
 #    This program is free software; you can redistribute it and/or modify
 #    it under the terms of the GNU General Public License as published by
@@ -458,6 +457,17 @@ subscribedonly = no
 #
 # foldersort = lambda x, y: -cmp(x, y)
 
+# Enable 1-way synchronization. When setting 'readonly' to True, this
+# repository will not be modified during synchronization. This can be
+# used to backup an IMAP server when you do not want to accidentally
+# synchronize changes made to your local backup to the main IMAP
+# server. The readonly setting can be applied to any type of
+# Repository. If you set both the local and remote Repository of an
+# account to readonly, the synchronization will not change anything, so
+# you will most of the time only want to set the remote repository
+# readonly.
+
+readonly = False
 
 [Repository GmailExample]
 
@@ -498,3 +508,5 @@ realdelete = no
 #
 # spamfolder = [Google Mail]/Spam
 
+# Enable 1-way synchronization. See above for explanation.
+readonly = False
diff --git a/offlineimap/accounts.py b/offlineimap/accounts.py
index 7edfa37..e39a72e 100644
--- a/offlineimap/accounts.py
+++ b/offlineimap/accounts.py
@@ -242,8 +242,10 @@ class SyncableAccount(Account):
             remoterepos = self.remoterepos
             localrepos = self.localrepos
             statusrepos = self.statusrepos
-            self.ui.syncfolders(remoterepos, localrepos)
-            remoterepos.syncfoldersto(localrepos, [statusrepos])
+            # replicate the folderstructure from REMOTE to LOCAL
+            if not localrepos.getconf('readonly', False):
+                self.ui.syncfolders(remoterepos, localrepos)
+                remoterepos.syncfoldersto(localrepos, [statusrepos])
 
             siglistener.addfolders(remoterepos.getfolders(), bool(self.refreshperiod), quick)
 
@@ -349,12 +351,20 @@ def syncfolder(accountname, remoterepos, remotefolder, localrepos,
                              remotefolder.getmessagecount())
 
         # Synchronize remote changes.
-        ui.syncingmessages(remoterepos, remotefolder, localrepos, localfolder)
-        remotefolder.syncmessagesto(localfolder, statusfolder)
+        if not localrepos.getconf('readonly', False):
+            ui.syncingmessages(remoterepos, remotefolder, localrepos, localfolder)
+            remotefolder.syncmessagesto(localfolder, statusfolder)
+        else:
+            ui.debug('imap',"Not syncing to read-only repository '%s'" \
+                         % localrepos.getname())
+        
         # Synchronize local changes
-        ui.syncingmessages(localrepos, localfolder, remoterepos, remotefolder)
-        localfolder.syncmessagesto(remotefolder, statusfolder)
-
+        if not remoterepos.getconf('readonly', False):
+            ui.syncingmessages(localrepos, localfolder, remoterepos, remotefolder)
+            localfolder.syncmessagesto(remotefolder, statusfolder)
+        else:
+            ui.debug('imap',"Not syncing to read-only repository '%s'" \
+                         % remoterepos.getname())
 
         statusfolder.save()
         localrepos.restore_atime()
-- 
1.7.1





More information about the OfflineIMAP-project mailing list