Combine checks for ignored folders in one place

- Factor out the code to find a local folder given a remote folder

Patch by Dave, split and modified by Sebastian.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
This commit is contained in:
Dave Abrahams 2012-09-01 02:16:06 +02:00 committed by Sebastian Spaeth
parent 1b54b85f20
commit e7ca5b25cb

View File

@ -261,6 +261,12 @@ class SyncableAccount(Account):
if looping and self.sleeper() >= 2: if looping and self.sleeper() >= 2:
looping = 0 looping = 0
def get_local_folder(self, remotefolder):
"""Return the corresponding local folder for a given remotefolder"""
return self.localrepos.getfolder(
remotefolder.getvisiblename().
replace(self.remoterepos.getsep(), self.localrepos.getsep()))
def sync(self): def sync(self):
"""Synchronize the account once, then return """Synchronize the account once, then return
@ -305,10 +311,13 @@ class SyncableAccount(Account):
for remotefolder in remoterepos.getfolders(): for remotefolder in remoterepos.getfolders():
# check for CTRL-C or SIGTERM # check for CTRL-C or SIGTERM
if Account.abort_NOW_signal.is_set(): break if Account.abort_NOW_signal.is_set(): break
if not remotefolder.sync_this:
self.ui.debug('', "Not syncing filtered remote folder '%s'" localfolder = self.get_local_folder(remotefolder)
if not (remotefolder.sync_this
and localfolder.sync_this):
self.ui.debug('', "Not syncing filtered folder '%s'"
"[%s]" % (remotefolder, remoterepos)) "[%s]" % (remotefolder, remoterepos))
continue # Filtered out remote folder continue # Ignore filtered folder
thread = InstanceLimitedThread(\ thread = InstanceLimitedThread(\
instancename = 'FOLDER_' + self.remoterepos.getname(), instancename = 'FOLDER_' + self.remoterepos.getname(),
target = syncfolder, target = syncfolder,
@ -372,17 +381,8 @@ def syncfolder(account, remotefolder, quick):
ui.registerthread(account) ui.registerthread(account)
try: try:
# Load local folder. # Load local folder.
localfolder = localrepos.\ localfolder = account.get_local_folder(remotefolder)
getfolder(remotefolder.getvisiblename().\
replace(remoterepos.getsep(), localrepos.getsep()))
#Filtered folders on the remote side will not invoke this
#function, but we need to NOOP if the local folder is filtered
#out too:
if not localfolder.sync_this:
ui.debug('', "Not syncing filtered local folder '%s'" \
% localfolder)
return
# Write the mailboxes # Write the mailboxes
mbnames.add(account.name, localfolder.getname()) mbnames.add(account.name, localfolder.getname())
@ -462,15 +462,8 @@ def syncfolder(account, remotefolder, quick):
if e.severity > OfflineImapError.ERROR.FOLDER: if e.severity > OfflineImapError.ERROR.FOLDER:
raise raise
else: else:
#if the initial localfolder assignement bailed out, the localfolder var will not be available, so we need
ui.error(e, exc_info()[2], msg = "Aborting sync, folder '%s' " ui.error(e, exc_info()[2], msg = "Aborting sync, folder '%s' "
"[acc: '%s']" % ( "[acc: '%s']" % (localfolder, account))
remotefolder.getvisiblename().\
replace(remoterepos.getsep(), localrepos.getsep()),
account))
# we reconstruct foldername above rather than using
# localfolder, as the localfolder var is not
# available if assignment fails.
except Exception as e: except Exception as e:
ui.error(e, msg = "ERROR in syncfolder for %s folder %s: %s" % \ ui.error(e, msg = "ERROR in syncfolder for %s folder %s: %s" % \
(account, remotefolder.getvisiblename(), (account, remotefolder.getvisiblename(),