[Python-checkins] r56383 - in python/branches/release25-maint: Lib/mailbox.py Lib/test/test_mailbox.py Misc/NEWS

andrew.kuchling python-checkins at python.org
Sun Jul 15 00:06:32 CEST 2007


Author: andrew.kuchling
Date: Sun Jul 15 00:06:30 2007
New Revision: 56383

Modified:
   python/branches/release25-maint/Lib/mailbox.py
   python/branches/release25-maint/Lib/test/test_mailbox.py
   python/branches/release25-maint/Misc/NEWS
Log:
[Backport of r56382]
Avoid exception if there's a stray directory inside a Maildir folder.

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.


Modified: python/branches/release25-maint/Lib/mailbox.py
==============================================================================
--- python/branches/release25-maint/Lib/mailbox.py	(original)
+++ python/branches/release25-maint/Lib/mailbox.py	Sun Jul 15 00:06:30 2007
@@ -459,7 +459,11 @@
         """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)
 

Modified: python/branches/release25-maint/Lib/test/test_mailbox.py
==============================================================================
--- python/branches/release25-maint/Lib/test/test_mailbox.py	(original)
+++ python/branches/release25-maint/Lib/test/test_mailbox.py	Sun Jul 15 00:06:30 2007
@@ -685,7 +685,18 @@
         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):
 

Modified: python/branches/release25-maint/Misc/NEWS
==============================================================================
--- python/branches/release25-maint/Misc/NEWS	(original)
+++ python/branches/release25-maint/Misc/NEWS	Sun Jul 15 00:06:30 2007
@@ -45,6 +45,9 @@
 - Fix bug in marshal where bad data would cause a segfault due to
   lack of an infinite recursion check.
 
+- mailbox.py: Ignore stray directories found in Maildir's cur/new/tmp
+  subdirectories.
+
 - HTML-escape the plain traceback in cgitb's HTML output, to prevent
   the traceback inadvertently or maliciously closing the comment and
   injecting HTML into the error page.


More information about the Python-checkins mailing list