[PATCH] Implement true 1-way sync

Sebastian Spaeth Sebastian at SSpaeth.de
Sun Mar 27 20:55:44 BST 2011


This commit enables true 1-way syncing between repositories as has often
been demanded for backup purposes (where you do not want to cause
accidental modifications of your backup Maildir 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. One could
configure either the local or the remote repository as readonly (it
obviously does not make sense to have both readonly).

I considered alternatively to specify 1waysync=True as a config option
to the 'Account' section, but per-Repository configuration was easier to
implement and also makes sense.

Signed-off-by: Sebastian Spaeth <Sebastian at SSpaeth.de>
---
I know I shouldn't sent off patches that implement features after rc1,
but this one was so easy and had been requested before that I couldn't
resist. We can of course hold it back until after the release.

 Changelog.draft.rst     |    5 +++++
 offlineimap.conf        |   25 +++++++++++++++++++++++++
 offlineimap/accounts.py |   18 +++++++++++++-----
 3 files changed, 43 insertions(+), 5 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..1a02828 100644
--- a/offlineimap.conf
+++ b/offlineimap.conf
@@ -234,6 +234,15 @@ type = Maildir
 
 localfolders = ~/Test
 
+# Enable 1-way synchronization. When setting 'readonly' to True, this
+# repository will not be modified during a synchronization. This can be
+# used to backup an IMAP server when you do not want to accidentally
+# synchronizes changes in your local backup to the main IMAP
+# server. Setting both involved Repositories in a synchronization is
+# obviously not sensible.
+
+readonly = False
+
 # You can specify the "path separator character" used for your Maildir
 # folders.  This is inserted in-between the components of the tree.
 # It defaults to ".".  If you want your Maildir folders to be nested,
@@ -458,6 +467,14 @@ 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 a synchronization. This can be
+# used to backup an IMAP server when you do not want to accidentally
+# synchronizes changes in your local backup to the main IMAP
+# server. Setting both involved Repositories in a synchronization is
+# obviously not sensible.
+
+readonly = False
 
 [Repository GmailExample]
 
@@ -498,3 +515,11 @@ realdelete = no
 #
 # spamfolder = [Google Mail]/Spam
 
+# Enable 1-way synchronization. When setting 'readonly' to True, this
+# repository will not be modified during a synchronization. This can be
+# used to backup an IMAP server when you do not want to accidentally
+# synchronizes changes in your local backup to the main IMAP
+# server. Setting both involved Repositories in a synchronization is
+# obviously not sensible.
+
+readonly = False
diff --git a/offlineimap/accounts.py b/offlineimap/accounts.py
index 7edfa37..4599e15 100644
--- a/offlineimap/accounts.py
+++ b/offlineimap/accounts.py
@@ -349,12 +349,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