diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/mailman/app/lifecycle.py | 16 | ||||
| -rw-r--r-- | src/mailman/app/tests/test_lifecycle.py | 23 | ||||
| -rw-r--r-- | src/mailman/config/schema.cfg | 5 | ||||
| -rw-r--r-- | src/mailman/docs/NEWS.rst | 2 |
4 files changed, 45 insertions, 1 deletions
diff --git a/src/mailman/app/lifecycle.py b/src/mailman/app/lifecycle.py index cfa01531b..6970de187 100644 --- a/src/mailman/app/lifecycle.py +++ b/src/mailman/app/lifecycle.py @@ -38,7 +38,7 @@ from zope.component import getUtility log = logging.getLogger('mailman.error') # These are the only characters allowed in list names. -_listname_chars = re.compile('[-0-9a-z_.]', re.IGNORECASE) +_listname_chars = re.compile('[-_.+=!$*{}~0-9a-z]', re.IGNORECASE) class InvalidListNameError(InvalidEmailAddressError): @@ -76,8 +76,22 @@ def create_list(fqdn_listname, owners=None, style_name=None): listname, domain = fqdn_listname.split('@', 1) # We need to be fussier than just validating the posting address. Various # legal local-part characters will cause problems in list names. + # First we check our maximally allowed set. if len(_listname_chars.sub('', listname)) > 0: raise InvalidListNameError(listname) + # Then if another set is configured, check that. + if config.mailman.listname_chars: + try: + cre = re.compile(config.mailman.listname_chars, re.IGNORECASE) + except re.error as error: + log.error( + 'Bad config.mailman.listname_chars setting: %s: %s', + config.mailman.listname_chars, + getattr(error, 'msg', str(error)) + ) + else: + if len(cre.sub('', listname)) > 0: + raise InvalidListNameError(listname) if domain not in getUtility(IDomainManager): raise BadDomainSpecificationError(domain) mlist = getUtility(IListManager).create(fqdn_listname) diff --git a/src/mailman/app/tests/test_lifecycle.py b/src/mailman/app/tests/test_lifecycle.py index db36d0b64..ec7d2b771 100644 --- a/src/mailman/app/tests/test_lifecycle.py +++ b/src/mailman/app/tests/test_lifecycle.py @@ -26,6 +26,7 @@ from mailman.app.lifecycle import ( from mailman.interfaces.address import InvalidEmailAddressError from mailman.interfaces.domain import BadDomainSpecificationError from mailman.interfaces.listmanager import IListManager +from mailman.testing.helpers import LogFileMark, configuration from mailman.testing.layers import ConfigLayer from zope.component import getUtility @@ -46,6 +47,28 @@ class TestLifecycle(unittest.TestCase): self.assertRaises(InvalidListNameError, create_list, 'my/list@example.com') + @configuration('mailman', listname_chars='[a-z0-9-+\]') + def test_bad_config_listname_chars(self): + mark = LogFileMark('mailman.error') + # This list create should succeed but log an error + mlist = create_list('test@example.com') + # Check the error log. + self.assertEqual( + mark.readline()[-83:-1], + 'Bad config.mailman.listname_chars setting: ' + '[a-z0-9-+\]: ' + 'unterminated character set' + ) + # Remove the list. + remove_list(mlist) + + @configuration('mailman', listname_chars='[a-z]') + def test_listname_with_minimal_listname_chars(self): + # This only allows letters in the listname. A listname with digits + # Raises an exception. + self.assertRaises(InvalidListNameError, + create_list, 'list1@example.com') + def test_unregistered_domain(self): # Creating a list with an unregistered domain raises an exception. self.assertRaises(BadDomainSpecificationError, diff --git a/src/mailman/config/schema.cfg b/src/mailman/config/schema.cfg index 6b6362ab4..9386caed1 100644 --- a/src/mailman/config/schema.cfg +++ b/src/mailman/config/schema.cfg @@ -75,6 +75,11 @@ filtered_messages_are_preservable: no # The command should print the converted text to stdout. html_to_plain_text_command: /usr/bin/lynx -dump $filename +# Specify what characters are allowed in list names. Characters outside of +# the class [-_.+=!$*{}~0-9a-z] matched case insensitively are never allowed, +# but this specifies a subset as the only allowable characters. +listname_chars: [-_.0-9a-z] + [shell] # `mailman shell` (also `withlist`) gives you an interactive prompt that you diff --git a/src/mailman/docs/NEWS.rst b/src/mailman/docs/NEWS.rst index 14d995190..ffd6c16a6 100644 --- a/src/mailman/docs/NEWS.rst +++ b/src/mailman/docs/NEWS.rst @@ -120,6 +120,8 @@ Configuration rules is not yet exposed through the REST API. Given by Aurélien Bompard. * The default languages from Mailman 2.1 have been ported over. Given by Aurélien Bompard. + * There is now a configuration setting to limit the characters that can be + used in list names. Command line ------------ |
