Commit 67e5157b authored by Alec Mitchell's avatar Alec Mitchell

Use a public method of the email module for generating address lists.

parent 77a3a5a5
...@@ -30,7 +30,6 @@ except ImportError: ...@@ -30,7 +30,6 @@ except ImportError:
import email.Charset import email.Charset
# We import from a private module here because the email module # We import from a private module here because the email module
# doesn't provide a good public address list parser # doesn't provide a good public address list parser
from email._parseaddr import AddressList as _AddressList
import uu import uu
from threading import Lock from threading import Lock
...@@ -68,6 +67,7 @@ LOG = logging.getLogger('MailHost') ...@@ -68,6 +67,7 @@ LOG = logging.getLogger('MailHost')
email.Charset.add_charset("utf-8", email.Charset.QP, email.Charset.QP, "utf-8") email.Charset.add_charset("utf-8", email.Charset.QP, email.Charset.QP, "utf-8")
formataddr = emailutils.formataddr formataddr = emailutils.formataddr
parseaddr = emailutils.parseaddr parseaddr = emailutils.parseaddr
getaddresses = emailutils.getaddresses
CHARSET_RE = re.compile('charset=[\'"]?([\w-]+)[\'"]?', re.IGNORECASE) CHARSET_RE = re.compile('charset=[\'"]?([\w-]+)[\'"]?', re.IGNORECASE)
class MailHostError(Exception): class MailHostError(Exception):
...@@ -442,7 +442,7 @@ def _mungeHeaders(messageText, mto=None, mfrom=None, subject=None, ...@@ -442,7 +442,7 @@ def _mungeHeaders(messageText, mto=None, mfrom=None, subject=None,
if mto: if mto:
if isinstance(mto, basestring): 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'): if not mo.get('To'):
mo['To'] = ', '.join(str(_encode_address_string(e, charset)) mo['To'] = ', '.join(str(_encode_address_string(e, charset))
for e in mto) for e in mto)
...@@ -452,8 +452,7 @@ def _mungeHeaders(messageText, mto=None, mfrom=None, subject=None, ...@@ -452,8 +452,7 @@ def _mungeHeaders(messageText, mto=None, mfrom=None, subject=None,
for header in ('To', 'Cc', 'Bcc'): for header in ('To', 'Cc', 'Bcc'):
v = ','.join(mo.get_all(header) or []) v = ','.join(mo.get_all(header) or [])
if v: if v:
mto += [formataddr(addr) for addr in mto += [formataddr(addr) for addr in getaddresses((v,))]
_AddressList(v).addresslist]
if not mto: if not mto:
raise MailHostError, "No message recipients designated" raise MailHostError, "No message recipients designated"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment