]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Avoid exception if there's a stray directory inside a Maildir folder.
authorAndrew M. Kuchling <amk@amk.ca>
Sat, 14 Jul 2007 21:56:19 +0000 (21:56 +0000)
committerAndrew M. Kuchling <amk@amk.ca>
Sat, 14 Jul 2007 21:56:19 +0000 (21:56 +0000)
The Maildir specification doesn't seem to say anything about this
situation, and it can happen if you're keeping a Maildir mailbox in
Subversion (.svn directories) or some similar system.  The patch just
ignores directories in the cur/, new/, tmp/ folders.

Lib/mailbox.py
Lib/test/test_mailbox.py

index 520afebb3c76a30a708f1e29b8e00b513c06cb33..3f7a12a6e67318773671daf38db1c0ad2ef3f7fb 100755 (executable)
@@ -459,7 +459,11 @@ class Maildir(Mailbox):
         """Update table of contents mapping."""
         self._toc = {}
         for subdir in ('new', 'cur'):
-            for entry in os.listdir(os.path.join(self._path, subdir)):
+            subdir_path = os.path.join(self._path, subdir)
+            for entry in os.listdir(subdir_path):
+                p = os.path.join(subdir_path, entry)
+                if os.path.isdir(p):
+                    continue
                 uniq = entry.split(self.colon)[0]
                 self._toc[uniq] = os.path.join(subdir, entry)
 
index 175c291a1208294f45d7fed8bba82e7214e9d592..684aeb21c316664546c90af7f07622e7845ce30b 100644 (file)
@@ -686,7 +686,18 @@ class TestMaildir(TestMailbox):
         folder1_alias = box.get_folder('folder1')
         self.assert_(folder1_alias._factory is dummy_factory)
 
-
+    def test_directory_in_folder (self):
+        # Test that mailboxes still work if there's a stray extra directory
+        # in a folder.
+        for i in range(10):
+            self._box.add(mailbox.Message(_sample_message))
+
+        # Create a stray directory
+        os.mkdir(os.path.join(self._path, 'cur', 'stray-dir'))
+
+        # Check that looping still works with the directory present.
+        for msg in self._box:
+            pass
 
 class _TestMboxMMDF(TestMailbox):