Commit d587406e authored by Stefan H. Holek's avatar Stefan H. Holek

Fixed MailHost documentation; simple_send does not

process or validate its arguments in any way.
Resolves http://www.zope.org/Collectors/Zope/2152
parent 9657f85a
......@@ -8,6 +8,9 @@ Zope Changes
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.
......
......@@ -10,7 +10,7 @@ MailHost: Sends mail through an SMTP server.
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 @@ MailHost: Sends mail through an SMTP server.
'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.
......
......@@ -37,7 +37,7 @@ class MailHost:
"""
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 @@ class MailHost:
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.
......
......@@ -17,15 +17,26 @@ $Id$
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,6 +124,73 @@ This is the message body."""
'"Foo Bar" <foo@domain.com>'])
self.failUnless(resfrom == 'sender@domain.com' )
def testSendMessageOnly(self):
msg = """\
To: "Name, Nick" <recipient@domain.com>, "Foo Bar" <foo@domain.com>
From: sender@domain.com
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" <recipient@domain.com>,"Foo Bar" <foo@domain.com>
From: sender@domain.com
This is the message body."""
mailhost = self._makeOne('MailHost')
mailhost.send(messageText=inmsg,
mto='"Name, Nick" <recipient@domain.com>, "Foo Bar" <foo@domain.com>',
mfrom='sender@domain.com', 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" <recipient@domain.com>,"Foo Bar" <foo@domain.com>
From: sender@domain.com
This is the message body."""
mailhost = self._makeOne('MailHost')
mailhost.send(messageText=inmsg,
mto=['"Name, Nick" <recipient@domain.com>', '"Foo Bar" <foo@domain.com>'],
mfrom='sender@domain.com', subject='This is the subject')
self.assertEqual(mailhost.sent, outmsg)
def testSimpleSend(self):
outmsg = """\
From: sender@domain.com
To: "Name, Nick" <recipient@domain.com>, "Foo Bar" <foo@domain.com>
Subject: This is the subject
This is the message body."""
mailhost = self._makeOne('MailHost')
mailhost.simple_send(mto='"Name, Nick" <recipient@domain.com>, "Foo Bar" <foo@domain.com>',
mfrom='sender@domain.com', subject='This is the subject',
body='This is the message body.')
self.assertEqual(mailhost.sent, outmsg)
def test_suite():
suite = unittest.TestSuite()
......
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