Log message for revision 69800: Fixed MailHost documentation; simple_send does not process or validate its arguments in any way. Resolves http://www.zope.org/Collectors/Zope/2152
Changed: U Zope/branches/2.9/doc/CHANGES.txt U Zope/branches/2.9/lib/python/Products/MailHost/help/Mail-Host.stx U Zope/branches/2.9/lib/python/Products/MailHost/help/MailHost.py U Zope/branches/2.9/lib/python/Products/MailHost/tests/testMailHost.py -=- Modified: Zope/branches/2.9/doc/CHANGES.txt =================================================================== --- Zope/branches/2.9/doc/CHANGES.txt 2006-08-27 15:39:55 UTC (rev 69799) +++ Zope/branches/2.9/doc/CHANGES.txt 2006-08-27 16:01:41 UTC (rev 69800) @@ -8,6 +8,9 @@ Bugs fixed + - Collector #2152: Fixed MailHost documentation; simple_send does not + process or validate its arguments in any way. + - Collector #2175: ZTUtils.make_hidden_input did not escape double-quotes. - Collector #1907: Moved 'alt' property from File to Image. Modified: Zope/branches/2.9/lib/python/Products/MailHost/help/Mail-Host.stx =================================================================== --- Zope/branches/2.9/lib/python/Products/MailHost/help/Mail-Host.stx 2006-08-27 15:39:55 UTC (rev 69799) +++ Zope/branches/2.9/lib/python/Products/MailHost/help/Mail-Host.stx 2006-08-27 16:01:41 UTC (rev 69800) @@ -10,7 +10,7 @@ Sends an email message where the messageText is an rfc822 formatted message. This allows you complete control over the message headers, - including setting any extra headers such as Cc: and Bcc:. + including setting any extra headers such as Cc: and Reply-To:. The arguments are: messageText -- The mail message. It can either be a rfc822 @@ -31,9 +31,11 @@ 'simple_send(self, mto, mfrom, subject, body)' Sends a message. Only To:, From: and Subject: headers can be set. + Note that simple_send does not process or validate its arguments + in any way. The arguments are: - mto -- A commaseparated string or list of recipient(s) of the message. + mto -- A commaseparated string of recipient(s) of the message. mfrom -- The address of the message sender. Modified: Zope/branches/2.9/lib/python/Products/MailHost/help/MailHost.py =================================================================== --- Zope/branches/2.9/lib/python/Products/MailHost/help/MailHost.py 2006-08-27 15:39:55 UTC (rev 69799) +++ Zope/branches/2.9/lib/python/Products/MailHost/help/MailHost.py 2006-08-27 16:01:41 UTC (rev 69800) @@ -37,7 +37,7 @@ """ Sends an email message where the messageText is an rfc822 formatted message. This allows you complete control over the message headers, - including setting any extra headers such as Cc: and Bcc:. + including setting any extra headers such as Cc: and Reply-To:. The arguments are: messageText -- The mail message. It can either be a rfc822 @@ -60,9 +60,11 @@ def simple_send(self, mto, mfrom, subject, body): """ Sends a message. Only To:, From: and Subject: headers can be set. + Note that simple_send does not process or validate its arguments + in any way. The arguments are: - mto -- A commaseparated string or list of recipient(s) of the message. + mto -- A commaseparated string of recipient(s) of the message. mfrom -- The address of the message sender. Modified: Zope/branches/2.9/lib/python/Products/MailHost/tests/testMailHost.py =================================================================== --- Zope/branches/2.9/lib/python/Products/MailHost/tests/testMailHost.py 2006-08-27 15:39:55 UTC (rev 69799) +++ Zope/branches/2.9/lib/python/Products/MailHost/tests/testMailHost.py 2006-08-27 16:01:41 UTC (rev 69800) @@ -17,15 +17,26 @@ import unittest +from Products.MailHost.MailHost import MailHost from Products.MailHost.MailHost import MailHostError, _mungeHeaders +class DummyMailHost(MailHost): + meta_type = 'Dummy Mail Host' + def __init__(self, id): + self.id = id + self.sent = '' + def _send(self, mfrom, mto, messageText): + self.sent = messageText + + class TestMailHost(unittest.TestCase): def _getTargetClass(self): - from Products.MailHost.MailHost import MailHost + return DummyMailHost - return MailHost + def _makeOne(self, *args, **kw): + return self._getTargetClass()(*args, **kw) def test_z3interfaces(self): from Products.MailHost.interfaces import IMailHost @@ -113,7 +124,74 @@ '"Foo Bar" <[EMAIL PROTECTED]>']) self.failUnless(resfrom == '[EMAIL PROTECTED]' ) + def testSendMessageOnly(self): + msg = """\ +To: "Name, Nick" <[EMAIL PROTECTED]>, "Foo Bar" <[EMAIL PROTECTED]> +From: [EMAIL PROTECTED] +Subject: This is the subject +Date: Sun, 27 Aug 2006 17:00:00 +0200 +This is the message body.""" + + mailhost = self._makeOne('MailHost') + mailhost.send(msg) + self.assertEqual(mailhost.sent, msg) + + def testSendWithArguments(self): + inmsg = """\ +Date: Sun, 27 Aug 2006 17:00:00 +0200 + +This is the message body.""" + + outmsg = """\ +Date: Sun, 27 Aug 2006 17:00:00 +0200 +Subject: This is the subject +To: "Name, Nick" <[EMAIL PROTECTED]>,"Foo Bar" <[EMAIL PROTECTED]> +From: [EMAIL PROTECTED] + +This is the message body.""" + + mailhost = self._makeOne('MailHost') + mailhost.send(messageText=inmsg, + mto='"Name, Nick" <[EMAIL PROTECTED]>, "Foo Bar" <[EMAIL PROTECTED]>', + mfrom='[EMAIL PROTECTED]', subject='This is the subject') + self.assertEqual(mailhost.sent, outmsg) + + def testSendWithMtoList(self): + inmsg = """\ +Date: Sun, 27 Aug 2006 17:00:00 +0200 + +This is the message body.""" + + outmsg = """\ +Date: Sun, 27 Aug 2006 17:00:00 +0200 +Subject: This is the subject +To: "Name, Nick" <[EMAIL PROTECTED]>,"Foo Bar" <[EMAIL PROTECTED]> +From: [EMAIL PROTECTED] + +This is the message body.""" + + mailhost = self._makeOne('MailHost') + mailhost.send(messageText=inmsg, + mto=['"Name, Nick" <[EMAIL PROTECTED]>', '"Foo Bar" <[EMAIL PROTECTED]>'], + mfrom='[EMAIL PROTECTED]', subject='This is the subject') + self.assertEqual(mailhost.sent, outmsg) + + def testSimpleSend(self): + outmsg = """\ +From: [EMAIL PROTECTED] +To: "Name, Nick" <[EMAIL PROTECTED]>, "Foo Bar" <[EMAIL PROTECTED]> +Subject: This is the subject + +This is the message body.""" + + mailhost = self._makeOne('MailHost') + mailhost.simple_send(mto='"Name, Nick" <[EMAIL PROTECTED]>, "Foo Bar" <[EMAIL PROTECTED]>', + mfrom='[EMAIL PROTECTED]', subject='This is the subject', + body='This is the message body.') + self.assertEqual(mailhost.sent, outmsg) + + def test_suite(): suite = unittest.TestSuite() suite.addTest( unittest.makeSuite( TestMailHost ) ) _______________________________________________ Zope-Checkins maillist - Zope-Checkins@zope.org http://mail.zope.org/mailman/listinfo/zope-checkins