[Zope-Checkins] CVS: Zope/lib/python/Products/MailHost - MailHost.py:1.70.12.2

Torped Strategy and Communications info@torped.se
Mon, 18 Mar 2002 12:52:18 -0500


Update of /cvs-repository/Zope/lib/python/Products/MailHost
In directory cvs.zope.org:/tmp/cvs-serv19331/lib/python/Products/MailHost

Modified Files:
      Tag: regebro-case_177-branch
	MailHost.py 
Log Message:
Changed from string module functions to string object methods. Changes from "is type" to "isinstance". Removed a couple of uneccesary type checks.

=== Zope/lib/python/Products/MailHost/MailHost.py 1.70.12.1 => 1.70.12.2 ===
 from AccessControl.Role import RoleManager
 from operator import truth
-import Acquisition, sys, string, types, mimetools
+import Acquisition, sys, types, mimetools
 import OFS.SimpleItem, re, quopri, rfc822
 from cStringIO import StringIO
 from AccessControl import ClassSecurityInfo
@@ -67,9 +67,7 @@
         self.id = id
         self.title = title
         self.smtp_host = str( smtp_host )
-        if type(smtp_port) is not type(1):
-            smtp_port=string.atoi(smtp_port)
-        self.smtp_port = smtp_port
+        self.smtp_port = int(smtp_port)
 
 
     # staying for now... (backwards compatibility)
@@ -84,8 +82,7 @@
 
         title=str(title)
         smtp_host=str(smtp_host)
-        if type(smtp_port) is not type(1):
-            smtp_port=string.atoi(smtp_port)
+        smtp_port=int(smtp_port)
 
         self.title=title
         self.smtp_host=smtp_host
@@ -161,7 +158,7 @@
     if mo.getencoding() != '7bit': 
         raise MailHostError, 'Message already encoded'
     newmfile=StringIO()
-    newmfile.write(string.joinfields(mo.headers, ''))
+    newmfile.write(''.join(mo.headers))
     newmfile.write('Content-Transfer-Encoding: %s\n' % encode)
     if not mo.has_key('Mime-Version'):
         newmfile.write('Mime-Version: 1.0\n')
@@ -169,15 +166,14 @@
     mimetools.encode(mfile, newmfile, encode)
     return newmfile.getvalue()
 
-
 def _mungeHeaders( messageText, mto=None, mfrom=None, subject=None):
     """Sets missing message headers, and deletes Bcc.
        returns fixed message, fixed mto and fixed mfrom"""
-    mfile=StringIO(string.strip(messageText))
+    mfile=StringIO(messageText.strip())
     mo=rfc822.Message(mfile)
 
     # Parameters given will *always* override headers in the messageText.
-    # This is so that you can't override or add to them by adding them to
+    # This is so that you can't override or add to subscribers by adding them to
     # the message text.
     if subject:
         mo['Subject'] = subject
@@ -185,17 +181,17 @@
         mo['Subject'] = '[No Subject]'
 
     if mto:
-        if type(mto) is type('s'):
-            mto=map(string.strip, string.split(mto,','))
-        mo['To'] = string.join(mto, ',')
+        if isinstance(mto, types.StringType):
+            mto=map(lambda x:x.strip(), mto.split(','))
+        mo['To'] = ','.join(mto)
     else:
         if not mo.getheader('To'):
             raise MailHostError,"Message missing SMTP Header 'To'"
-        mto = map(string.strip, string.split(mo['To'],','))
+        mto = map(lambda x:x.strip(), mo['To'].split(','))
         if mo.getheader('Cc'):
-            mto = mto + map(string.strip, string.split(mo['Cc'],','))
+            mto = mto + map(lambda x:x.strip(), mo['Cc'].split(','))
         if mo.getheader('Bcc'):
-            mto = mto + map(string.strip, string.split(mo['Bcc'],','))
+            mto = mto + map(lambda x:x.strip(), mo['Bcc'].split(','))
 
     if mfrom:
         mo['From'] = mfrom