Index: src/Products/MailHost/tests/testMailHost.py =================================================================== --- src/Products/MailHost/tests/testMailHost.py (revision 124734) +++ src/Products/MailHost/tests/testMailHost.py (working copy) @@ -26,6 +26,8 @@ self.id = id self.sent = '' def _send(self, mfrom, mto, messageText, immediate=False): + self.mfrom = mfrom + self.mto = mto self.sent = messageText self.immediate = immediate @@ -444,7 +446,8 @@ # We need to make sure we didn't mutate the message we were passed self.failIfEqual(out.as_string(), msg.as_string()) - self.failUnlessEqual(out['From'], 'Foo Bar ') + self.failUnlessEqual(out['From'], + '=?utf-8?q?Jos=C3=A9_Andr=C3=A9s?= ') self.failUnlessEqual(msg['From'], '=?utf-8?q?Jos=C3=A9_Andr=C3=A9s?= ') # The subject is encoded with the body encoding since no @@ -637,7 +640,37 @@ mailhost.send(msg, charset='utf-8') self.assertEqual(mailhost.sent, msg) + def testSMTPMailFromHeaderSetup(self): + msg = message_from_string("""\ +From: =?utf-8?q?Jos=C3=A9_Andr=C3=A9s?= +To: =?utf-8?q?Ferran_Adri=C3=A0?= +Subject: =?utf-8?q?=C2=BFEsferificaci=C3=B3n=3F?= +Date: Sun, 27 Aug 2006 17:00:00 +0200 +Content-Type: text/html; charset="utf-8" +Content-Transfer-Encoding: base64 +MIME-Version: 1.1 +wqFVbiB0cnVjbyA8c3Ryb25nPmZhbnTDoXN0aWNvPC9zdHJvbmc+IQ=3D=3D +""") + mailhost = self._makeOne('MailHost') + mailhost.send(msg, mfrom='Foo Bar ') + out = message_from_string(mailhost.sent) + + # We need to check if the 'From' header in message that we passed + # haven't changed. + self.failUnlessEqual(out['From'], msg['From']) + + # We need to make sure that proper 'SMTP MAIL FROM' header was send. + self.failUnlessEqual(mailhost.mfrom, 'Foo Bar ') + + # If 'From' header is missing in the message + # it should be added with 'MAIL FROM' SMTP Envelope header value. + del msg['From'] + mailhost.send(msg, mfrom='Foo Bar ') + out = message_from_string(mailhost.sent) + self.failUnlessEqual(out['From'], 'Foo Bar ') + + def test_suite(): suite = unittest.TestSuite() suite.addTest(unittest.makeSuite(TestMailHost)) Index: src/Products/MailHost/MailHost.py =================================================================== --- src/Products/MailHost/MailHost.py (revision 124734) +++ src/Products/MailHost/MailHost.py (working copy) @@ -450,10 +450,8 @@ raise MailHostError("No message recipients designated") if mfrom: - # XXX: do we really want to override an explicitly set From - # header in the messageText - del mo['From'] - mo['From'] = _encode_address_string(mfrom, charset) + if not mo['From']: + mo['From'] = _encode_address_string(mfrom, charset) else: if mo.get('From') is None: raise MailHostError("Message missing SMTP Header 'From'")