]> code.delx.au - offlineimap/blobdiff - offlineimap/repository/Base.py
Synchronize newly created folders both ways
[offlineimap] / offlineimap / repository / Base.py
index 945183f48cf59d330bb2bcbf2641bd1d19964331..3abd290d233613331aabef2b5b0b910bc15f698c 100644 (file)
@@ -1,5 +1,5 @@
 # Base repository support
-# Copyright (C) 2002, 2003, 2006 John Goerzen
+# Copyright (C) 2002-2007 John Goerzen
 # <jgoerzen@complete.org>
 #
 #    This program is free software; you can redistribute it and/or modify
@@ -17,6 +17,7 @@
 #    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 
 from offlineimap import CustomConfig
+from offlineimap.ui import UIBase
 import os.path
 
 def LoadRepository(name, account, reqtype):
@@ -51,6 +52,27 @@ class BaseRepository(CustomConfig.ConfigHelperMixin):
         if not os.path.exists(self.uiddir):
             os.mkdir(self.uiddir, 0700)
 
+    # The 'restoreatime' config parameter only applies to local Maildir
+    # mailboxes.
+    def restore_atime(self):
+       if self.config.get('Repository ' + self.name, 'type').strip() != \
+               'Maildir':
+           return
+
+       if not self.config.has_option('Repository ' + self.name, 'restoreatime') or not self.config.getboolean('Repository ' + self.name, 'restoreatime'):
+           return
+
+       return self.restore_folder_atimes()
+
+    def connect(self):
+        """Establish a connection to the remote, if necessary.  This exists
+        so that IMAP connections can all be established up front, gathering
+        passwords as needed.  It was added in order to support the
+        error recovery -- we need to connect first outside of the error
+        trap in order to validate the password, and that's the point of
+        this function."""
+        pass
+
     def holdordropconnections(self):
         pass
 
@@ -85,6 +107,11 @@ class BaseRepository(CustomConfig.ConfigHelperMixin):
         """Returns a list of ALL folders on this server."""
         return []
 
+    def forgetfolders(self):
+        """Forgets the cached list of folders, if any.  Useful to run
+        after a sync run."""
+        pass
+
     def getsep(self):
         raise NotImplementedError
 
@@ -97,7 +124,7 @@ class BaseRepository(CustomConfig.ConfigHelperMixin):
     def getfolder(self, foldername):
         raise NotImplementedError
     
-    def syncfoldersto(self, dest):
+    def syncfoldersto(self, dest, status):
         """Syncs the folders in this repository to those in dest.
         It does NOT sync the contents of those folders."""
         src = self
@@ -109,6 +136,8 @@ class BaseRepository(CustomConfig.ConfigHelperMixin):
 
         srchash = {}
         for folder in srcfolders:
+            if (folder.getvisiblename()[-2:] == src.getsep() + "."):
+                continue
             srchash[folder.getvisiblename().replace(src.getsep(), dest.getsep())] = \
                                                            folder
         desthash = {}
@@ -119,9 +148,18 @@ class BaseRepository(CustomConfig.ConfigHelperMixin):
         # Find new folders.
         #
         
+        ignoredfolders = []
+        newfolders = []
+
         for key in srchash.keys():
             if not key in desthash:
-                dest.makefolder(key)
+                srckey = key.replace(dest.getsep(),src.getsep())
+                if status.getfolder(key.replace(dest.getsep(),status.getsep())).isnewfolder():
+                    dest.makefolder(key)
+                    newfolders.append(srckey)
+                else:
+                    UIBase.getglobalui().ignorefolder (key, src, dest)
+                    ignoredfolders.append(srckey)
 
         #
         # Find deleted folders.
@@ -131,6 +169,8 @@ class BaseRepository(CustomConfig.ConfigHelperMixin):
         #for key in desthash.keys():
         #    if not key in srchash:
         #        dest.deletefolder(key)
+
+        return (ignoredfolders,newfolders)
         
     ##### Keepalive