From 2659dab1180ae8f8fda6935c16e27a19fbbb5cd6 Mon Sep 17 00:00:00 2001 From: jgoerzen Date: Wed, 19 Jun 2002 07:16:19 +0100 Subject: [PATCH] /head: changeset 9 Updated --- head/offlineimap/repository/Base.py | 43 ++++++++++++++++++++++++++ head/offlineimap/repository/IMAP.py | 3 ++ head/offlineimap/repository/Maildir.py | 3 ++ 3 files changed, 49 insertions(+) diff --git a/head/offlineimap/repository/Base.py b/head/offlineimap/repository/Base.py index 76aa9d6..78ce4e9 100644 --- a/head/offlineimap/repository/Base.py +++ b/head/offlineimap/repository/Base.py @@ -20,4 +20,47 @@ class BaseRepository: def getfolders(self): """Returns a list of ALL folders on this server.""" return [] + + def getsep(self): + raise NotImplementedError + + def makefolder(self): + raise NotImplementedError + + def deletefolder(self): + raise NotImplementedError + def syncfoldersto(self, dest): + """Syncs the folders in this repository to those in dest. + It does NOT sync the contents of those folders.""" + src = self + srcfolders = src.getfolders() + destfolders = dest.getfolders() + + # Create hashes with the names, but convert the source folders + # to the dest folder's sep. + + srchash = {} + for folder in srcfolders: + srchash[folder.getname().replace(src.getsep(), dest.getsep())] = \ + folder + desthash = {} + for folder in destfolders: + desthash[folder.getname()] = folder + + # + # Find new folders. + # + + for key in srchash.keys(): + if not key in desthash: + dest.makefolder(key) + + # + # Find deleted folders. + # + + for key in desthash.keys(): + if not key in srchash: + dest.deletefolder(key) + diff --git a/head/offlineimap/repository/IMAP.py b/head/offlineimap/repository/IMAP.py index f6f2c5c..51011b3 100644 --- a/head/offlineimap/repository/IMAP.py +++ b/head/offlineimap/repository/IMAP.py @@ -27,6 +27,9 @@ class IMAPRepository(BaseRepository): self.imapobj = imapserver.makeconnection() self.folders = None + def getsep(self): + return self.imapserver.delim + def getfolders(self): if self.folders != None: return self.folders diff --git a/head/offlineimap/repository/Maildir.py b/head/offlineimap/repository/Maildir.py index 4a9f998..df7f5bb 100644 --- a/head/offlineimap/repository/Maildir.py +++ b/head/offlineimap/repository/Maildir.py @@ -29,6 +29,9 @@ class MaildirRepository(BaseRepository): self.root = root self.folders = None + def getsep(self): + return '.' + def getfolders(self): if self.folders != None: return self.folders