/head: changeset 9

Updated
This commit is contained in:
jgoerzen 2002-06-19 07:16:19 +01:00
parent 0e4e4aa6c5
commit 2659dab118
3 changed files with 49 additions and 0 deletions

View File

@ -20,4 +20,47 @@ class BaseRepository:
def getfolders(self): def getfolders(self):
"""Returns a list of ALL folders on this server.""" """Returns a list of ALL folders on this server."""
return [] 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)

View File

@ -27,6 +27,9 @@ class IMAPRepository(BaseRepository):
self.imapobj = imapserver.makeconnection() self.imapobj = imapserver.makeconnection()
self.folders = None self.folders = None
def getsep(self):
return self.imapserver.delim
def getfolders(self): def getfolders(self):
if self.folders != None: if self.folders != None:
return self.folders return self.folders

View File

@ -29,6 +29,9 @@ class MaildirRepository(BaseRepository):
self.root = root self.root = root
self.folders = None self.folders = None
def getsep(self):
return '.'
def getfolders(self): def getfolders(self):
if self.folders != None: if self.folders != None:
return self.folders return self.folders