From 335b320d9a3cefabc586c69ddfe62454752f3525 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Thu, 16 Jun 2011 17:09:29 +0200 Subject: [PATCH] Fix recursively scanning Maildir folders Commit 1754bf4110da251f4aa1dc0803889899b02bfcff introduced a blunder: - for dirname in os.listdir(toppath) + ['.']: + for dirname in os.listdir(toppath) + [toppath]: ... - if self.getsep() == '/' and dirname != '.': + if self.getsep() == '/' and dirname: This change was plainly wrong and would never have worked, so this commit reverts above bit. While touching the function, some minor code documentation, cleanup and limiting line length to 80 chars. Signed-off-by: Sebastian Spaeth Signed-off-by: Nicolas Sebrecht --- offlineimap/repository/Maildir.py | 36 +++++++++++++++++-------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/offlineimap/repository/Maildir.py b/offlineimap/repository/Maildir.py index 2a10a93..86716e1 100644 --- a/offlineimap/repository/Maildir.py +++ b/offlineimap/repository/Maildir.py @@ -117,23 +117,23 @@ class MaildirRepository(BaseRepository): self.accountname, self.config) def _getfolders_scandir(self, root, extension = None): + """Recursively scan folder 'root'; return a list of MailDirFolder + + :param root: (absolute) path to Maildir root + :param extension: (relative) subfolder to examine within root""" self.debug("_GETFOLDERS_SCANDIR STARTING. root = %s, extension = %s" \ % (root, extension)) - # extension willl only be non-None when called recursively when - # getsep() returns '/'. retval = [] # Configure the full path to this repository -- "toppath" - - if extension == None: - toppath = root - else: + if extension: toppath = os.path.join(root, extension) - + else: + toppath = root self.debug(" toppath = %s" % toppath) # Iterate over directories in top & top itself. - for dirname in os.listdir(toppath) + [toppath]: + for dirname in os.listdir(toppath) + ['.']: self.debug(" *** top of loop") self.debug(" dirname = %s" % dirname) if dirname in ['cur', 'new', 'tmp']: @@ -153,17 +153,21 @@ class MaildirRepository(BaseRepository): os.path.isdir(os.path.join(fullname, 'new')) and os.path.isdir(os.path.join(fullname, 'tmp'))): # This directory has maildir stuff -- process - self.debug(" This is a maildir folder.") + self.debug(" This is maildir folder '%s'." % foldername) - self.debug(" foldername = %s" % foldername) - - if self.config.has_option('Repository ' + self.name, 'restoreatime') and self.config.getboolean('Repository ' + self.name, 'restoreatime'): + if self.config.has_option('Repository %s' % self, + 'restoreatime') and \ + self.config.getboolean('Repository %s' % self, + 'restoreatime'): self._append_folder_atimes(foldername) - retval.append(folder.Maildir.MaildirFolder(self.root, foldername, - self.getsep(), self, self.accountname, + retval.append(folder.Maildir.MaildirFolder(self.root, + foldername, + self.getsep(), + self, + self.accountname, self.config)) - if self.getsep() == '/' and dirname: - # Check sub-directories for folders. + if self.getsep() == '/' and dirname != '.': + # Recursively check sub-directories for folders too. retval.extend(self._getfolders_scandir(root, foldername)) self.debug("_GETFOLDERS_SCANDIR RETURNING %s" % \ repr([x.getname() for x in retval]))