diff --git a/Changelog.draft.rst b/Changelog.draft.rst index ed3a14e..ff559a0 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 e.g. 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 7018090..f8506b2 100644 --- a/offlineimap.conf +++ b/offlineimap.conf @@ -1,6 +1,5 @@ # Sample configuration file -# Copyright (C) 2002-2005 John Goerzen -# +# 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 @@ -67,13 +66,14 @@ maxsyncaccounts = 1 ui = Blinkenlights -# If you try to synchronize messages to a read-only folder, -# OfflineIMAP will generate a warning. If you want to suppress these -# warnings, set ignore-readonly to yes. Read-only IMAP folders allow -# reading but not modification, so if you try to change messages in -# the local copy of such a folder, the IMAP server will prevent -# OfflineIMAP from propagating those changes to the IMAP server. - +# If you try to synchronize messages to a folder which the IMAP server +# considers read-only, OfflineIMAP will generate a warning. If you want +# to suppress these warnings, set ignore-readonly to yes. Read-only +# IMAP folders allow reading but not modification, so if you try to +# change messages in the local copy of such a folder, the IMAP server +# will prevent OfflineIMAP from propagating those changes to the IMAP +# server. Note that ignore-readonly is unrelated to the "readonly" +# setting which prevents a repository from being modified at all. ignore-readonly = no ########## Advanced settings @@ -469,6 +469,11 @@ 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. Use to +# e.g. backup an IMAP server. The readonly setting can be applied to any +# type of Repository (Maildir, Imap, etc). +readonly = False [Repository GmailExample] @@ -509,3 +514,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 c366810..0b71377 100644 --- a/offlineimap/accounts.py +++ b/offlineimap/accounts.py @@ -260,8 +260,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) @@ -374,12 +376,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('', "Not syncing to read-only repository '%s'" \ + % remoterepos.getname()) statusfolder.save() localrepos.restore_atime()