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 @@
#
##############################################################################
"""SMTP mail objects
$Id: MailHost.py,v 1.78 2003/02/22 15:13:32 andreasjung Exp $"""
__version__ = "$Revision: 1.78 $"[11:-2]
$Id: MailHost.py,v 1.79 2003/03/04 16:29:12 shane Exp $"""
__version__ = "$Revision: 1.79 $"[11:-2]
from Globals import Persistent, DTMLFile, InitializeClass
from smtplib import SMTP
......@@ -187,13 +187,13 @@ def _mungeHeaders( messageText, mto=None, mfrom=None, subject=None):
if not mo.getheader('To'):
mo['To'] = ','.join(mto)
else:
if not mo.getheader('To'):
raise MailHostError,"Message missing SMTP Header 'To'"
mto = map(lambda x:x.strip(), mo['To'].split(','))
if mo.getheader('Cc'):
mto = mto + map(lambda x:x.strip(), mo['Cc'].split(','))
if mo.getheader('Bcc'):
mto = mto + map(lambda x:x.strip(), mo['Bcc'].split(','))
mto = []
for header in ('To', 'Cc', 'Bcc'):
v = mo.getheader(header)
if v:
mto += [addr.strip() for addr in v.split(',')]
if not mto:
raise MailHostError, "No message recipients designated"
if mfrom:
mo['From'] = mfrom
......
......@@ -47,6 +47,14 @@ This is the message body."""
self.failUnless(resto == ['recipient2@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():
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