------------------------------------------------------------ revno: 6519 committer: Barry Warsaw <[EMAIL PROTECTED]> branch nick: 3.0 timestamp: Sun 2007-07-01 23:31:21 -0400 message: Convert failing test_message.py to doctests bounces.txt and message.txt, which of course now succeed. Rename Bouncer.py's BounceMessage() method to bounce_message() and remove the 'msgdata' parameter, which wasn't being used. Change the RejectNotice exception class to expose .notice directly, as there's no reason for this to be an accessor or property. Move the coverage.py installation to the install-packages target instead of the install-other target, so that it only gets installed once the pythonlib directory is created. removed: Mailman/testing/test_message.py added: Mailman/docs/bounces.txt Mailman/docs/message.txt modified: Mailman/Bouncer.py Mailman/Errors.py Mailman/Queue/IncomingRunner.py misc/Makefile.in
=== removed file 'Mailman/testing/test_message.py' --- a/Mailman/testing/test_message.py 2007-01-19 04:38:06 +0000 +++ b/Mailman/testing/test_message.py 1970-01-01 00:00:00 +0000 @@ -1,98 +0,0 @@ -# Copyright (C) 2001-2007 by the Free Software Foundation, Inc. -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, -# USA. - -"""Unit tests for the various Message class methods.""" - -import email -import unittest - -from Mailman import Errors -from Mailman import Message -from Mailman import Version -from Mailman.testing.emailbase import EmailBase - - - -class TestSentMessage(EmailBase): - def test_user_notification(self): - eq = self.assertEqual - unless = self.failUnless - msg = Message.UserNotification( - '[EMAIL PROTECTED]', - '[EMAIL PROTECTED]', - 'Your Test List', - 'About your test list') - msg.send(self._mlist) - qmsg = email.message_from_string(self._readmsg()) - eq(qmsg['subject'], 'Your Test List') - eq(qmsg['from'], '[EMAIL PROTECTED]') - eq(qmsg['to'], '[EMAIL PROTECTED]') - # The Message-ID: header has some time-variant information - msgid = qmsg['message-id'] - unless(msgid.startswith('<mailman.')) - unless(msgid.endswith('[EMAIL PROTECTED]>')) - eq(qmsg['sender'], '[EMAIL PROTECTED]') - eq(qmsg['errors-to'], '[EMAIL PROTECTED]') - eq(qmsg['x-beenthere'], '[EMAIL PROTECTED]') - eq(qmsg['x-mailman-version'], Version.VERSION) - eq(qmsg['precedence'], 'bulk') - # UserNotifications have reduced_list_headers so it won't have - # List-Help, List-Subscribe, or List-Unsubscribe. XXX Why would that - # possibly be? - eq(qmsg['list-help'], - '<mailto:[EMAIL PROTECTED]>') - eq(qmsg['list-subscribe'], """\ -<http://www.example.com/mailman/listinfo/[EMAIL PROTECTED]>, -\t<mailto:[EMAIL PROTECTED]>""") - eq(qmsg['list-id'], '<_xtest.example.com>') - eq(qmsg['list-unsubscribe'], """\ -<http://www.example.com/mailman/listinfo/[EMAIL PROTECTED]>, -\t<mailto:[EMAIL PROTECTED]>""") - eq(qmsg.get_payload(), 'About your test list') - - def test_bounce_message(self): - eq = self.assertEqual - unless = self.failUnless - msg = email.message_from_string("""\ -To: [EMAIL PROTECTED] -From: [EMAIL PROTECTED] -Subject: and another thing - -yadda yadda yadda -""", Message.Message) - self._mlist.BounceMessage(msg, {}) - qmsg = email.message_from_string(self._readmsg()) - unless(qmsg.is_multipart()) - eq(len(qmsg.get_payload()), 2) - # The first payload is the details of the bounce action, and the - # second message is the message/rfc822 attachment of the original - # message. - msg1 = qmsg.get_payload(0) - eq(msg1.get_content_type(), 'text/plain') - eq(msg1.get_payload(), '[No bounce details are available]') - msg2 = qmsg.get_payload(1) - eq(msg2.get_content_type(), 'message/rfc822') - unless(msg2.is_multipart()) - msg3 = msg2.get_payload(0) - eq(msg3.get_payload(), 'yadda yadda yadda\n') - - - -def test_suite(): - suite = unittest.TestSuite() - suite.addTest(unittest.makeSuite(TestSentMessage)) - return suite === added file 'Mailman/docs/bounces.txt' --- a/Mailman/docs/bounces.txt 1970-01-01 00:00:00 +0000 +++ b/Mailman/docs/bounces.txt 2007-07-02 03:31:21 +0000 @@ -0,0 +1,112 @@ +Bounces +======= + +An important feature of Mailman is automatic bounce process. + +XXX Many more converted tests go here. + + +Bounces, or message rejection +----------------------------- + +Mailman can also bounce messages back to the original sender. This is +essentially equivalent to rejecting the message with notification. Mailing +lists can bounce a message with an optional error message. + + >>> from Mailman.configuration import config + >>> from Mailman.database import flush + >>> mlist = config.list_manager.create('[EMAIL PROTECTED]') + >>> mlist.preferred_language = u'en' + >>> flush() + +Any message can be bounced. + + >>> from email import message_from_string + >>> from Mailman.Message import Message + >>> msg = message_from_string("""\ + ... To: [EMAIL PROTECTED] + ... From: [EMAIL PROTECTED] + ... Subject: Something important + ... + ... I sometimes say something important. + ... """, Message) + +Bounce a message by passing in the original message, and an optional error +message. The bounced message ends up in the virgin queue, awaiting sending +to the original messageauthor. + + >>> from Mailman.Queue.Switchboard import Switchboard + >>> switchboard = Switchboard(config.VIRGINQUEUE_DIR) + >>> mlist.bounce_message(msg) + >>> len(switchboard.files) + 1 + >>> filebase = switchboard.files[0] + >>> qmsg, qmsgdata = switchboard.dequeue(filebase) + >>> switchboard.finish(filebase) + >>> print qmsg.as_string() + Subject: Something important + From: [EMAIL PROTECTED] + To: [EMAIL PROTECTED] + MIME-Version: 1.0 + Content-Type: multipart/mixed; boundary="..." + Message-ID: ... + Date: ... + Precedence: bulk + <BLANKLINE> + --... + Content-Type: text/plain; charset="us-ascii" + MIME-Version: 1.0 + Content-Transfer-Encoding: 7bit + <BLANKLINE> + [No bounce details are available] + --... + Content-Type: message/rfc822 + MIME-Version: 1.0 + <BLANKLINE> + To: [EMAIL PROTECTED] + From: [EMAIL PROTECTED] + Subject: Something important + <BLANKLINE> + I sometimes say something important. + <BLANKLINE> + --...-- + +An error message can be given when the message is bounced, and this will be +included in the payload of the text/plain part. The error message must be +passed in as an instance of a RejectMessage exception. + + >>> from Mailman.Errors import RejectMessage + >>> error = RejectMessage("This wasn't very important after all.") + >>> mlist.bounce_message(msg, error) + >>> len(switchboard.files) + 1 + >>> filebase = switchboard.files[0] + >>> qmsg, qmsgdata = switchboard.dequeue(filebase) + >>> switchboard.finish(filebase) + >>> print qmsg.as_string() + Subject: Something important + From: [EMAIL PROTECTED] + To: [EMAIL PROTECTED] + MIME-Version: 1.0 + Content-Type: multipart/mixed; boundary="..." + Message-ID: ... + Date: ... + Precedence: bulk + <BLANKLINE> + --... + Content-Type: text/plain; charset="us-ascii" + MIME-Version: 1.0 + Content-Transfer-Encoding: 7bit + <BLANKLINE> + This wasn't very important after all. + --... + Content-Type: message/rfc822 + MIME-Version: 1.0 + <BLANKLINE> + To: [EMAIL PROTECTED] + From: [EMAIL PROTECTED] + Subject: Something important + <BLANKLINE> + I sometimes say something important. + <BLANKLINE> + --...-- === added file 'Mailman/docs/message.txt' --- a/Mailman/docs/message.txt 1970-01-01 00:00:00 +0000 +++ b/Mailman/docs/message.txt 2007-07-02 03:31:21 +0000 @@ -0,0 +1,52 @@ +Messages +======== + +Mailman has its own Message classes, derived from the standard +email.message.Message class, but providing additional useful methods. + + +User notifications +------------------ + +When Mailman needs to send a message to a user, it creates a UserNotification +instance, and then calls the .send() method on this object. This method +requires a mailing list instance. + + >>> from Mailman.configuration import config + >>> from Mailman.database import flush + >>> mlist = config.list_manager.create('[EMAIL PROTECTED]') + >>> mlist.preferred_language = u'en' + >>> flush() + +The UserNotification constructor takes the recipient address, the sender +address, an optional subject, optional body text, and optional language. + + >>> from Mailman.Message import UserNotification + >>> msg = UserNotification( + ... '[EMAIL PROTECTED]', + ... '[EMAIL PROTECTED]', + ... 'Something you need to know', + ... 'I needed to tell you this.') + >>> msg.send(mlist) + +The message will end up in the virgin queue. + + >>> from Mailman.Queue.Switchboard import Switchboard + >>> switchboard = Switchboard(config.VIRGINQUEUE_DIR) + >>> len(switchboard.files) + 1 + >>> filebase = switchboard.files[0] + >>> qmsg, qmsgdata = switchboard.dequeue(filebase) + >>> switchboard.finish(filebase) + >>> print qmsg.as_string() + MIME-Version: 1.0 + Content-Type: text/plain; charset="us-ascii" + Content-Transfer-Encoding: 7bit + Subject: Something you need to know + From: [EMAIL PROTECTED] + To: [EMAIL PROTECTED] + Message-ID: ... + Date: ... + Precedence: bulk + <BLANKLINE> + I needed to tell you this. === modified file 'Mailman/Bouncer.py' --- a/Mailman/Bouncer.py 2007-01-19 04:38:06 +0000 +++ b/Mailman/Bouncer.py 2007-07-02 03:31:21 +0000 @@ -274,7 +274,7 @@ info.noticesleft -= 1 info.lastnotice = time.localtime()[:3] - def BounceMessage(self, msg, msgdata, e=None): + def bounce_message(self, msg, e=None): # Bounce a message back to the sender, with an error message if # provided in the exception argument. sender = msg.get_sender() @@ -284,10 +284,10 @@ if e is None: notice = _('[No bounce details are available]') else: - notice = _(e.notice()) + notice = _(e.notice) # Currently we always craft bounces as MIME messages. bmsg = Message.UserNotification(msg.get_sender(), - self.GetOwnerEmail(), + self.owner_address, subject, lang=self.preferred_language) # BAW: Be sure you set the type before trying to attach, or you'll get === modified file 'Mailman/Errors.py' --- a/Mailman/Errors.py 2007-05-28 20:21:41 +0000 +++ b/Mailman/Errors.py 2007-07-02 03:31:21 +0000 @@ -162,10 +162,8 @@ notice += '\n' else: notice += '\n\n' - self.__notice = notice + self.notice = notice - def notice(self): - return self.__notice # Additional exceptions === modified file 'Mailman/Queue/IncomingRunner.py' --- a/Mailman/Queue/IncomingRunner.py 2007-01-19 04:38:06 +0000 +++ b/Mailman/Queue/IncomingRunner.py 2007-07-02 03:31:21 +0000 @@ -172,7 +172,7 @@ # longer needs to be queued. return 0 except Errors.RejectMessage, e: - mlist.BounceMessage(msg, msgdata, e) + mlist.bounce_message(msg, e) return 0 except: # Push this pipeline module back on the stack, then re-raise === modified file 'misc/Makefile.in' --- a/misc/Makefile.in 2007-07-02 01:49:34 +0000 +++ b/misc/Makefile.in 2007-07-02 03:31:21 +0000 @@ -92,7 +92,6 @@ dir=$(DESTDIR)$(prefix)/$$d; \ $(INSTALL) -m $(FILEMODE) paths.py $$dir; \ done - $(INSTALL) -m $(FILEMODE) coverage.py $(PYTHONPATHDIR) $(INSTALL) -m $(EXEMODE) mailman $(DESTDIR)$(SCRIPTSDIR) $(INSTALL) -m $(FILEMODE) mailman.cfg.sample $(DESTDIR)$(ETCDIR) @@ -108,6 +107,7 @@ do \ (umask 02 ; PYTHONPATH=$(PYTHONPATHDIR) $(EZCMD) $$p); \ done + $(INSTALL) -m $(FILEMODE) coverage.py $(PYTHONPATHDIR) finish: -- (no title) https://code.launchpad.net/~mailman-coders/mailman/3.0 You are receiving this branch notification because you are subscribed to it. To unsubscribe from this branch go to https://code.launchpad.net/~mailman-coders/mailman/3.0/+subscription/mailman-checkins. _______________________________________________ Mailman-checkins mailing list Mailman-checkins@python.org Unsubscribe: http://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org