]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-21360: mailbox.Maildir now ignores files with a leading dot (GH-11833)
authorZackery Spytz <zspytz@gmail.com>
Mon, 25 Dec 2023 15:07:51 +0000 (07:07 -0800)
committerGitHub <noreply@github.com>
Mon, 25 Dec 2023 15:07:51 +0000 (17:07 +0200)
The maildir format specification states that files with a leading dot
should be ignored.

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Doc/library/mailbox.rst
Doc/whatsnew/3.13.rst
Lib/mailbox.py
Lib/test/test_mailbox.py
Misc/NEWS.d/next/Library/2019-02-12-16-12-54.bpo-21360.gkSSfx.rst [new file with mode: 0644]

index c98496d1fff993ffdccf8421d620aa20a007996a..3ffd0981a4a4f2bb5ffcdbd4a466773512fe0165 100644 (file)
@@ -364,6 +364,9 @@ Supported mailbox formats are Maildir, mbox, MH, Babyl, and MMDF.
 
       The :attr:`!colon` attribute may also be set on a per-instance basis.
 
+   .. versionchanged:: 3.13
+      :class:`Maildir` now ignores files with a leading dot.
+
    :class:`!Maildir` instances have all of the methods of :class:`Mailbox` in
    addition to the following:
 
index b4cd106f5cac5fbc0a0abe947c5794e1e3b2ba0d..c905cddc6cba628490dbf9b84f232fefd3822f40 100644 (file)
@@ -1163,6 +1163,9 @@ Changes in the Python API
   other "private" attributes.
   (See :gh:`112826`.)
 
+* :class:`mailbox.Maildir` now ignores files with a leading dot.
+  (Contributed by Zackery Spytz in :gh:`65559`.)
+
 
 Build Changes
 =============
index 36afaded705d0a7c1948ca61c4503ccab511c5c2..574c01475dece60a1ae3705a5b61759fd72f826b 100644 (file)
@@ -590,6 +590,8 @@ class Maildir(Mailbox):
         for subdir in self._toc_mtimes:
             path = self._paths[subdir]
             for entry in os.listdir(path):
+                if entry.startswith('.'):
+                    continue
                 p = os.path.join(path, entry)
                 if os.path.isdir(p):
                     continue
index 23fcbfac1f9c891575226a146528465fa45b012b..caa7eb3d829c68254853dda6a9a463d24551c118 100644 (file)
@@ -681,6 +681,20 @@ class TestMaildir(TestMailbox, unittest.TestCase):
         self._box = mailbox.Maildir(self._path)
         self._check_basics()
 
+    def test_filename_leading_dot(self):
+        self.tearDown()
+        for subdir in '', 'tmp', 'new', 'cur':
+            os.mkdir(os.path.normpath(os.path.join(self._path, subdir)))
+        for subdir in 'tmp', 'new', 'cur':
+            fname = os.path.join(self._path, subdir, '.foo' + subdir)
+            with open(fname, 'wb') as f:
+                f.write(b"@")
+        self._box = mailbox.Maildir(self._path)
+        self.assertNotIn('.footmp', self._box)
+        self.assertNotIn('.foonew', self._box)
+        self.assertNotIn('.foocur', self._box)
+        self.assertEqual(list(self._box.iterkeys()), [])
+
     def _check_basics(self, factory=None):
         # (Used by test_open_new() and test_open_existing().)
         self.assertEqual(self._box._path, os.path.abspath(self._path))
diff --git a/Misc/NEWS.d/next/Library/2019-02-12-16-12-54.bpo-21360.gkSSfx.rst b/Misc/NEWS.d/next/Library/2019-02-12-16-12-54.bpo-21360.gkSSfx.rst
new file mode 100644 (file)
index 0000000..bc32b9f
--- /dev/null
@@ -0,0 +1 @@
+:class:`mailbox.Maildir` now ignores files with a leading dot.