[Python-checkins] r60095 - in python/trunk/Lib: mailbox.py test/test_mailbox.py

andrew.kuchling python-checkins at python.org
Sat Jan 19 21:12:04 CET 2008


Author: andrew.kuchling
Date: Sat Jan 19 21:12:04 2008
New Revision: 60095

Modified:
   python/trunk/Lib/mailbox.py
   python/trunk/Lib/test/test_mailbox.py
Log:
Bug 1277: make Maildir use the user-provided factory instead of hard-wiring MaildirMessage.
2.5.2 bugfix candidate.

Modified: python/trunk/Lib/mailbox.py
==============================================================================
--- python/trunk/Lib/mailbox.py	(original)
+++ python/trunk/Lib/mailbox.py	Sat Jan 19 21:12:04 2008
@@ -315,7 +315,10 @@
         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)

Modified: python/trunk/Lib/test/test_mailbox.py
==============================================================================
--- python/trunk/Lib/test/test_mailbox.py	(original)
+++ python/trunk/Lib/test/test_mailbox.py	Sat Jan 19 21:12:04 2008
@@ -509,6 +509,20 @@
         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()


More information about the Python-checkins mailing list