Merge lp:~abompard/mailman/bug-1170347 into lp:mailman

Proposed by Aurélien Bompard
Status: Merged
Approved by: Barry Warsaw
Approved revision: 7265
Merged at revision: 7269
Proposed branch: lp:~abompard/mailman/bug-1170347
Merge into: lp:mailman
Diff against target: 80 lines (+64/-1)
2 files modified
src/mailman/handlers/tests/test_to_digest.py (+63/-0)
src/mailman/handlers/to_digest.py (+1/-1)
To merge this branch: bzr merge lp:~abompard/mailman/bug-1170347
Reviewer Review Type Date Requested Status
Barry Warsaw Approve
Review via email: mp+242761@code.launchpad.net

Description of the change

Fix digest handler crash reported in bug #1170347.

To post a comment you must log in.
Revision history for this message
Barry Warsaw (barry) wrote :

LGTM, thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'src/mailman/handlers/tests/test_to_digest.py'
2--- src/mailman/handlers/tests/test_to_digest.py 1970-01-01 00:00:00 +0000
3+++ src/mailman/handlers/tests/test_to_digest.py 2014-11-25 11:23:22 +0000
4@@ -0,0 +1,63 @@
5+# Copyright (C) 2012-2014 by the Free Software Foundation, Inc.
6+#
7+# This file is part of GNU Mailman.
8+#
9+# GNU Mailman is free software: you can redistribute it and/or modify it under
10+# the terms of the GNU General Public License as published by the Free
11+# Software Foundation, either version 3 of the License, or (at your option)
12+# any later version.
13+#
14+# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
15+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17+# more details.
18+#
19+# You should have received a copy of the GNU General Public License along with
20+# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
21+
22+"""Test the to_digest handler."""
23+
24+from __future__ import absolute_import, print_function, unicode_literals
25+
26+__metaclass__ = type
27+__all__ = [
28+ 'TestToDigest',
29+ ]
30+
31+
32+import unittest
33+import os
34+
35+from mailman.app.lifecycle import create_list
36+from mailman.testing.helpers import (
37+ get_queue_messages,
38+ specialized_message_from_string as mfs)
39+from mailman.testing.layers import ConfigLayer
40+
41+from mailman.handlers.to_digest import ToDigest
42+
43+
44+
45
46+class TestToDigest(unittest.TestCase):
47+ """Test the to_digest handler."""
48+
49+ layer = ConfigLayer
50+
51+ def setUp(self):
52+ self._mlist = create_list('test@example.com')
53+ self._msg = mfs("""\
54+From: anne@example.com
55+To: test@example.com
56+Subject: A disposable message
57+Message-ID: <ant>
58+
59+""")
60+ self._handler = ToDigest()
61+
62+ def test_unicode_message(self):
63+ self._msg.set_payload(b"non-ascii chars \xc3\xa9 \xc3\xa8 \xc3\xa7")
64+ self._msg["X-Test"] = "dummy"
65+ self._handler.process(self._mlist, self._msg, {})
66+ # Make sure the digest mbox is not empty
67+ mailbox_path = os.path.join(self._mlist.data_path, 'digest.mmdf')
68+ self.assertNotEqual(os.path.getsize(mailbox_path), 0)
69
70=== modified file 'src/mailman/handlers/to_digest.py'
71--- src/mailman/handlers/to_digest.py 2014-01-01 14:59:42 +0000
72+++ src/mailman/handlers/to_digest.py 2014-11-25 11:23:22 +0000
73@@ -55,7 +55,7 @@
74 mailbox_path = os.path.join(mlist.data_path, 'digest.mmdf')
75 # Lock the mailbox and append the message.
76 with Mailbox(mailbox_path, create=True) as mbox:
77- mbox.add(msg)
78+ mbox.add(msg.as_string())
79 # Calculate the current size of the mailbox file. This will not tell
80 # us exactly how big the resulting MIME and rfc1153 digest will
81 # actually be, but it's the most easily available metric to decide