Skip to content

Commit

Permalink
mbnames: don't duplicate entries in autorefresh mode
Browse files Browse the repository at this point in the history
mbnames is initialized and written once in the run from OfflineImap.__sync().

However, the in-memory instance is fed with data at sync time for each folder
and the intermediate files are written as soon as all the folders are synced for
the account. All of this is done inside the SyncableAccount.__sync() method
while the syncrunner is looping on this.

This means that we duplicate entries for mbnames in each loop (most likely when
autorefresh is enabled).

It is wrong to have duplicates in mbnames for each account. Ignore duplicates
when adding data in the mbnames intermediate files.

Github-ref: OfflineIMAP#467
Reported-by: Shin Kojima <shin@kojima.org>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
  • Loading branch information
nicolas33 committed May 18, 2017
1 parent ddf2df1 commit f876205
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions offlineimap/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,9 @@ def get_local_folder(self, remotefolder):
remotefolder.getvisiblename().
replace(self.remoterepos.getsep(), self.localrepos.getsep()))


# The syncrunner will loop on this method. This means it is called more than
# once during the run.
def __sync(self):
"""Synchronize the account once, then return.
Expand Down
8 changes: 7 additions & 1 deletion offlineimap/mbnames.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
_mbnames = None


# Called at sync time for each folder.
def add(accountname, folder_root, foldername):
global _mbnames
if _mbnames.is_enabled() is not True:
Expand All @@ -41,12 +42,14 @@ def add(accountname, folder_root, foldername):
_mbnames.addAccountFolder(accountname, folder_root, foldername)


# Called once.
def init(conf, ui, dry_run):
global _mbnames
if _mbnames is None:
_mbnames = _Mbnames(conf, ui, dry_run)


# Called once.
def prune(accounts):
global _mbnames
if _mbnames.is_enabled() is True:
Expand All @@ -55,6 +58,7 @@ def prune(accounts):
_mbnames.pruneAll()


# Called once.
def write():
"""Write the mbnames file."""

Expand All @@ -66,6 +70,7 @@ def write():
_mbnames.write()


# Called as soon as all the folders are synced for the account.
def writeIntermediateFile(accountname):
"""Write intermediate mbnames file."""

Expand Down Expand Up @@ -93,7 +98,8 @@ def __init__(self, accountname, folder_root, mbnamesdir, folderfilter,
self._dryrun = dry_run

def add(self, foldername):
self._foldernames.append(foldername)
if foldername not in self._foldernames:
self._foldernames.append(foldername)

def get_folder_root(self):
return self._folder_root
Expand Down

0 comments on commit f876205

Please sign in to comment.