[PATCH] Fix recursively scanning Maildir folders
Sebastian Spaeth
Sebastian at SSpaeth.de
Thu Jun 16 16:09:29 BST 2011
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 <Sebastian at SSpaeth.de>
---
Not sure why I never tripped over this obvious mistake, despite me
running the code daily. This is on top of master and recommended for master.
The only functional change is the reverting of the above 2 lines, the rest is minor cleanup and documentation. Sorry for the blunder.
offlineimap/repository/Maildir.py | 36 ++++++++++++++++++++----------------
1 files 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(" foldername = %s" % foldername)
+ self.debug(" This is maildir folder '%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]))
--
1.7.4.1
More information about the OfflineIMAP-project
mailing list