Log message for revision 88311:
        - Launchpad #246748: added 'immediate' option to sendXXX() methods
          for sending a mail immediately by-passing the zope.sendmail delivery
          mechanism
  

Changed:
  U   Zope/branches/2.11/doc/CHANGES.txt
  U   Zope/branches/2.11/lib/python/Products/MailHost/MailHost.py
  U   Zope/branches/2.11/lib/python/Products/MailHost/tests/testMailHost.py

-=-
Modified: Zope/branches/2.11/doc/CHANGES.txt
===================================================================
--- Zope/branches/2.11/doc/CHANGES.txt  2008-07-13 10:49:19 UTC (rev 88310)
+++ Zope/branches/2.11/doc/CHANGES.txt  2008-07-13 10:53:06 UTC (rev 88311)
@@ -7,6 +7,10 @@
   After Zope 2.11.0
 
     Bugs Fixed
+
+      - Launchpad #246748: added 'immediate' option to sendXXX() methods
+        for sending a mail immediately by-passing the zope.sendmail delivery
+        mechanism
     
       - Launchpad #246290: fixed backward compatibility issue
 

Modified: Zope/branches/2.11/lib/python/Products/MailHost/MailHost.py
===================================================================
--- Zope/branches/2.11/lib/python/Products/MailHost/MailHost.py 2008-07-13 
10:49:19 UTC (rev 88310)
+++ Zope/branches/2.11/lib/python/Products/MailHost/MailHost.py 2008-07-13 
10:53:06 UTC (rev 88311)
@@ -155,15 +155,16 @@
     security.declareProtected(use_mailhost_services, 'sendTemplate')
     def sendTemplate(trueself, self, messageTemplate,
                      statusTemplate=None, mto=None, mfrom=None,
-                     encode=None, REQUEST=None):
+                     encode=None, REQUEST=None, immediate=False):
         'render a mail template, then send it...'
         mtemplate = getattr(self, messageTemplate)
         messageText = mtemplate(self, trueself.REQUEST)
         messageText, mto, mfrom = _mungeHeaders( messageText, mto, mfrom)
         messageText=_encode(messageText, encode)
-        trueself._send(mfrom, mto, messageText)
+        trueself._send(mfrom, mto, messageText, immediate)
 
-        if not statusTemplate: return "SEND OK"
+        if not statusTemplate: 
+            return "SEND OK"
 
         try:
             stemplate=getattr(self, statusTemplate)
@@ -173,11 +174,11 @@
 
     security.declareProtected(use_mailhost_services, 'send')
     def send(self, messageText, mto=None, mfrom=None, subject=None,
-             encode=None):
+             encode=None, immediate=False):
 
         messageText, mto, mfrom = _mungeHeaders( messageText, mto, mfrom, 
subject)
         messageText = _encode(messageText, encode)
-        self._send(mfrom, mto, messageText)
+        self._send(mfrom, mto, messageText, immediate)
 
     # This is here for backwards compatibility only. Possibly it could
     # be used to send messages at a scheduled future time, or via a mail queue?
@@ -185,11 +186,11 @@
     scheduledSend = send
 
     security.declareProtected(use_mailhost_services, 'simple_send')
-    def simple_send(self, mto, mfrom, subject, body):
+    def simple_send(self, mto, mfrom, subject, body, immediate=False):
         body="From: %s\nTo: %s\nSubject: %s\n\n%s" % (
             mfrom, mto, subject, body)
 
-        self._send( mfrom, mto, body )
+        self._send(mfrom, mto, body, immediate)
 
 
     def _makeMailer(self):
@@ -218,7 +219,7 @@
     @synchronized(lock)
     def _startQueueProcessorThread(self):
         """ Start thread for processing the mail queue """
-        
+
         path = self.absolute_url(1)
         if not queue_threads.has_key(path):
             thread = QueueProcessorThread()
@@ -228,7 +229,6 @@
             queue_threads[path] = thread     
             LOG.info('Thread for %s started' % path)
 
-     
     security.declareProtected(view, 'queueLength')
     def queueLength(self):
         """ return length of mail queue """
@@ -268,17 +268,20 @@
 
 
     security.declarePrivate('_send')
-    def _send(self, mfrom, mto, messageText):
+    def _send(self, mfrom, mto, messageText, immediate=False):
         """ Send the message """
 
-        if self.smtp_queue:
-            # Start queue processor thread, if necessary
-            self._startQueueProcessorThread()
-            delivery = QueuedMailDelivery(self.smtp_queue_directory)
+        if immediate:
+            self._makeMailer().send(mfrom, mto, messageText)
         else:
-            delivery = DirectMailDelivery(self._makeMailer())
+            if self.smtp_queue:
+                # Start queue processor thread, if necessary
+                self._startQueueProcessorThread()
+                delivery = QueuedMailDelivery(self.smtp_queue_directory)
+            else:
+                delivery = DirectMailDelivery(self._makeMailer())
 
-        delivery.send(mfrom, mto, messageText)                
+            delivery.send(mfrom, mto, messageText)
 
 InitializeClass(MailBase)
 

Modified: Zope/branches/2.11/lib/python/Products/MailHost/tests/testMailHost.py
===================================================================
--- Zope/branches/2.11/lib/python/Products/MailHost/tests/testMailHost.py       
2008-07-13 10:49:19 UTC (rev 88310)
+++ Zope/branches/2.11/lib/python/Products/MailHost/tests/testMailHost.py       
2008-07-13 10:53:06 UTC (rev 88311)
@@ -26,8 +26,9 @@
     def __init__(self, id):
         self.id = id
         self.sent = ''
-    def _send(self, mfrom, mto, messageText):
+    def _send(self, mfrom, mto, messageText, immediate=False):
         self.sent = messageText
+        self.immediate = immediate
 
 
 class TestMailHost(unittest.TestCase):
@@ -190,8 +191,24 @@
                              mfrom='[EMAIL PROTECTED]', subject='This is the 
subject',
                              body='This is the message body.')
         self.assertEqual(mailhost.sent, outmsg)
+        self.assertEqual(mailhost.immediate, False)
 
+    def testSendImmediate(self):
+        outmsg = """\
+From: [EMAIL PROTECTED]
+To: "Name, Nick" <[EMAIL PROTECTED]>, "Foo Bar" <[EMAIL PROTECTED]>
+Subject: This is the subject
 
+This is the message body."""
+
+        mailhost = self._makeOne('MailHost')
+        mailhost.simple_send(mto='"Name, Nick" <[EMAIL PROTECTED]>, "Foo Bar" 
<[EMAIL PROTECTED]>',
+                             mfrom='[EMAIL PROTECTED]', subject='This is the 
subject',
+                             body='This is the message body.', immediate=True)
+        self.assertEqual(mailhost.sent, outmsg)
+        self.assertEqual(mailhost.immediate, True)
+
+
 def test_suite():
     suite = unittest.TestSuite()
     suite.addTest( unittest.makeSuite( TestMailHost ) )

_______________________________________________
Zope-Checkins maillist  -  Zope-Checkins@zope.org
http://mail.zope.org/mailman/listinfo/zope-checkins

Reply via email to