Fix recursively scanning Maildir folders

Commit 1754bf4110 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 <Sebastian@SSpaeth.de>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
Sebastian Spaeth 2011-06-16 17:09:29 +02:00 committed by Nicolas Sebrecht
parent 2180f5fbf4
commit 335b320d9a

View File

@ -117,23 +117,23 @@ class MaildirRepository(BaseRepository):
self.accountname, self.config) self.accountname, self.config)
def _getfolders_scandir(self, root, extension = None): 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" \ self.debug("_GETFOLDERS_SCANDIR STARTING. root = %s, extension = %s" \
% (root, extension)) % (root, extension))
# extension willl only be non-None when called recursively when
# getsep() returns '/'.
retval = [] retval = []
# Configure the full path to this repository -- "toppath" # Configure the full path to this repository -- "toppath"
if extension:
if extension == None:
toppath = root
else:
toppath = os.path.join(root, extension) toppath = os.path.join(root, extension)
else:
toppath = root
self.debug(" toppath = %s" % toppath) self.debug(" toppath = %s" % toppath)
# Iterate over directories in top & top itself. # 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(" *** top of loop")
self.debug(" dirname = %s" % dirname) self.debug(" dirname = %s" % dirname)
if dirname in ['cur', 'new', 'tmp']: 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, 'new')) and
os.path.isdir(os.path.join(fullname, 'tmp'))): os.path.isdir(os.path.join(fullname, 'tmp'))):
# This directory has maildir stuff -- process # 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 %s' % self,
'restoreatime') and \
if self.config.has_option('Repository ' + self.name, 'restoreatime') and self.config.getboolean('Repository ' + self.name, 'restoreatime'): self.config.getboolean('Repository %s' % self,
'restoreatime'):
self._append_folder_atimes(foldername) self._append_folder_atimes(foldername)
retval.append(folder.Maildir.MaildirFolder(self.root, foldername, retval.append(folder.Maildir.MaildirFolder(self.root,
self.getsep(), self, self.accountname, foldername,
self.getsep(),
self,
self.accountname,
self.config)) self.config))
if self.getsep() == '/' and dirname: if self.getsep() == '/' and dirname != '.':
# Check sub-directories for folders. # Recursively check sub-directories for folders too.
retval.extend(self._getfolders_scandir(root, foldername)) retval.extend(self._getfolders_scandir(root, foldername))
self.debug("_GETFOLDERS_SCANDIR RETURNING %s" % \ self.debug("_GETFOLDERS_SCANDIR RETURNING %s" % \
repr([x.getname() for x in retval])) repr([x.getname() for x in retval]))