Commit dbc879f1 authored by Shane Hathaway's avatar Shane Hathaway

Restored MailHost's ability to send bulk emails using the "Bcc" header to

avoid disclosing the recipients.
parent 23927884
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
# #
############################################################################## ##############################################################################
"""SMTP mail objects """SMTP mail objects
$Id: MailHost.py,v 1.78 2003/02/22 15:13:32 andreasjung Exp $""" $Id: MailHost.py,v 1.79 2003/03/04 16:29:12 shane Exp $"""
__version__ = "$Revision: 1.78 $"[11:-2] __version__ = "$Revision: 1.79 $"[11:-2]
from Globals import Persistent, DTMLFile, InitializeClass from Globals import Persistent, DTMLFile, InitializeClass
from smtplib import SMTP from smtplib import SMTP
...@@ -187,13 +187,13 @@ def _mungeHeaders( messageText, mto=None, mfrom=None, subject=None): ...@@ -187,13 +187,13 @@ def _mungeHeaders( messageText, mto=None, mfrom=None, subject=None):
if not mo.getheader('To'): if not mo.getheader('To'):
mo['To'] = ','.join(mto) mo['To'] = ','.join(mto)
else: else:
if not mo.getheader('To'): mto = []
raise MailHostError,"Message missing SMTP Header 'To'" for header in ('To', 'Cc', 'Bcc'):
mto = map(lambda x:x.strip(), mo['To'].split(',')) v = mo.getheader(header)
if mo.getheader('Cc'): if v:
mto = mto + map(lambda x:x.strip(), mo['Cc'].split(',')) mto += [addr.strip() for addr in v.split(',')]
if mo.getheader('Bcc'): if not mto:
mto = mto + map(lambda x:x.strip(), mo['Bcc'].split(',')) raise MailHostError, "No message recipients designated"
if mfrom: if mfrom:
mo['From'] = mfrom mo['From'] = mfrom
......
...@@ -47,6 +47,14 @@ This is the message body.""" ...@@ -47,6 +47,14 @@ This is the message body."""
self.failUnless(resto == ['recipient2@domain.com']) self.failUnless(resto == ['recipient2@domain.com'])
self.failUnless(resfrom == 'sender2@domain.com' ) self.failUnless(resfrom == 'sender2@domain.com' )
def testBCCHeader( self ):
msg = "From: me@example.com\nBcc: many@example.com\n\nMessage text"
# Specify only the "Bcc" header. Useful for bulk emails.
resmsg, resto, resfrom = _mungeHeaders(msg)
self.failUnless(resto == ['many@example.com'])
self.failUnless(resfrom == 'me@example.com' )
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest( unittest.makeSuite( TestMailHost ) ) 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