mirror of
https://github.com/python/cpython.git
synced 2025-08-22 17:55:18 +00:00
bpo-21360: mailbox.Maildir now ignores files with a leading dot (GH-11833)
The maildir format specification states that files with a leading dot should be ignored. Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
f7c5a7a0f9
commit
3f5eb3e6c7
5 changed files with 23 additions and 0 deletions
|
@ -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.
|
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
|
:class:`!Maildir` instances have all of the methods of :class:`Mailbox` in
|
||||||
addition to the following:
|
addition to the following:
|
||||||
|
|
||||||
|
|
|
@ -1163,6 +1163,9 @@ Changes in the Python API
|
||||||
other "private" attributes.
|
other "private" attributes.
|
||||||
(See :gh:`112826`.)
|
(See :gh:`112826`.)
|
||||||
|
|
||||||
|
* :class:`mailbox.Maildir` now ignores files with a leading dot.
|
||||||
|
(Contributed by Zackery Spytz in :gh:`65559`.)
|
||||||
|
|
||||||
|
|
||||||
Build Changes
|
Build Changes
|
||||||
=============
|
=============
|
||||||
|
|
|
@ -590,6 +590,8 @@ class Maildir(Mailbox):
|
||||||
for subdir in self._toc_mtimes:
|
for subdir in self._toc_mtimes:
|
||||||
path = self._paths[subdir]
|
path = self._paths[subdir]
|
||||||
for entry in os.listdir(path):
|
for entry in os.listdir(path):
|
||||||
|
if entry.startswith('.'):
|
||||||
|
continue
|
||||||
p = os.path.join(path, entry)
|
p = os.path.join(path, entry)
|
||||||
if os.path.isdir(p):
|
if os.path.isdir(p):
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -681,6 +681,20 @@ class TestMaildir(TestMailbox, unittest.TestCase):
|
||||||
self._box = mailbox.Maildir(self._path)
|
self._box = mailbox.Maildir(self._path)
|
||||||
self._check_basics()
|
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):
|
def _check_basics(self, factory=None):
|
||||||
# (Used by test_open_new() and test_open_existing().)
|
# (Used by test_open_new() and test_open_existing().)
|
||||||
self.assertEqual(self._box._path, os.path.abspath(self._path))
|
self.assertEqual(self._box._path, os.path.abspath(self._path))
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
:class:`mailbox.Maildir` now ignores files with a leading dot.
|
Loading…
Add table
Add a link
Reference in a new issue