[Checkins] SVN: zope.sendmail/trunk/ Sort by modification time the messages in zope.sendmail.maildir so earlier

Fabio Tranchitella kobold at kobold.it
Wed Jan 6 15:38:47 EST 2010


Log message for revision 107751:
  Sort by modification time the messages in zope.sendmail.maildir so earlier
  messages are sent before later messages during queue processing.
  
  
  

Changed:
  U   zope.sendmail/trunk/CHANGES.txt
  U   zope.sendmail/trunk/src/zope/sendmail/maildir.py
  U   zope.sendmail/trunk/src/zope/sendmail/tests/test_maildir.py

-=-
Modified: zope.sendmail/trunk/CHANGES.txt
===================================================================
--- zope.sendmail/trunk/CHANGES.txt	2010-01-06 18:10:43 UTC (rev 107750)
+++ zope.sendmail/trunk/CHANGES.txt	2010-01-06 20:38:46 UTC (rev 107751)
@@ -10,6 +10,9 @@
   is similar to the optional security support introduced in ``zope.component``
   3.8.0, and in fact it uses the same helpers.
 
+- Sort by modification time the messages in zope.sendmail.maildir so earlier
+  messages are sent before later messages during queue processing.
+
 3.6.1 (2009-11-16)
 ------------------
 

Modified: zope.sendmail/trunk/src/zope/sendmail/maildir.py
===================================================================
--- zope.sendmail/trunk/src/zope/sendmail/maildir.py	2010-01-06 18:10:43 UTC (rev 107750)
+++ zope.sendmail/trunk/src/zope/sendmail/maildir.py	2010-01-06 20:38:46 UTC (rev 107751)
@@ -71,7 +71,12 @@
                         if not x.startswith('.')]
         cur_messages = [join(subdir_cur, x) for x in os.listdir(subdir_cur)
                         if not x.startswith('.')]
-        return iter(new_messages + cur_messages)
+        # Sort by modification time so earlier messages are sent before
+        # later messages during queue processing.
+        msgs_sorted = [(m, os.path.getmtime(m)) for m 
+                      in new_messages + cur_messages]
+        msgs_sorted.sort(key=lambda x: x[1])
+        return iter([m[0] for m in msgs_sorted])
 
     def newMessage(self):
         "See `zope.sendmail.interfaces.IMaildir`"

Modified: zope.sendmail/trunk/src/zope/sendmail/tests/test_maildir.py
===================================================================
--- zope.sendmail/trunk/src/zope/sendmail/tests/test_maildir.py	2010-01-06 18:10:43 UTC (rev 107750)
+++ zope.sendmail/trunk/src/zope/sendmail/tests/test_maildir.py	2010-01-06 20:38:46 UTC (rev 107751)
@@ -44,6 +44,10 @@
     def __init__(self, files, dirs):
         self.files = files
         self.dirs = dirs
+        mtimes = {}
+        for t,f in enumerate(files):
+            mtimes[f] = 9999 - t
+        self._mtimes = mtimes
 
     def join(self, *args):
         return '/'.join(args)
@@ -51,7 +55,10 @@
     def isdir(self, dir):
         return dir in self.dirs
 
+    def getmtime(self, f):
+        return self._mtimes.get(f, 10000)
 
+
 class FakeOsModule(object):
 
     F_OK = 0
@@ -223,11 +230,10 @@
         from zope.sendmail.maildir import Maildir
         m = Maildir('/path/to/maildir')
         messages = list(m)
-        messages.sort()
-        self.assertEquals(messages, ['/path/to/maildir/cur/1',
-                                     '/path/to/maildir/cur/2',
-                                     '/path/to/maildir/new/1',
-                                     '/path/to/maildir/new/2'])
+        self.assertEquals(messages, ['/path/to/maildir/cur/2',
+                                     '/path/to/maildir/cur/1',
+                                     '/path/to/maildir/new/2',
+                                     '/path/to/maildir/new/1'])
 
     def test_newMessage(self):
         from zope.sendmail.maildir import Maildir



More information about the checkins mailing list