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

Skip to content

Commit 3f5eb3e

Browse files
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 <[email protected]>
1 parent f7c5a7a commit 3f5eb3e

File tree

5 files changed

+23
-0
lines changed

5 files changed

+23
-0
lines changed

Doc/library/mailbox.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,9 @@ Supported mailbox formats are Maildir, mbox, MH, Babyl, and MMDF.
364364

365365
The :attr:`!colon` attribute may also be set on a per-instance basis.
366366

367+
.. versionchanged:: 3.13
368+
:class:`Maildir` now ignores files with a leading dot.
369+
367370
:class:`!Maildir` instances have all of the methods of :class:`Mailbox` in
368371
addition to the following:
369372

Doc/whatsnew/3.13.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,9 @@ Changes in the Python API
11631163
other "private" attributes.
11641164
(See :gh:`112826`.)
11651165

1166+
* :class:`mailbox.Maildir` now ignores files with a leading dot.
1167+
(Contributed by Zackery Spytz in :gh:`65559`.)
1168+
11661169

11671170
Build Changes
11681171
=============

Lib/mailbox.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,8 @@ def _refresh(self):
590590
for subdir in self._toc_mtimes:
591591
path = self._paths[subdir]
592592
for entry in os.listdir(path):
593+
if entry.startswith('.'):
594+
continue
593595
p = os.path.join(path, entry)
594596
if os.path.isdir(p):
595597
continue

Lib/test/test_mailbox.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,20 @@ def test_initialize_existing(self):
681681
self._box = mailbox.Maildir(self._path)
682682
self._check_basics()
683683

684+
def test_filename_leading_dot(self):
685+
self.tearDown()
686+
for subdir in '', 'tmp', 'new', 'cur':
687+
os.mkdir(os.path.normpath(os.path.join(self._path, subdir)))
688+
for subdir in 'tmp', 'new', 'cur':
689+
fname = os.path.join(self._path, subdir, '.foo' + subdir)
690+
with open(fname, 'wb') as f:
691+
f.write(b"@")
692+
self._box = mailbox.Maildir(self._path)
693+
self.assertNotIn('.footmp', self._box)
694+
self.assertNotIn('.foonew', self._box)
695+
self.assertNotIn('.foocur', self._box)
696+
self.assertEqual(list(self._box.iterkeys()), [])
697+
684698
def _check_basics(self, factory=None):
685699
# (Used by test_open_new() and test_open_existing().)
686700
self.assertEqual(self._box._path, os.path.abspath(self._path))
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:class:`mailbox.Maildir` now ignores files with a leading dot.

0 commit comments

Comments
 (0)