Abhilash Raj pushed to branch master at GNU Mailman / Mailman Core
Commits: c3912d62 by Mark Sapiro at 2020-04-21T16:18:43-07:00 Ignore CRs when importing header and footers. - - - - - 555964ca by Abhilash Raj at 2020-04-22T00:08:42+00:00 Merge branch 'fix_701' into 'master' Ignore CRs when importing header and footers. Closes #701 See merge request mailman/mailman!628 - - - - - 3 changed files: - src/mailman/docs/NEWS.rst - src/mailman/utilities/importer.py - src/mailman/utilities/tests/test_import.py Changes: ===================================== src/mailman/docs/NEWS.rst ===================================== @@ -13,6 +13,11 @@ Here is a history of user visible changes to Mailman. (XXXX-XX-XX) +Bugs +---- +* When importing 2.1 lists, ignore CR characters added by browsers in headers + and footers. (Closes #701) + 3.3.1 ===== ===================================== src/mailman/utilities/importer.py ===================================== @@ -452,6 +452,8 @@ def import_config_pck(mlist, config_dict): # order dependent; the longer substitution with the common prefix must # show up earlier. convert_placeholders = [ + # First convert \r\n that may have been set by a browser to \n. + ('\r\n', '\n'), ('%(real_name)s@%(host_name)s', 'To unsubscribe send an email to ${short_listname}-leave@${domain}'), ('%(real_name)s mailing list', ===================================== src/mailman/utilities/tests/test_import.py ===================================== @@ -20,7 +20,8 @@ import os import unittest -from datetime import timedelta, datetime +from contextlib import ExitStack +from datetime import datetime, timedelta from enum import Enum from importlib_resources import open_binary from mailman.app.lifecycle import create_list @@ -44,9 +45,11 @@ from mailman.model.roster import RosterVisibility from mailman.testing.helpers import LogFileMark from mailman.testing.layers import ConfigLayer from mailman.utilities.filesystem import makedirs +from mailman.utilities.i18n import search from mailman.utilities.importer import ( Import21Error, check_language_code, import_config_pck) from pickle import load +from shutil import rmtree from unittest import mock from urllib.error import URLError from zope.component import getUtility @@ -785,6 +788,10 @@ class TestConvertToURI(unittest.TestCase): digest_footer='list:member:digest:footer', ) self._pckdict = dict() + # Remove any residual template files. + with ExitStack() as resources: + filepath = list(search(resources, '', self._mlist))[0] + rmtree(filepath, ignore_errors=True) def test_text_to_uri(self): for oldvar, newvar in self._conf_mapping.items(): @@ -811,6 +818,22 @@ class TestConvertToURI(unittest.TestCase): text, expected_text, 'Old variables were not converted for %s' % newvar) + def test_drop_listinfo_if_contains_crs(self): + self._pckdict = dict(msg_footer=( + '_______________________________________________\r\n' + 'This is a message footer\r\n' + '%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s\r\n' + )) + expected_text = ( + '_______________________________________________\n' + 'This is a message footer\n' + ) + import_config_pck(self._mlist, self._pckdict) + newvar = 'list:member:regular:footer' + text = getUtility(ITemplateLoader).get(newvar, self._mlist) + self.assertEqual( + text, expected_text, 'Listinfo URL not dropped') + def test_keep_default(self): # If the value was not changed from MM2.1's default, don't import it. default_msg_footer = ( @@ -837,6 +860,33 @@ class TestConvertToURI(unittest.TestCase): '{} changed unexpectedly: {} != {}'.format( newvar, old_value, new_value)) + def test_keep_default_with_crs(self): + # If the value was not changed from MM2.1's default, don't import it. + default_msg_footer = ( + '_______________________________________________\n' + '%(real_name)s mailing list\n' + '%(real_name)s@%(host_name)s\n' + '%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s\n' + ) + loader = getUtility(ITemplateLoader) + for oldvar in ('msg_footer', 'digest_footer'): + newvar = self._conf_mapping[oldvar] + self._pckdict[str(oldvar)] = str(default_msg_footer).replace( + '\n', '\r\n') + try: + old_value = loader.get(newvar, self._mlist) + except URLError: + old_value = None + import_config_pck(self._mlist, self._pckdict) + try: + new_value = loader.get(newvar, self._mlist) + except URLError: + new_value = None + self.assertEqual( + old_value, new_value, + '{} changed unexpectedly: {} != {}'.format( + newvar, old_value, new_value)) + def test_keep_default_if_fqdn_changed(self): # Use case: importing the old a...@ex.com into b...@ex.com. We can't check # if it changed from the default so don't import. We may do more harm View it on GitLab: https://gitlab.com/mailman/mailman/-/compare/1509c7ff1179506cc77033157b67f190105c6bb4...555964ca4e69a92ae5f9a19e68e41f94491906a4 -- View it on GitLab: https://gitlab.com/mailman/mailman/-/compare/1509c7ff1179506cc77033157b67f190105c6bb4...555964ca4e69a92ae5f9a19e68e41f94491906a4 You're receiving this email because of your account on gitlab.com.
_______________________________________________ Mailman-checkins mailing list Mailman-checkins@python.org Unsubscribe: https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org