From 15ce880cc8c3de29e91e2e867b2db0b19a48e5f3 Mon Sep 17 00:00:00 2001 From: "Andrew M. Kuchling" Date: Sat, 19 Jan 2008 20:12:04 +0000 Subject: [PATCH] Bug 1277: make Maildir use the user-provided factory instead of hard-wiring MaildirMessage. 2.5.2 bugfix candidate. --- Lib/mailbox.py | 5 ++++- Lib/test/test_mailbox.py | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Lib/mailbox.py b/Lib/mailbox.py index 3f7a12a6e67..e3e9cbb3422 100755 --- a/Lib/mailbox.py +++ b/Lib/mailbox.py @@ -315,7 +315,10 @@ class Maildir(Mailbox): subpath = self._lookup(key) f = open(os.path.join(self._path, subpath), 'r') try: - msg = MaildirMessage(f) + if self._factory: + msg = self._factory(f) + else: + msg = MaildirMessage(f) finally: f.close() subdir, name = os.path.split(subpath) diff --git a/Lib/test/test_mailbox.py b/Lib/test/test_mailbox.py index 684aeb21c31..ff214cef981 100644 --- a/Lib/test/test_mailbox.py +++ b/Lib/test/test_mailbox.py @@ -509,6 +509,20 @@ class TestMaildir(TestMailbox): self.assert_(msg_returned.get_flags() == 'S') 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): # Initialize a non-existent mailbox self.tearDown()