Commit ae03ca94 authored by Andreas Jung's avatar Andreas Jung

     - Collector #893: Mailhost: munge_header has been broken for addresses
       containing the recipients full name
parent 21c6c294
......@@ -71,6 +71,9 @@ Zope Changes
Bugs Fixed
- Collector #893: Mailhost: munge_header has been broken for addresses
containing the recipients full name
- Collector #342: Avoiding insertion of a BASE tag for file objects
with content-type text/html
......
......@@ -11,8 +11,8 @@
#
##############################################################################
"""SMTP mail objects
$Id: MailHost.py,v 1.79 2003/03/04 16:29:12 shane Exp $"""
__version__ = "$Revision: 1.79 $"[11:-2]
$Id: MailHost.py,v 1.80 2003/07/07 16:04:16 andreasjung Exp $"""
__version__ = "$Revision: 1.80 $"[11:-2]
from Globals import Persistent, DTMLFile, InitializeClass
from smtplib import SMTP
......@@ -183,7 +183,7 @@ def _mungeHeaders( messageText, mto=None, mfrom=None, subject=None):
if mto:
if isinstance(mto, types.StringType):
mto=map(lambda x:x.strip(), mto.split(','))
mto = [rfc822.dump_address_pair(addr) for addr in rfc822.AddressList(mto) ]
if not mo.getheader('To'):
mo['To'] = ','.join(mto)
else:
......@@ -191,7 +191,7 @@ def _mungeHeaders( messageText, mto=None, mfrom=None, subject=None):
for header in ('To', 'Cc', 'Bcc'):
v = mo.getheader(header)
if v:
mto += [addr.strip() for addr in v.split(',')]
mto += [rfc822.dump_address_pair(addr) for addr in rfc822.AddressList(v)]
if not mto:
raise MailHostError, "No message recipients designated"
......
......@@ -55,6 +55,27 @@ This is the message body."""
self.failUnless(resfrom == 'me@example.com' )
def testAddressParser( self ):
msg = """To: "Name, Nick" <recipient@domain.com>, "Foo Bar" <foo@domain.com>
CC: "Web, Jack" <jack@web.com>
From: sender@domain.com
Subject: This is the subject
This is the message body."""
# Test Address-Parser for To & CC given in messageText
resmsg, resto, resfrom = _mungeHeaders( msg )
self.failUnless(resto == ['"Name, Nick" <recipient@domain.com>','"Foo Bar" <foo@domain.com>','"Web, Jack" <jack@web.com>'])
self.failUnless(resfrom == 'sender@domain.com' )
# Test Address-Parser for a given mto-string
resmsg, resto, resfrom = _mungeHeaders( msg, mto= '"Public, Joe" <pjoe@domain.com>, "Foo Bar" <foo@domain.com>')
self.failUnless(resto == ['"Public, Joe" <pjoe@domain.com>','"Foo Bar" <foo@domain.com>'])
self.failUnless(resfrom == 'sender@domain.com' )
def test_suite():
suite = unittest.TestSuite()
suite.addTest( unittest.makeSuite( TestMailHost ) )
......
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