[PATCH 3/8] add sync_this variable to all Folder() instances

Sebastian Spaeth Sebastian at SSpaeth.de
Mon Aug 29 15:00:12 BST 2011


This variable shows if this folder should be synced or is disabled due to
a folderfilter statement. This lets us distinguish between a non-existent
folder and one that has been filtered out. Previously any filtered folder
would simply appear to be non-existing.

Signed-off-by: Sebastian Spaeth <Sebastian at SSpaeth.de>
---
 offlineimap/accounts.py        |   16 +++++++++++++++-
 offlineimap/folder/Base.py     |    2 ++
 offlineimap/repository/IMAP.py |   13 ++++++++-----
 3 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/offlineimap/accounts.py b/offlineimap/accounts.py
index 31ea2b7..731b11b 100644
--- a/offlineimap/accounts.py
+++ b/offlineimap/accounts.py
@@ -237,6 +237,10 @@ class SyncableAccount(Account):
 
             # iterate through all folders on the remote repo and sync
             for remotefolder in remoterepos.getfolders():
+                if not remotefolder.sync_this:
+                    self.ui.debug('', "Not syncing filtered remote folder '%s'"
+                                  "[%s]" % (remotefolder, remoterepos))
+                    continue # Filtered out remote folder
                 thread = InstanceLimitedThread(\
                     instancename = 'FOLDER_' + self.remoterepos.getname(),
                     target = syncfolder,
@@ -286,7 +290,9 @@ class SyncableAccount(Account):
 def syncfolder(accountname, remoterepos, remotefolder, localrepos,
                statusrepos, quick):
     """This function is called as target for the
-    InstanceLimitedThread invokation in SyncableAccount."""
+    InstanceLimitedThread invokation in SyncableAccount.
+
+    Filtered folders on the remote side will not invoke this function."""
     ui = getglobalui()
     ui.registerthread(accountname)
     try:
@@ -294,6 +300,14 @@ def syncfolder(accountname, remoterepos, remotefolder, localrepos,
         localfolder = localrepos.\
                       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
         mbnames.add(accountname, localfolder.getvisiblename())
 
diff --git a/offlineimap/folder/Base.py b/offlineimap/folder/Base.py
index 5bd8061..8a674d1 100644
--- a/offlineimap/folder/Base.py
+++ b/offlineimap/folder/Base.py
@@ -29,6 +29,8 @@ except NameError:
 
 class BaseFolder(object):
     def __init__(self):
+        self.sync_this = True
+        """Should this folder be included in syncing?"""
         self.ui = getglobalui()
 
     def getname(self):
diff --git a/offlineimap/repository/IMAP.py b/offlineimap/repository/IMAP.py
index 68eb637..11ec25b 100644
--- a/offlineimap/repository/IMAP.py
+++ b/offlineimap/repository/IMAP.py
@@ -295,13 +295,16 @@ class IMAPRepository(BaseRepository):
             if '\\noselect' in flaglist:
                 continue
             foldername = imaputil.dequote(name)
-            if not self.folderfilter(foldername):
-                self.ui.debug('imap',"Filtering out '%s' due to folderfilter" %\
-                                  foldername)
-                continue
             retval.append(self.getfoldertype()(self.imapserver, foldername,
                                                self.nametrans(foldername),
                                                self.accountname, self))
+
+            # filter out the folder?
+            if not self.folderfilter(foldername):
+                self.ui.debug('imap', "Filtering out '%s'[%s] due to folderfilt"
+                              "er" % (foldername, self))
+                retval[-1].sync_this = False
+        # Add all folderincludes
         if len(self.folderincludes):
             imapobj = self.imapserver.acquireconnection()
             try:
@@ -324,7 +327,7 @@ class IMAPRepository(BaseRepository):
                 
         retval.sort(lambda x, y: self.foldersort(x.getvisiblename(), y.getvisiblename()))
         self.folders = retval
-        return retval
+        return self.folders
 
     def makefolder(self, foldername):
         #if self.getreference() != '""':
-- 
1.7.4.1





More information about the OfflineIMAP-project mailing list