Skip to content

Commit

Permalink
bpo-21360: mailbox.Maildir now ignores files with a leading dot (pyth…
Browse files Browse the repository at this point in the history
…onGH-11833)

The maildir format specification states that files with a leading dot
should be ignored.

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
  • Loading branch information
ZackerySpytz and serhiy-storchaka committed Dec 25, 2023
1 parent f7c5a7a commit 3f5eb3e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Doc/library/mailbox.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
3 changes: 3 additions & 0 deletions Doc/whatsnew/3.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=============
Expand Down
2 changes: 2 additions & 0 deletions Lib/mailbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,8 @@ def _refresh(self):
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
Expand Down
14 changes: 14 additions & 0 deletions Lib/test/test_mailbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,20 @@ def test_initialize_existing(self):
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))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:class:`mailbox.Maildir` now ignores files with a leading dot.

0 comments on commit 3f5eb3e

Please sign in to comment.