avoid removing of data when user removed a maildir
When a maildir is removed it must be considered new for the sync. However, the local cache of the folder remains. This means the sync of the folder removes all the missing emails. Avoid loosing of data for users not aware of the local cache by removing any pre-existing status cache of a folder when we actually want to create the database. Improve style. Github-fix: https://github.com/OfflineIMAP/offlineimap/issues/333 Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
# Base repository support
|
||||
# Copyright (C) 2002-2015 John Goerzen & contributors
|
||||
# Copyright (C) 2002-2016 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
|
||||
@ -222,12 +222,13 @@ class BaseRepository(CustomConfig.ConfigHelperMixin, object):
|
||||
"') as it would be filtered out on that repository."%
|
||||
(dst_name_t, self))
|
||||
continue
|
||||
# get IMAPFolder and see if the reverse nametrans
|
||||
# Get IMAPFolder and see if the reverse nametrans
|
||||
# works fine TODO: getfolder() works only because we
|
||||
# succeed in getting inexisting folders which I would
|
||||
# like to change. Take care!
|
||||
folder = self.getfolder(dst_name_t)
|
||||
# apply reverse nametrans to see if we end up with the same name
|
||||
# Apply reverse nametrans to see if we end up with the same
|
||||
# name.
|
||||
newdst_name = folder.getvisiblename().replace(
|
||||
src_repo.getsep(), dst_repo.getsep())
|
||||
if dst_folder.name != newdst_name:
|
||||
@ -239,13 +240,14 @@ class BaseRepository(CustomConfig.ConfigHelperMixin, object):
|
||||
"itories so they lead to identical names if applied bac"
|
||||
"k and forth. 2) Use folderfilter settings on a reposit"
|
||||
"ory to prevent some folders from being created on the "
|
||||
"other side." % (dst_folder.name, dst_repo, dst_name_t,
|
||||
src_repo, newdst_name),
|
||||
OfflineImapError.ERROR.REPO)
|
||||
# end sanity check, actually create the folder
|
||||
"other side."%
|
||||
(dst_folder.name, dst_repo, dst_name_t,
|
||||
src_repo, newdst_name),
|
||||
OfflineImapError.ERROR.REPO)
|
||||
# End sanity check, actually create the folder.
|
||||
try:
|
||||
src_repo.makefolder(dst_name_t)
|
||||
src_haschanged = True # Need to refresh list
|
||||
src_haschanged = True # Need to refresh list.
|
||||
except OfflineImapError as e:
|
||||
self.ui.error(e, exc_info()[2], "Creating folder %s on "
|
||||
"repository %s" % (dst_name_t, src_repo))
|
||||
@ -255,7 +257,7 @@ class BaseRepository(CustomConfig.ConfigHelperMixin, object):
|
||||
# Find deleted folders.
|
||||
# TODO: We don't delete folders right now.
|
||||
|
||||
#Forget old list of cached folders so we get new ones if needed
|
||||
# Forget old list of cached folders so we get new ones if needed.
|
||||
if src_haschanged:
|
||||
self.forgetfolders()
|
||||
if dst_haschanged:
|
||||
|
@ -1,5 +1,5 @@
|
||||
# Local status cache repository support
|
||||
# Copyright (C) 2002-2015 John Goerzen & contributors
|
||||
# Copyright (C) 2002-2016 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
|
||||
@ -61,15 +61,15 @@ class LocalStatusRepository(BaseRepository):
|
||||
|
||||
def import_other_backend(self, folder):
|
||||
for bk, dic in self.backends.items():
|
||||
# skip folder's own type
|
||||
# Skip folder's own type.
|
||||
if dic['class'] == type(folder):
|
||||
continue
|
||||
|
||||
repobk = LocalStatusRepository(self.name, self.account)
|
||||
repobk.setup_backend(bk) # fake the backend
|
||||
repobk.setup_backend(bk) # Fake the backend.
|
||||
folderbk = dic['class'](folder.name, repobk)
|
||||
|
||||
# if backend contains data, import it to folder.
|
||||
# If backend contains data, import it to folder.
|
||||
if not folderbk.isnewfolder():
|
||||
self.ui._msg("Migrating LocalStatus cache from %s to %s "
|
||||
"status folder for %s:%s"%
|
||||
@ -87,10 +87,14 @@ class LocalStatusRepository(BaseRepository):
|
||||
"""Create a LocalStatus Folder."""
|
||||
|
||||
if self.account.dryrun:
|
||||
return # bail out in dry-run mode
|
||||
return # Bail out in dry-run mode.
|
||||
|
||||
# Create an empty StatusFolder
|
||||
# Create an empty StatusFolder.
|
||||
folder = self._instanciatefolder(foldername)
|
||||
# First delete any existing data to make sure we won't consider obsolete
|
||||
# data. This might happen if the user removed the folder (maildir) and
|
||||
# it is re-created afterwards.
|
||||
folder.purge()
|
||||
folder.save()
|
||||
folder.closefiles()
|
||||
|
||||
|
Reference in New Issue
Block a user