[Zope-Checkins] SVN: Zope/trunk/lib/python/Products/MailHost/ - added IMailHost interface

Yvo Schubbe y.2005- at wcm-solutions.de
Sun Oct 2 09:09:03 EDT 2005


Log message for revision 38715:
  - added IMailHost interface
  - some cleanup

Changed:
  UU  Zope/trunk/lib/python/Products/MailHost/MailHost.py
  A   Zope/trunk/lib/python/Products/MailHost/interfaces.py
  UU  Zope/trunk/lib/python/Products/MailHost/tests/testMailHost.py

-=-
Modified: Zope/trunk/lib/python/Products/MailHost/MailHost.py
===================================================================
--- Zope/trunk/lib/python/Products/MailHost/MailHost.py	2005-10-02 13:02:19 UTC (rev 38714)
+++ Zope/trunk/lib/python/Products/MailHost/MailHost.py	2005-10-02 13:09:02 UTC (rev 38715)
@@ -7,28 +7,38 @@
 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE
+# FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
 """SMTP mail objects
-$Id$"""
-__version__ = "$Revision: 1.83 $"[11:-2]
 
-from Globals import Persistent, DTMLFile, InitializeClass
+$Id$
+"""
+
+import mimetools
+import rfc822
+from cStringIO import StringIO
 from smtplib import SMTP
+
+import Acquisition
+import OFS.SimpleItem
+from AccessControl import ClassSecurityInfo
+from AccessControl.Permissions import change_configuration
+from AccessControl.Permissions import use_mailhost_services
+from AccessControl.Permissions import view_management_screens
 from AccessControl.Role import RoleManager
-from operator import truth
-import Acquisition, sys, types, mimetools
-import OFS.SimpleItem, re, quopri, rfc822
-from cStringIO import StringIO
-from AccessControl import ClassSecurityInfo
-from AccessControl.Permissions import view_management_screens, \
-                                      use_mailhost_services
+from Globals import Persistent, DTMLFile, InitializeClass
 from DateTime import DateTime
+from zope.interface import implements
 
-class MailHostError( Exception ):
+from interfaces import IMailHost
+
+
+class MailHostError(Exception):
+
     pass
 
+
 manage_addMailHostForm=DTMLFile('dtml/addMailHost_form', globals())
 def manage_addMailHost( self, id, title='', smtp_host='localhost'
                       , localhost='localhost', smtp_port=25
@@ -42,8 +52,13 @@
 
 add = manage_addMailHost
 
+
 class MailBase(Acquisition.Implicit, OFS.SimpleItem.Item, RoleManager):
+
     'a mailhost...?'
+
+    implements(IMailHost)
+
     meta_type='Mail Host'
     manage=manage_main=DTMLFile('dtml/manageMailHost', globals())
     manage_main._setName('manage_main')
@@ -81,8 +96,7 @@
         self.smtp_host=smtp_host
         self.smtp_port=smtp_port
 
-
-    security.declareProtected( 'Change configuration', 'manage_makeChanges' )
+    security.declareProtected(change_configuration, 'manage_makeChanges')
     def manage_makeChanges(self,title,smtp_host,smtp_port,smtp_uid='',smtp_pwd='', REQUEST=None):
         'make the changes'
 
@@ -102,8 +116,7 @@
                                    , manage_tabs_message=msg
                                    )
 
-
-    security.declareProtected( use_mailhost_services, 'sendTemplate' )
+    security.declareProtected(use_mailhost_services, 'sendTemplate')
     def sendTemplate(trueself, self, messageTemplate,
                      statusTemplate=None, mto=None, mfrom=None,
                      encode=None, REQUEST=None):
@@ -122,8 +135,7 @@
         except:
             return "SEND OK"
 
-
-    security.declareProtected( use_mailhost_services, 'send' )
+    security.declareProtected(use_mailhost_services, 'send')
     def send(self, messageText, mto=None, mfrom=None, subject=None,
              encode=None):
 
@@ -131,21 +143,19 @@
         messageText = _encode(messageText, encode)
         self._send(mfrom, mto, messageText)
 
-
     # 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?
-    security.declareProtected( use_mailhost_services, 'scheduledSend' )
+    security.declareProtected(use_mailhost_services, 'scheduledSend')
     scheduledSend = send
 
-    security.declareProtected( use_mailhost_services, 'simple_send' )
+    security.declareProtected(use_mailhost_services, 'simple_send')
     def simple_send(self, mto, mfrom, subject, body):
         body="From: %s\nTo: %s\nSubject: %s\n\n%s" % (
             mfrom, mto, subject, body)
 
         self._send( mfrom, mto, body )
 
-
-    security.declarePrivate( '_send' )
+    security.declarePrivate('_send')
     def _send( self, mfrom, mto, messageText ):
         """ Send the message """
         smtpserver = SMTP(self.smtp_host, int(self.smtp_port) )
@@ -154,12 +164,14 @@
         smtpserver.sendmail( mfrom, mto, messageText )
         smtpserver.quit()
 
+InitializeClass(MailBase)
 
-InitializeClass( MailBase )
 
 class MailHost(Persistent, MailBase):
+
     "persistent version"
 
+
 def _encode(body, encode=None):
     if encode is None:
         return body
@@ -191,7 +203,7 @@
         mo['Subject'] = '[No Subject]'
 
     if mto:
-        if isinstance(mto, types.StringType):
+        if isinstance(mto, basestring):
             mto = [rfc822.dump_address_pair(addr) for addr in rfc822.AddressList(mto) ]
         if not mo.getheader('To'):
             mo['To'] = ','.join(mto)


Property changes on: Zope/trunk/lib/python/Products/MailHost/MailHost.py
___________________________________________________________________
Name: cvs2svn:cvs-rev
   - 1.83

Added: Zope/trunk/lib/python/Products/MailHost/interfaces.py
===================================================================
--- Zope/trunk/lib/python/Products/MailHost/interfaces.py	2005-10-02 13:02:19 UTC (rev 38714)
+++ Zope/trunk/lib/python/Products/MailHost/interfaces.py	2005-10-02 13:09:02 UTC (rev 38715)
@@ -0,0 +1,25 @@
+##############################################################################
+#
+# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""MailHost z3 interfaces.
+
+$Id$
+"""
+
+from zope.interface import Interface
+
+
+class IMailHost(Interface):
+
+    def send(messageText, mto=None, mfrom=None, subject=None, encode=None):
+        """Send mail.
+        """


Property changes on: Zope/trunk/lib/python/Products/MailHost/interfaces.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: Zope/trunk/lib/python/Products/MailHost/tests/testMailHost.py
===================================================================
--- Zope/trunk/lib/python/Products/MailHost/tests/testMailHost.py	2005-10-02 13:02:19 UTC (rev 38714)
+++ Zope/trunk/lib/python/Products/MailHost/tests/testMailHost.py	2005-10-02 13:09:02 UTC (rev 38715)
@@ -1,11 +1,38 @@
-import os, sys, unittest
+##############################################################################
+#
+# Copyright (c) 2002 Zope Corporation and Contributors. All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""MailHost unit tests.
 
-import string, cStringIO, re
-import ZODB, Acquisition
+$Id$
+"""
+
+import unittest
+
 from Products.MailHost.MailHost import MailHostError, _mungeHeaders
 
-class TestMailHost( unittest.TestCase ):
 
+class TestMailHost(unittest.TestCase):
+
+    def _getTargetClass(self):
+        from Products.MailHost.MailHost import MailHost
+
+        return MailHost
+
+    def test_z3interfaces(self):
+        from Products.MailHost.interfaces import IMailHost
+        from zope.interface.verify import verifyClass
+
+        verifyClass(IMailHost, self._getTargetClass())
+
     def testAllHeaders( self ):
         msg = """To: recipient at domain.com
 From: sender at domain.com
@@ -18,12 +45,14 @@
         self.failUnless(resfrom == 'sender at domain.com' )
 
         # Add duplicated info
-        resmsg, resto, resfrom = _mungeHeaders( msg, 'recipient at domain.com', 'sender at domain.com', 'This is the subject' )
+        resmsg, resto, resfrom = _mungeHeaders(msg, 'recipient at domain.com',
+                                  'sender at domain.com', 'This is the subject' )
         self.failUnless(resto == ['recipient at domain.com'])
         self.failUnless(resfrom == 'sender at domain.com' )
 
         # Add extra info
-        resmsg, resto, resfrom = _mungeHeaders( msg, 'recipient2 at domain.com', 'sender2 at domain.com', 'This is the real subject' )
+        resmsg, resto, resfrom = _mungeHeaders(msg, 'recipient2 at domain.com',
+                            'sender2 at domain.com', 'This is the real subject' )
         self.failUnless(resto == ['recipient2 at domain.com'])
         self.failUnless(resfrom == 'sender2 at domain.com' )
 
@@ -32,18 +61,23 @@
 
 This is the message body."""
         # Doesn't specify to
-        self.failUnlessRaises( MailHostError, _mungeHeaders, msg, mfrom='sender at domain.com' )
+        self.failUnlessRaises(MailHostError, _mungeHeaders, msg,
+                              mfrom='sender at domain.com')
         # Doesn't specify from
-        self.failUnlessRaises( MailHostError, _mungeHeaders, msg, mto='recipient at domain.com' )
+        self.failUnlessRaises(MailHostError, _mungeHeaders, msg,
+                              mto='recipient at domain.com')
 
     def testNoHeaders( self ):
         msg = """This is the message body."""
         # Doesn't specify to
-        self.failUnlessRaises( MailHostError, _mungeHeaders, msg, mfrom='sender at domain.com' )
+        self.failUnlessRaises(MailHostError, _mungeHeaders, msg,
+                              mfrom='sender at domain.com')
         # Doesn't specify from
-        self.failUnlessRaises( MailHostError, _mungeHeaders, msg, mto='recipient at domain.com' )
+        self.failUnlessRaises(MailHostError, _mungeHeaders, msg,
+                              mto='recipient at domain.com')
         # Specify all
-        resmsg, resto, resfrom = _mungeHeaders( msg, 'recipient2 at domain.com', 'sender2 at domain.com', 'This is the real subject' )
+        resmsg, resto, resfrom = _mungeHeaders(msg, 'recipient2 at domain.com',
+                             'sender2 at domain.com', 'This is the real subject')
         self.failUnless(resto == ['recipient2 at domain.com'])
         self.failUnless(resfrom == 'sender2 at domain.com' )
 
@@ -66,23 +100,24 @@
         # Test Address-Parser for To & CC given in messageText
         
         resmsg, resto, resfrom = _mungeHeaders( msg )
-        self.failUnless(resto == ['"Name, Nick" <recipient at domain.com>','"Foo Bar" <foo at domain.com>','"Web, Jack" <jack at web.com>'])
+        self.failUnless(resto == ['"Name, Nick" <recipient at domain.com>',
+                                  '"Foo Bar" <foo at domain.com>',
+                                  '"Web, Jack" <jack at web.com>'])
         self.failUnless(resfrom == 'sender at domain.com' )
 
         # Test Address-Parser for a given mto-string
         
-        resmsg, resto, resfrom = _mungeHeaders( msg, mto= '"Public, Joe" <pjoe at domain.com>, "Foo Bar" <foo at domain.com>')
+        resmsg, resto, resfrom = _mungeHeaders(msg, mto= '"Public, Joe" <pjoe at domain.com>, "Foo Bar" <foo at domain.com>')
 
-        self.failUnless(resto == ['"Public, Joe" <pjoe at domain.com>','"Foo Bar" <foo at domain.com>'])
+        self.failUnless(resto == ['"Public, Joe" <pjoe at domain.com>',
+                                  '"Foo Bar" <foo at domain.com>'])
         self.failUnless(resfrom == 'sender at domain.com' )
 
+
 def test_suite():
     suite = unittest.TestSuite()
     suite.addTest( unittest.makeSuite( TestMailHost ) )
     return suite
 
-def main():
-    unittest.TextTestRunner().run(test_suite())
-
 if __name__ == '__main__':
-    main()
+    unittest.main(defaultTest='test_suite')


Property changes on: Zope/trunk/lib/python/Products/MailHost/tests/testMailHost.py
___________________________________________________________________
Name: cvs2svn:cvs-rev
   - 1.5
Name: svn:keywords
   + Id



More information about the Zope-Checkins mailing list