Thanks to visit codestin.com
Credit goes to github.com

Skip to content

bpo-21360: mailbox.Maildir now ignores files with a leading dot #11833

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -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 @@ -1117,6 +1117,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.