[Zope-Checkins] SVN: Zope/trunk/src/Products/MailHost/MailHost.py Use a public method of the email module for generating address lists.

Alec Mitchell alecpm at gmail.com
Sat Aug 15 12:05:46 EDT 2009


Log message for revision 102819:
  Use a public method of the email module for generating address lists.
  

Changed:
  U   Zope/trunk/src/Products/MailHost/MailHost.py

-=-
Modified: Zope/trunk/src/Products/MailHost/MailHost.py
===================================================================
--- Zope/trunk/src/Products/MailHost/MailHost.py	2009-08-15 15:59:19 UTC (rev 102818)
+++ Zope/trunk/src/Products/MailHost/MailHost.py	2009-08-15 16:05:46 UTC (rev 102819)
@@ -30,7 +30,6 @@
 import email.Charset
 # We import from a private module here because the email module
 # doesn't provide a good public address list parser
-from email._parseaddr import AddressList as _AddressList
 import uu
 
 from threading import Lock
@@ -68,6 +67,7 @@
 email.Charset.add_charset("utf-8", email.Charset.QP, email.Charset.QP, "utf-8")
 formataddr = emailutils.formataddr
 parseaddr = emailutils.parseaddr
+getaddresses = emailutils.getaddresses
 CHARSET_RE = re.compile('charset=[\'"]?([\w-]+)[\'"]?', re.IGNORECASE)
 
 class MailHostError(Exception):
@@ -442,7 +442,7 @@
 
     if mto:
         if isinstance(mto, basestring):
-            mto = [formataddr(addr) for addr in _AddressList(mto).addresslist]
+            mto = [formataddr(addr) for addr in getaddresses((mto,))]
         if not mo.get('To'):
             mo['To'] = ', '.join(str(_encode_address_string(e, charset))
                                  for e in mto)
@@ -452,8 +452,7 @@
         for header in ('To', 'Cc', 'Bcc'):
             v = ','.join(mo.get_all(header) or [])
             if v:
-                mto += [formataddr(addr) for addr in
-                        _AddressList(v).addresslist]
+                mto += [formataddr(addr) for addr in getaddresses((v,))]
         if not mto:
             raise MailHostError, "No message recipients designated"
 



More information about the Zope-Checkins mailing list