summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mailman/database/tests/test_factory.py25
-rw-r--r--src/mailman/docs/NEWS.rst5
-rw-r--r--src/mailman/handlers/owner_recipients.py7
-rw-r--r--src/mailman/handlers/tests/test_recipients.py24
-rw-r--r--src/mailman/runners/digest.py13
-rw-r--r--src/mailman/runners/tests/test_digest.py58
-rw-r--r--src/mailman/testing/helpers.py5
7 files changed, 93 insertions, 44 deletions
diff --git a/src/mailman/database/tests/test_factory.py b/src/mailman/database/tests/test_factory.py
index d7c4d8503..29cca41ba 100644
--- a/src/mailman/database/tests/test_factory.py
+++ b/src/mailman/database/tests/test_factory.py
@@ -47,13 +47,13 @@ class TestSchemaManager(unittest.TestCase):
layer = ConfigLayer
def setUp(self):
- # Drop the existing database.
+ # Drop the existing model tables.
Model.metadata.drop_all(config.db.engine)
+ # Drop leftover tables (e.g. Alembic & Storm schema versions).
md = MetaData()
md.reflect(bind=config.db.engine)
- for tablename in ('alembic_version', 'version'):
- if tablename in md.tables:
- md.tables[tablename].drop(config.db.engine)
+ for table in md.sorted_tables:
+ table.drop(config.db.engine)
self.schema_mgr = SchemaManager(config.db)
def tearDown(self):
@@ -114,15 +114,24 @@ class TestSchemaManager(unittest.TestCase):
self.assertFalse(alembic_command.stamp.called)
self.assertFalse(alembic_command.upgrade.called)
- @patch('alembic.command')
- def test_initial(self, alembic_command):
+ @patch('alembic.command.upgrade')
+ def test_initial(self, alembic_command_upgrade):
# No existing database.
self.assertFalse(self._table_exists('mailinglist'))
self.assertFalse(self._table_exists('alembic_version'))
- self.schema_mgr.setup_database()
- self.assertFalse(alembic_command.upgrade.called)
+ # For the initial setup of the database, the upgrade command will not
+ # be called. The tables will be created and then the schema stamped
+ # at Alembic's latest revision.
+ head_rev = self.schema_mgr.setup_database()
+ self.assertFalse(alembic_command_upgrade.called)
self.assertTrue(self._table_exists('mailinglist'))
self.assertTrue(self._table_exists('alembic_version'))
+ # The current Alembic revision is the same as the initial revision.
+ md = MetaData()
+ md.reflect(bind=config.db.engine)
+ current_rev = config.db.engine.execute(
+ md.tables['alembic_version'].select()).scalar()
+ self.assertEqual(current_rev, head_rev)
@patch('alembic.command.stamp')
def test_storm(self, alembic_command_stamp):
diff --git a/src/mailman/docs/NEWS.rst b/src/mailman/docs/NEWS.rst
index 6223dc9d0..5afc6a1e0 100644
--- a/src/mailman/docs/NEWS.rst
+++ b/src/mailman/docs/NEWS.rst
@@ -12,6 +12,11 @@ Here is a history of user visible changes to Mailman.
====================================
(2014-XX-XX)
+Bugs
+----
+ * Fixed Unicode errors in the digest runner and when sending messages to the
+ site owner as a fallback. Given by Aurélien Bompard. (LP: #1130957).
+
Commands
--------
* The `mailman conf` command no longer takes the `-t/--sort` option; the
diff --git a/src/mailman/handlers/owner_recipients.py b/src/mailman/handlers/owner_recipients.py
index 1bd907bf7..5a1d0bd2e 100644
--- a/src/mailman/handlers/owner_recipients.py
+++ b/src/mailman/handlers/owner_recipients.py
@@ -55,7 +55,12 @@ 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((unicode(config.mailman.site_owner),))
+ # Ensure that the site owner address is a unicode.
+ # See LP: #1130957
+ site_owner = config.mailman.site_owner
+ if isinstance(site_owner, bytes):
+ site_owner = site_owner.decode('utf-8')
+ msgdata['recipients'] = set((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 82f3714fa..afe533a7e 100644
--- a/src/mailman/handlers/tests/test_recipients.py
+++ b/src/mailman/handlers/tests/test_recipients.py
@@ -200,18 +200,22 @@ To: test-owner@example.com
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.
+ # Since the config file is read as bytes, the site_owner is also a
+ # bytes 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")
+ # In order to properly mimic the testing environment, use
+ # config.push()/config.pop() directly instead of using the
+ # configuration() context manager.
+ config.push('test_site_admin_unicode', b"""\
+[mailman]
+site_owner: siteadmin@example.com
+""")
+ try:
+ self._process(self._mlist, self._msg, msgdata)
+ finally:
+ config.pop('test_site_admin_unicode')
self.assertEqual(len(msgdata['recipients']), 1)
- self.assertTrue(isinstance(list(msgdata['recipients'])[0], unicode))
+ self.assertIsInstance(list(msgdata['recipients'])[0], unicode)
diff --git a/src/mailman/runners/digest.py b/src/mailman/runners/digest.py
index 2e349c35e..98fe82f39 100644
--- a/src/mailman/runners/digest.py
+++ b/src/mailman/runners/digest.py
@@ -148,7 +148,7 @@ class Digester:
for value in keepers[header]:
msg[header] = value
# Add some useful extra stuff.
- msg['Message'] = unicode(count)
+ msg['Message'] = count.decode('utf-8')
@@ -260,13 +260,18 @@ 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(b'\n\n', 1)[1])
+ if not payload:
+ # Split using bytes so as not to turn the payload into unicode
+ # strings due to unicode_literals above.
+ payload = msg.as_string().split(b'\n\n', 1)[1]
try:
+ # Do the decoding inside the try/except so that if the charset
+ # conversion fails, we'll just drop back to ascii.
charset = msg.get_content_charset('us-ascii')
- payload = unicode(payload, charset, 'replace')
+ payload = payload.decode(charset, 'replace')
except (LookupError, TypeError):
# Unknown or empty charset.
- payload = unicode(payload, 'us-ascii', 'replace')
+ payload = payload.decode('us-ascii', 'replace')
print(payload, file=self._text)
if not payload.endswith('\n'):
print(file=self._text)
diff --git a/src/mailman/runners/tests/test_digest.py b/src/mailman/runners/tests/test_digest.py
index 17482c344..80cf253bc 100644
--- a/src/mailman/runners/tests/test_digest.py
+++ b/src/mailman/runners/tests/test_digest.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2014 by the Free Software Foundation, Inc.
+# Copyright (C) 2014 by the Free Software Foundation, Inc.
#
# This file is part of GNU Mailman.
#
@@ -24,16 +24,17 @@ __all__ = [
'TestDigest',
]
+
import os
import unittest
-from email.mime.text import MIMEText
+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,
+ LogFileMark, digest_mbox, get_queue_messages, make_testable_runner,
specialized_message_from_string as mfs)
from mailman.testing.layers import ConfigLayer
@@ -47,17 +48,12 @@ class TestDigest(unittest.TestCase):
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
@@ -65,32 +61,52 @@ 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,
+ self._digestq.enqueue(
+ msg,
listname=self._mlist.fqdn_listname,
digest_path=mbox_path,
volume=1, digest_number=1)
self._runner.run()
+ # There are two messages in the virgin queue: the digest as plain-text
+ # and as multipart.
+ messages = get_queue_messages('virgin')
+ self.assertEqual(len(messages), 2)
+ self.assertEqual(
+ sorted(item.msg.get_content_type() for item in messages),
+ ['multipart/mixed', 'text/plain'])
+ for item in messages:
+ self.assertEqual(item.msg['subject'],
+ 'Test Digest, Vol 1, Issue 1')
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"))
+ 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,
+ self._digestq.enqueue(
+ msg,
listname=self._mlist.fqdn_listname,
digest_path=mbox_path,
volume=1, digest_number=1)
+ # Use any error logs as the error message if the test fails.
+ error_log = LogFileMark('mailman.error')
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)
+ # The runner will send the file to the shunt queue on exception.
+ self.assertEqual(len(self._shuntq.files), 0, error_log.read())
+ # There are two messages in the virgin queue: the digest as plain-text
+ # and as multipart.
+ messages = get_queue_messages('virgin')
+ self.assertEqual(len(messages), 2)
+ self.assertEqual(
+ sorted(item.msg.get_content_type() for item in messages),
+ ['multipart/mixed', 'text/plain'])
+ for item in messages:
+ self.assertEqual(item.msg['subject'],
+ 'Test Digest, Vol 1, Issue 1')
diff --git a/src/mailman/testing/helpers.py b/src/mailman/testing/helpers.py
index aab23ab75..b0fe14a0d 100644
--- a/src/mailman/testing/helpers.py
+++ b/src/mailman/testing/helpers.py
@@ -524,3 +524,8 @@ class LogFileMark:
with open(self._filename) as fp:
fp.seek(self._filepos)
return fp.readline()
+
+ def read(self):
+ with open(self._filename) as fp:
+ fp.seek(self._filepos)
+ return fp.read()