diff options
| author | Aurélien Bompard | 2014-11-27 16:56:42 +0100 |
|---|---|---|
| committer | Aurélien Bompard | 2014-11-27 16:56:42 +0100 |
| commit | 43b8f3f8faeccec1726466455f0affa9e98880d5 (patch) | |
| tree | c21eca83073cc3978b598e61f1f84218fe52f023 | |
| parent | 11af7021249c5827c4c2d72a90fb4dd2321395c0 (diff) | |
| download | mailman-43b8f3f8faeccec1726466455f0affa9e98880d5.tar.gz mailman-43b8f3f8faeccec1726466455f0affa9e98880d5.tar.zst mailman-43b8f3f8faeccec1726466455f0affa9e98880d5.zip | |
| -rw-r--r-- | src/mailman/handlers/owner_recipients.py | 2 | ||||
| -rw-r--r-- | src/mailman/handlers/tests/test_recipients.py | 17 | ||||
| -rw-r--r-- | src/mailman/runners/digest.py | 2 | ||||
| -rw-r--r-- | src/mailman/runners/tests/test_digest.py | 96 |
4 files changed, 115 insertions, 2 deletions
diff --git a/src/mailman/handlers/owner_recipients.py b/src/mailman/handlers/owner_recipients.py index de6d575e1..1bd907bf7 100644 --- a/src/mailman/handlers/owner_recipients.py +++ b/src/mailman/handlers/owner_recipients.py @@ -55,7 +55,7 @@ class OwnerRecipients: # To prevent -owner messages from going into a black hole, if there # are no administrators available, the message goes to the site owner. if len(recipients) == 0: - msgdata['recipients'] = set((config.mailman.site_owner,)) + msgdata['recipients'] = set((unicode(config.mailman.site_owner),)) else: msgdata['recipients'] = recipients # Don't decorate these messages with the header/footers. Eventually diff --git a/src/mailman/handlers/tests/test_recipients.py b/src/mailman/handlers/tests/test_recipients.py index 04789c281..82f3714fa 100644 --- a/src/mailman/handlers/tests/test_recipients.py +++ b/src/mailman/handlers/tests/test_recipients.py @@ -198,3 +198,20 @@ To: test-owner@example.com msgdata = {} self._process(self._mlist, self._msg, msgdata) self.assertEqual(msgdata['recipients'], set(('noreply@example.com',))) + + def test_site_admin_unicode(self): + # Since the conf file is read as a bytestring, the site_owner is also a + # bytestring and must be converted to unicode when used as a fallback. + self._cris.unsubscribe() + self._dave.unsubscribe() + self.assertEqual(self._mlist.administrators.member_count, 0) + msgdata = {} + strconf = b""" + [mailman] + site_owner: siteadmin@example.com + """ + config.push("test_site_admin_unicode", strconf) + self._process(self._mlist, self._msg, msgdata) + config.pop("test_site_admin_unicode") + self.assertEqual(len(msgdata['recipients']), 1) + self.assertTrue(isinstance(list(msgdata['recipients'])[0], unicode)) diff --git a/src/mailman/runners/digest.py b/src/mailman/runners/digest.py index f2c888275..2e349c35e 100644 --- a/src/mailman/runners/digest.py +++ b/src/mailman/runners/digest.py @@ -260,7 +260,7 @@ class RFC1153Digester(Digester): # Add the payload. If the decoded payload is empty, this may be a # multipart message. In that case, just stringify it. payload = msg.get_payload(decode=True) - payload = (payload if payload else msg.as_string().split('\n\n', 1)[1]) + payload = (payload if payload else msg.as_string().split(b'\n\n', 1)[1]) try: charset = msg.get_content_charset('us-ascii') payload = unicode(payload, charset, 'replace') diff --git a/src/mailman/runners/tests/test_digest.py b/src/mailman/runners/tests/test_digest.py new file mode 100644 index 000000000..17482c344 --- /dev/null +++ b/src/mailman/runners/tests/test_digest.py @@ -0,0 +1,96 @@ +# Copyright (C) 2012-2014 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/>. + +"""Test the digest runner.""" + +from __future__ import absolute_import, print_function, unicode_literals + +__metaclass__ = type +__all__ = [ + 'TestDigest', + ] + +import os +import unittest +from email.mime.text import MIMEText + +from mailman.app.lifecycle import create_list +from mailman.config import config +from mailman.email.message import Message +from mailman.runners.digest import DigestRunner +from mailman.testing.helpers import ( + digest_mbox, make_testable_runner, reset_the_world, + specialized_message_from_string as mfs) +from mailman.testing.layers import ConfigLayer + + + +class TestDigest(unittest.TestCase): + """Test the digest runner.""" + + layer = ConfigLayer + + def setUp(self): + self._mlist = create_list('test@example.com') + self._mlist.digest_size_threshold = 1 + #self._mlist.volume = 1 + #self._mlist.next_digest_number = 1 + self._digestq = config.switchboards['digest'] + self._shuntq = config.switchboards['shunt'] + self._virginq = config.switchboards['virgin'] + self._runner = make_testable_runner(DigestRunner, 'digest') + self._process = config.handlers['to-digest'].process + + def tearDown(self): + reset_the_world() + + def test_simple_message(self): + msg = mfs("""\ +From: anne@example.org +To: test@example.com + +message triggering a digest +""") + mbox = digest_mbox(self._mlist) + mbox_path = os.path.join(self._mlist.data_path, 'digest.mmdf') + self._process(self._mlist, msg, {}) + self._digestq.enqueue(msg, + listname=self._mlist.fqdn_listname, + digest_path=mbox_path, + volume=1, digest_number=1) + self._runner.run() + + def test_non_ascii_message(self): + msg = Message() + msg["From"] = "anne@example.org" + msg["To"] = "test@example.com" + msg["Content-Type"] = "multipart/mixed" + msg.attach(MIMEText("message with non-ascii chars: \xc3\xa9", + "plain", "utf-8")) + mbox = digest_mbox(self._mlist) + mbox_path = os.path.join(self._mlist.data_path, 'digest.mmdf') + mbox.add(msg.as_string()) + self._digestq.enqueue(msg, + listname=self._mlist.fqdn_listname, + digest_path=mbox_path, + volume=1, digest_number=1) + self._runner.run() + errorlog = open(os.path.join(config.LOG_DIR, "error")).read() + # The runner will send the file to the shunt queue on exception + self.assertEqual(len(self._shuntq.files), 0, errorlog) + # 2 messages in the virgin queue: the digest as plain-text and as multipart + self.assertEqual(len(self._virginq.files), 2, errorlog) |
