Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Doc/library/mailbox.rst
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,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 @@ -1104,6 +1104,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.