[PATCH] Re: Implement true 1-way sync

Nicolas Sebrecht nicolas.s-dev at laposte.net
Mon Mar 28 16:45:50 BST 2011


On Sun, Mar 27, 2011 at 09:55:44PM +0200, Sebastian Spaeth wrote:
> 
> 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.

This ยง should be removed.

(
  Oh, and I agree on the per-Repository configuration rather than a
  config option to the Account section even if not for the same reason.
  I'm much more sensible about the user-friendliness rather than the
  implementation POV, here.
)

> 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.

It could be for the next stable if merged before -rc2.

> 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.

Hugh? You said "either local or remote" in the commit message.

> 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.

Ditto.

>            Setting both involved Repositories in a synchronization is
> +# obviously not sensible.

Didn't know that. No, seriously, users rather want to know what will
happen.

> +
> +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

Why the f**k do we need the same documentation 3 times in the same file?
At least, make the text generic enough and refer to the same
explanation.

> 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())

Should really both string refer to 'imap' type?

-- 
Nicolas Sebrecht




More information about the OfflineIMAP-project mailing list