summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBarry Warsaw2016-08-23 22:06:55 -0400
committerBarry Warsaw2016-08-23 22:06:55 -0400
commitdf929b21f9afc917cb515aca613fc925f6c9d1d0 (patch)
tree79240a6f6c097264f08eb7349089c05967683ecf
parent3667b6dbc4110b12dd625e458dcdc8b3d9da7817 (diff)
downloadmailman-df929b21f9afc917cb515aca613fc925f6c9d1d0.tar.gz
mailman-df929b21f9afc917cb515aca613fc925f6c9d1d0.tar.zst
mailman-df929b21f9afc917cb515aca613fc925f6c9d1d0.zip
-rw-r--r--src/mailman/docs/NEWS.rst2
-rw-r--r--src/mailman/handlers/cook_headers.py3
-rw-r--r--src/mailman/handlers/tests/test_cook_headers.py33
-rw-r--r--src/mailman/rest/listconf.py3
-rw-r--r--src/mailman/rest/tests/test_listconf.py2
5 files changed, 35 insertions, 8 deletions
diff --git a/src/mailman/docs/NEWS.rst b/src/mailman/docs/NEWS.rst
index f2c63a8f3..5408c29b4 100644
--- a/src/mailman/docs/NEWS.rst
+++ b/src/mailman/docs/NEWS.rst
@@ -86,6 +86,8 @@ Bugs
* Nonmember subscriptions are removed when one of the addresses controlled by
a user is subscribed as a member. Given by Aditya Divekar. (Closes #237)
* Email address validation is now more compliant with RFC 5321. (Closes #266)
+ * A mailing list's ``description`` must not contain newlines. Given by
+ Aurélien Bompard. (Closes: #273)
Configuration
-------------
diff --git a/src/mailman/handlers/cook_headers.py b/src/mailman/handlers/cook_headers.py
index f43e3ad5a..78109bb77 100644
--- a/src/mailman/handlers/cook_headers.py
+++ b/src/mailman/handlers/cook_headers.py
@@ -29,6 +29,7 @@ from mailman.interfaces.mailinglist import Personalization, ReplyToMunging
from mailman.version import VERSION
from zope.interface import implementer
+
log = logging.getLogger('mailman.error')
COMMASPACE = ', '
@@ -58,7 +59,7 @@ def uheader(mlist, s, header_name=None, continuation_ws='\t', maxlinelen=None):
if '\n' in s:
s = '{} [...]'.format(s.split('\n')[0])
log.warning('Header {} contains a newline, truncating it.'.format(
- header_name, s))
+ header_name, s))
return Header(s, charset, maxlinelen, header_name, continuation_ws)
diff --git a/src/mailman/handlers/tests/test_cook_headers.py b/src/mailman/handlers/tests/test_cook_headers.py
index f9def6ca8..8ab301f96 100644
--- a/src/mailman/handlers/tests/test_cook_headers.py
+++ b/src/mailman/handlers/tests/test_cook_headers.py
@@ -21,9 +21,11 @@ import unittest
from mailman.app.lifecycle import create_list
from mailman.handlers import cook_headers
+from mailman.interfaces.mailinglist import ReplyToMunging
from mailman.interfaces.member import DeliveryMode
from mailman.testing.helpers import (
- get_queue_messages, LogFileMark, make_digest_messages, subscribe)
+ LogFileMark, get_queue_messages, make_digest_messages,
+ specialized_message_from_string as mfs, subscribe)
from mailman.testing.layers import ConfigLayer
@@ -33,7 +35,7 @@ class TestCookHeaders(unittest.TestCase):
layer = ConfigLayer
def setUp(self):
- self._mlist = create_list('test@example.com')
+ self._mlist = create_list('ant@example.com')
self._mlist.send_welcome_message = False
def test_process_digest(self):
@@ -56,8 +58,31 @@ class TestCookHeaders(unittest.TestCase):
mark = LogFileMark('mailman.error')
header = cook_headers.uheader(
self._mlist, 'A multiline\ndescription', 'X-Header')
- self.assertEqual(
- header.encode(), 'A multiline [...]')
+ self.assertEqual(header.encode(), 'A multiline [...]')
log_messages = mark.read()
self.assertIn(
'Header X-Header contains a newline, truncating it', log_messages)
+
+ def test_truncate_description(self):
+ # Existing multiline descriptions get truncated with ellipses.
+ self._mlist.description = 'A multiline\ndescription\nalready\nexists'
+ self._mlist.reply_goes_to_list = ReplyToMunging.point_to_list
+ msg = mfs("""\
+From: anne@example.com
+To: ant@example.com
+Subject: A subject
+X-Mailman-Version: X.Y
+
+More things to say.
+""")
+ cook_headers.process(self._mlist, msg, {})
+ self.assertMultiLineEqual(msg.as_string(), """\
+From: anne@example.com
+To: ant@example.com
+Subject: A subject
+X-Mailman-Version: X.Y
+Precedence: list
+Reply-To: "A multiline [...]" <ant@example.com>
+
+More things to say.
+""")
diff --git a/src/mailman/rest/listconf.py b/src/mailman/rest/listconf.py
index c49228c39..ad8aefcbb 100644
--- a/src/mailman/rest/listconf.py
+++ b/src/mailman/rest/listconf.py
@@ -104,8 +104,7 @@ def password_bytes_validator(value):
def no_newlines_validator(value):
value = str(value)
if '\n' in value:
- raise ValueError(
- 'This value must be on a single line: {}'.format(value))
+ raise ValueError('This value must be a single line: {}'.format(value))
return value
diff --git a/src/mailman/rest/tests/test_listconf.py b/src/mailman/rest/tests/test_listconf.py
index 54918282f..b454337e4 100644
--- a/src/mailman/rest/tests/test_listconf.py
+++ b/src/mailman/rest/tests/test_listconf.py
@@ -439,7 +439,7 @@ class TestConfiguration(unittest.TestCase):
self.assertTrue(self._mlist.advertised)
def test_patch_bad_description_value(self):
- # GL issue #273
+ # Do not accept multiline descriptions. GL#273
with self.assertRaises(HTTPError) as cm:
call_api(
'http://localhost:9001/3.0/lists/ant.example.com/config'