Abhilash Raj pushed to branch master at GNU Mailman / Mailman Core
Commits: 5c5504bf by Mark Sapiro at 2018-05-07T20:05:06Z Replace invalid characters when encoding header and footers. - - - - - a4dbf1e7 by Abhilash Raj at 2018-05-08T07:11:04Z Merge branch 'decorate' into 'master' Replace invalid characters when encoding header and footers. Closes #409 See merge request mailman/mailman!381 - - - - - 3 changed files: - src/mailman/docs/NEWS.rst - src/mailman/handlers/decorate.py - src/mailman/handlers/tests/test_decorate.py Changes: ===================================== src/mailman/docs/NEWS.rst ===================================== --- a/src/mailman/docs/NEWS.rst +++ b/src/mailman/docs/NEWS.rst @@ -70,6 +70,8 @@ Bugs * The override of Message.as_string() has been extended to catch yet another observed exception. (Closes #470) * Fixed a typo in the help for ``mailman digests --periodic``. (Closes #472) +* Character encoding errors in adding headers and footers to multipart messages + are detected and ``replaced``. (Closes #409) Command line ------------ ===================================== src/mailman/handlers/decorate.py ===================================== --- a/src/mailman/handlers/decorate.py +++ b/src/mailman/handlers/decorate.py @@ -156,11 +156,13 @@ def process(mlist, msg, msgdata): if not isinstance(payload, list): payload = [payload] if len(footer) > 0: - mimeftr = MIMEText(footer.encode(lcset), 'plain', lcset) + mimeftr = MIMEText( + footer.encode(lcset, errors='replace'), 'plain', lcset) mimeftr['Content-Disposition'] = 'inline' payload.append(mimeftr) if len(header) > 0: - mimehdr = MIMEText(header.encode(lcset), 'plain', lcset) + mimehdr = MIMEText( + header.encode(lcset, errors='replace'), 'plain', lcset) mimehdr['Content-Disposition'] = 'inline' payload.insert(0, mimehdr) msg.set_payload(payload) @@ -198,11 +200,13 @@ def process(mlist, msg, msgdata): # any). payload = [inner] if len(header) > 0: - mimehdr = MIMEText(header.encode(lcset), 'plain', lcset) + mimehdr = MIMEText( + header.encode(lcset, errors='replace'), 'plain', lcset) mimehdr['Content-Disposition'] = 'inline' payload.insert(0, mimehdr) if len(footer) > 0: - mimeftr = MIMEText(footer.encode(lcset), 'plain', lcset) + mimeftr = MIMEText( + footer.encode(lcset, errors='replace'), 'plain', lcset) mimeftr['Content-Disposition'] = 'inline' payload.append(mimeftr) msg.set_payload(payload) ===================================== src/mailman/handlers/tests/test_decorate.py ===================================== --- a/src/mailman/handlers/tests/test_decorate.py +++ b/src/mailman/handlers/tests/test_decorate.py @@ -74,6 +74,38 @@ Content-Type: text/plain; This is a test message. """) + self._mpm = mfs("""\ +To: a...@example.com +From: aper...@example.com +Message-ID: <alpha> +Content-Type: multipart/mixed; boundary="aaaaaa" + +--aaaaaa +Content-Type: text/plain; + +This is a test message. +--aaaaaa +Content-Type: text/plain; + +This is part 2 +--aaaaaa-- +""") + self._mpa = mfs("""\ +To: a...@example.com +From: aper...@example.com +Message-ID: <alpha> +Content-Type: multipart/alternative; boundary="aaaaaa" + +--aaaaaa +Content-Type: text/plain; + +This is a test message. +--aaaaaa +Content-Type: text/html; + +This is a test message. +--aaaaaa-- +""") temporary_dir = TemporaryDirectory() self.addCleanup(temporary_dir.cleanup) template_dir = temporary_dir.name @@ -137,6 +169,42 @@ This is a test message. self.assertIn('Anne Person <aper...@example.com>', self._msg.as_string()) + def test_decorate_header_footer_with_bad_character_mpa(self): + site_dir = os.path.join(config.TEMPLATE_DIR, 'site', 'en') + os.makedirs(site_dir) + footer_path = os.path.join(site_dir, 'myfooter.txt') + header_path = os.path.join(site_dir, 'myheader.txt') + with open(footer_path, 'w', encoding='utf-8') as fp: + print('Foot\xe9r:', file=fp) + with open(header_path, 'w', encoding='utf-8') as fp: + print('Head\xe9r:', file=fp) + getUtility(ITemplateManager).set( + 'list:member:regular:footer', None, 'mailman:///myfooter.txt') + getUtility(ITemplateManager).set( + 'list:member:regular:header', None, 'mailman:///myheader.txt') + self._mlist.preferred_language = 'en' + decorate.process(self._mlist, self._mpa, {}) + self.assertIn('Head?r:', self._mpa.get_payload(0).as_string()) + self.assertIn('Foot?r:', self._mpa.get_payload(2).as_string()) + + def test_decorate_header_footer_with_bad_character_mpm(self): + site_dir = os.path.join(config.TEMPLATE_DIR, 'site', 'en') + os.makedirs(site_dir) + footer_path = os.path.join(site_dir, 'myfooter.txt') + header_path = os.path.join(site_dir, 'myheader.txt') + with open(footer_path, 'w', encoding='utf-8') as fp: + print('Foot\xe9r:', file=fp) + with open(header_path, 'w', encoding='utf-8') as fp: + print('Head\xe9r:', file=fp) + getUtility(ITemplateManager).set( + 'list:member:regular:footer', None, 'mailman:///myfooter.txt') + getUtility(ITemplateManager).set( + 'list:member:regular:header', None, 'mailman:///myheader.txt') + self._mlist.preferred_language = 'en' + decorate.process(self._mlist, self._mpm, {}) + self.assertIn('Head?r:', self._mpm.get_payload(0).as_string()) + self.assertIn('Foot?r:', self._mpm.get_payload(3).as_string()) + def test_list_id_allowed_in_template_uri(self): # Issue #196 - allow the list_id in the template uri expansion. list_dir = os.path.join( View it on GitLab: https://gitlab.com/mailman/mailman/compare/c215b56d24ca17a81ed30105348f0f687a1dff71...a4dbf1e7cf6ed30a56e4eb9f0d473196c94ccf32 -- View it on GitLab: https://gitlab.com/mailman/mailman/compare/c215b56d24ca17a81ed30105348f0f687a1dff71...a4dbf1e7cf6ed30a56e4eb9f0d473196c94ccf32 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