diff options
| -rw-r--r-- | src/mailman/chains/hold.py | 18 | ||||
| -rw-r--r-- | src/mailman/chains/tests/__init__.py | 0 | ||||
| -rw-r--r-- | src/mailman/chains/tests/test_hold.py | 101 | ||||
| -rw-r--r-- | src/mailman/docs/NEWS.rst | 2 | ||||
| -rw-r--r-- | src/mailman/templates/en/nomoretoday.txt | 15 |
5 files changed, 120 insertions, 16 deletions
diff --git a/src/mailman/chains/hold.py b/src/mailman/chains/hold.py index 7b78f118e..dd7276aed 100644 --- a/src/mailman/chains/hold.py +++ b/src/mailman/chains/hold.py @@ -64,22 +64,22 @@ class HoldNotification(ChainNotification): -def autorespond_to_sender(mlist, sender, lang=None): +def autorespond_to_sender(mlist, sender, language=None): """Should Mailman automatically respond to this sender? :param mlist: The mailing list. :type mlist: `IMailingList`. :param sender: The sender's email address. :type sender: string - :param lang: Optional language. - :type lang: `ILanguage` or None + :param language: Optional language. + :type language: `ILanguage` or None :return: True if an automatic response should be sent, otherwise False. If an automatic response is not sent, a message is sent indicating that, er no more will be sent today. :rtype: bool """ - if lang is None: - lang = mlist.preferred_language + if language is None: + language = mlist.preferred_language max_autoresponses_per_day = int(config.mta.max_autoresponses_per_day) if max_autoresponses_per_day == 0: # Unlimited. @@ -104,17 +104,17 @@ def autorespond_to_sender(mlist, sender, lang=None): response_set.response_sent(address, Response.hold) # Send this notification message instead. text = make('nomoretoday.txt', - language=lang, + language=language.code, sender=sender, listname=mlist.fqdn_listname, - num=todays_count, + count=todays_count, owneremail=mlist.owner_address, ) - with _.using(lang.code): + with _.using(language.code): msg = UserNotification( sender, mlist.owner_address, _('Last autoresponse notification for today'), - text, lang=lang) + text, lang=language) msg.send(mlist) return False else: diff --git a/src/mailman/chains/tests/__init__.py b/src/mailman/chains/tests/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/src/mailman/chains/tests/__init__.py diff --git a/src/mailman/chains/tests/test_hold.py b/src/mailman/chains/tests/test_hold.py new file mode 100644 index 000000000..3e9f66084 --- /dev/null +++ b/src/mailman/chains/tests/test_hold.py @@ -0,0 +1,101 @@ +# Copyright (C) 2011 by the Free Software Foundation, Inc. +# +# This file is part of GNU Mailman. +# +# GNU Mailman 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 3 of the License, or (at your option) +# any later version. +# +# GNU Mailman 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 +# GNU Mailman. If not, see <http://www.gnu.org/licenses/>. + +"""Additional tests for the hold chain.""" + +from __future__ import absolute_import, unicode_literals + +__metaclass__ = type +__all__ = [ + 'test_suite', + ] + + +import unittest + +from zope.component import getUtility + +from mailman.app.lifecycle import create_list +from mailman.chains.hold import autorespond_to_sender +from mailman.config import config +from mailman.interfaces.autorespond import IAutoResponseSet, Response +from mailman.interfaces.usermanager import IUserManager +from mailman.testing.helpers import get_queue_messages +from mailman.testing.layers import ConfigLayer + + + +class TestAutorespond(unittest.TestCase): + """Test autorespond_to_sender()""" + + layer = ConfigLayer + + def setUp(self): + self._mlist = create_list('test@example.com') + + def test_max_autoresponses_per_day(self): + # The last one we sent was the last one we should send today. Instead + # of sending an automatic response, send them the "no more today" + # message. + config.push('max-1', """ + [mta] + max_autoresponses_per_day: 1 + """) + # Simulate a response having been sent to an address already. + anne = getUtility(IUserManager).create_address('anne@example.com') + response_set = IAutoResponseSet(self._mlist) + response_set.response_sent(anne, Response.hold) + # Trigger the sending of a "last response for today" using the default + # language (i.e. the mailing list's preferred language). + autorespond_to_sender(self._mlist, 'anne@example.com') + # So first, there should be one more hold response sent to the user. + self.assertEqual(response_set.todays_count(anne, Response.hold), 2) + # And the virgin queue should have the message in it. + messages = get_queue_messages('virgin') + self.assertEqual(len(messages), 1) + # Remove the variable headers. + message = messages[0].msg + self.assertTrue('message-id' in message) + del message['message-id'] + self.assertTrue('date' in message) + del message['date'] + self.assertEqual(messages[0].msg.as_string(), """\ +MIME-Version: 1.0 +Content-Type: text/plain; charset="us-ascii" +Content-Transfer-Encoding: 7bit +Subject: Last autoresponse notification for today +From: test-owner@example.com +To: anne@example.com +Precedence: bulk + +We have received a message from your address <anne@example.com> +requesting an automated response from the test@example.com mailing +list. + +The number we have seen today: 1. In order to avoid problems such as +mail loops between email robots, we will not be sending you any +further responses today. Please try again tomorrow. + +If you believe this message is in error, or if you have any questions, +please contact the list owner at test-owner@example.com.""") + + + +def test_suite(): + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(TestAutorespond)) + return suite diff --git a/src/mailman/docs/NEWS.rst b/src/mailman/docs/NEWS.rst index a0665171d..360a340dc 100644 --- a/src/mailman/docs/NEWS.rst +++ b/src/mailman/docs/NEWS.rst @@ -68,6 +68,8 @@ Testing Other bugs ---------- * Moderating a message with Action.accept now sends the message. (LP: #827697) + * Fix AttributeError triggered by i18n call in autorespond_to_sender() + (LP: #827060) 3.0 alpha 7 -- "Mission" diff --git a/src/mailman/templates/en/nomoretoday.txt b/src/mailman/templates/en/nomoretoday.txt index 1019dce34..51e571cf2 100644 --- a/src/mailman/templates/en/nomoretoday.txt +++ b/src/mailman/templates/en/nomoretoday.txt @@ -1,8 +1,9 @@ -We have received a message from your address `%(sender)s' requesting -an automated response from the %(listname)s mailing list. We have -seen %(num)s such messages from you today. In order to avoid problems -such as mail loops between email robots, we will not be sending you -any further email responses today. Please try again tomorrow. +We have received a message from your address <$sender> requesting an automated +response from the $listname mailing list. -If you believe this message is in error, or if you have any questions, -please contact the list owner at %(owneremail)s. +The number we have seen today: $count. In order to avoid problems such as +mail loops between email robots, we will not be sending you any further +responses today. Please try again tomorrow. + +If you believe this message is in error, or if you have any questions, please +contact the list owner at $owneremail. |
