Bug 1277: make Maildir use the user-provided factory instead of hard-wiring MaildirMessage.

2.5.2 bugfix candidate.
This commit is contained in:
Andrew M. Kuchling 2008-01-19 20:12:04 +00:00
parent c6fde7293e
commit 15ce880cc8
2 changed files with 18 additions and 1 deletions

View File

@ -315,7 +315,10 @@ class Maildir(Mailbox):
subpath = self._lookup(key) subpath = self._lookup(key)
f = open(os.path.join(self._path, subpath), 'r') f = open(os.path.join(self._path, subpath), 'r')
try: try:
msg = MaildirMessage(f) if self._factory:
msg = self._factory(f)
else:
msg = MaildirMessage(f)
finally: finally:
f.close() f.close()
subdir, name = os.path.split(subpath) subdir, name = os.path.split(subpath)

View File

@ -509,6 +509,20 @@ class TestMaildir(TestMailbox):
self.assert_(msg_returned.get_flags() == 'S') self.assert_(msg_returned.get_flags() == 'S')
self.assert_(msg_returned.get_payload() == '3') self.assert_(msg_returned.get_payload() == '3')
def test_consistent_factory(self):
# Add a message.
msg = mailbox.MaildirMessage(self._template % 0)
msg.set_subdir('cur')
msg.set_flags('RF')
key = self._box.add(msg)
# Create new mailbox with
class FakeMessage(mailbox.MaildirMessage):
pass
box = mailbox.Maildir(self._path, factory=FakeMessage)
msg2 = box.get_message(key)
self.assert_(isinstance(msg2, FakeMessage))
def test_initialize_new(self): def test_initialize_new(self):
# Initialize a non-existent mailbox # Initialize a non-existent mailbox
self.tearDown() self.tearDown()