[Bug #1569790] mailbox.Maildir.get_folder() loses factory information
Both the Maildir and MH classes had this bug; the patch fixes both classes and adds a test. Will backport to 25-maint.
This commit is contained in:
parent
038cad7ee4
commit
a3e5d3757c
|
@ -367,12 +367,14 @@ class Maildir(Mailbox):
|
||||||
|
|
||||||
def get_folder(self, folder):
|
def get_folder(self, folder):
|
||||||
"""Return a Maildir instance for the named folder."""
|
"""Return a Maildir instance for the named folder."""
|
||||||
return Maildir(os.path.join(self._path, '.' + folder), create=False)
|
return Maildir(os.path.join(self._path, '.' + folder),
|
||||||
|
factory=self._factory,
|
||||||
|
create=False)
|
||||||
|
|
||||||
def add_folder(self, folder):
|
def add_folder(self, folder):
|
||||||
"""Create a folder and return a Maildir instance representing it."""
|
"""Create a folder and return a Maildir instance representing it."""
|
||||||
path = os.path.join(self._path, '.' + folder)
|
path = os.path.join(self._path, '.' + folder)
|
||||||
result = Maildir(path)
|
result = Maildir(path, factory=self._factory)
|
||||||
maildirfolder_path = os.path.join(path, 'maildirfolder')
|
maildirfolder_path = os.path.join(path, 'maildirfolder')
|
||||||
if not os.path.exists(maildirfolder_path):
|
if not os.path.exists(maildirfolder_path):
|
||||||
os.close(os.open(maildirfolder_path, os.O_CREAT | os.O_WRONLY))
|
os.close(os.open(maildirfolder_path, os.O_CREAT | os.O_WRONLY))
|
||||||
|
@ -944,11 +946,13 @@ class MH(Mailbox):
|
||||||
|
|
||||||
def get_folder(self, folder):
|
def get_folder(self, folder):
|
||||||
"""Return an MH instance for the named folder."""
|
"""Return an MH instance for the named folder."""
|
||||||
return MH(os.path.join(self._path, folder), create=False)
|
return MH(os.path.join(self._path, folder),
|
||||||
|
factory=self._factory, create=False)
|
||||||
|
|
||||||
def add_folder(self, folder):
|
def add_folder(self, folder):
|
||||||
"""Create a folder and return an MH instance representing it."""
|
"""Create a folder and return an MH instance representing it."""
|
||||||
return MH(os.path.join(self._path, folder))
|
return MH(os.path.join(self._path, folder),
|
||||||
|
factory=self._factory)
|
||||||
|
|
||||||
def remove_folder(self, folder):
|
def remove_folder(self, folder):
|
||||||
"""Delete the named folder, which must be empty."""
|
"""Delete the named folder, which must be empty."""
|
||||||
|
|
|
@ -673,6 +673,19 @@ class TestMaildir(TestMailbox):
|
||||||
self._box.lock()
|
self._box.lock()
|
||||||
self._box.unlock()
|
self._box.unlock()
|
||||||
|
|
||||||
|
def test_folder (self):
|
||||||
|
# Test for bug #1569790: verify that folders returned by .get_folder()
|
||||||
|
# use the same factory function.
|
||||||
|
def dummy_factory (s):
|
||||||
|
return None
|
||||||
|
box = self._factory(self._path, factory=dummy_factory)
|
||||||
|
folder = box.add_folder('folder1')
|
||||||
|
self.assert_(folder._factory is dummy_factory)
|
||||||
|
|
||||||
|
folder1_alias = box.get_folder('folder1')
|
||||||
|
self.assert_(folder1_alias._factory is dummy_factory)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class _TestMboxMMDF(TestMailbox):
|
class _TestMboxMMDF(TestMailbox):
|
||||||
|
|
||||||
|
@ -789,7 +802,11 @@ class TestMH(TestMailbox):
|
||||||
|
|
||||||
def test_get_folder(self):
|
def test_get_folder(self):
|
||||||
# Open folders
|
# Open folders
|
||||||
self._box.add_folder('foo.bar')
|
def dummy_factory (s):
|
||||||
|
return None
|
||||||
|
self._box = self._factory(self._path, dummy_factory)
|
||||||
|
|
||||||
|
new_folder = self._box.add_folder('foo.bar')
|
||||||
folder0 = self._box.get_folder('foo.bar')
|
folder0 = self._box.get_folder('foo.bar')
|
||||||
folder0.add(self._template % 'bar')
|
folder0.add(self._template % 'bar')
|
||||||
self.assert_(os.path.isdir(os.path.join(self._path, 'foo.bar')))
|
self.assert_(os.path.isdir(os.path.join(self._path, 'foo.bar')))
|
||||||
|
@ -797,6 +814,11 @@ class TestMH(TestMailbox):
|
||||||
self.assert_(folder1.get_string(folder1.keys()[0]) == \
|
self.assert_(folder1.get_string(folder1.keys()[0]) == \
|
||||||
self._template % 'bar')
|
self._template % 'bar')
|
||||||
|
|
||||||
|
# Test for bug #1569790: verify that folders returned by .get_folder()
|
||||||
|
# use the same factory function.
|
||||||
|
self.assert_(new_folder._factory is self._box._factory)
|
||||||
|
self.assert_(folder0._factory is self._box._factory)
|
||||||
|
|
||||||
def test_add_and_remove_folders(self):
|
def test_add_and_remove_folders(self):
|
||||||
# Delete folders
|
# Delete folders
|
||||||
self._box.add_folder('one')
|
self._box.add_folder('one')
|
||||||
|
|
|
@ -96,6 +96,10 @@ Core and builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Bug #1569790: mailbox.py: Maildir.get_folder() and MH.get_folder()
|
||||||
|
weren't passing the message factory on to newly created Maildir/MH
|
||||||
|
objects.
|
||||||
|
|
||||||
- Patch #1592250: Add elidge argument to Tkinter.Text.search.
|
- Patch #1592250: Add elidge argument to Tkinter.Text.search.
|
||||||
|
|
||||||
- Patch #838546: Make terminal become controlling in pty.fork()
|
- Patch #838546: Make terminal become controlling in pty.fork()
|
||||||
|
|
Loading…
Reference in New Issue