Mark Sapiro pushed to branch master at GNU Mailman / Mailman Core
Commits: 577e66aa by Mark Sapiro at 2020-05-18T16:23:23-07:00 Fix mime_delete to not break messages when setting non-ascii payloads. - - - - - 1cbdb8ef by Mark Sapiro at 2020-05-18T23:35:17+00:00 Merge branch 'fix_718' into 'master' Fix mime_delete to not break messages when setting non-ascii payloads. Closes #718 See merge request mailman/mailman!646 - - - - - 3 changed files: - src/mailman/handlers/docs/filtering.rst - src/mailman/handlers/mime_delete.py - src/mailman/handlers/tests/test_mimedel.py Changes: ===================================== src/mailman/handlers/docs/filtering.rst ===================================== @@ -103,6 +103,7 @@ the ``multipart`` will be replaced by the subpart. >>> print(msg.as_string()) From: aper...@example.com MIME-Version: 1.0 + Content-Transfer-Encoding: 7bit Content-Type: image/gif X-Content-Filtered-By: Mailman/MimeDel ... <BLANKLINE> @@ -155,6 +156,7 @@ recast as just the subpart. >>> print(msg.as_string()) From: aper...@example.com MIME-Version: 1.0 + Content-Transfer-Encoding: 7bit Content-Type: image/gif X-Content-Filtered-By: Mailman/MimeDel ... <BLANKLINE> @@ -185,6 +187,8 @@ promoted to being the outer part. >>> process(mlist, msg, {}) >>> print(msg.as_string()) From: aper...@example.com + MIME-Version: 1.0 + Content-Transfer-Encoding: 7bit Content-Type: text/plain X-Content-Filtered-By: Mailman/MimeDel ... <BLANKLINE> ===================================== src/mailman/handlers/mime_delete.py ===================================== @@ -166,12 +166,13 @@ def process(mlist, msg, msgdata): def reset_payload(msg, subpart): # Reset payload of msg to contents of subpart, and fix up content headers - payload = subpart.get_payload() if subpart.is_multipart(): - cset = None + msg.set_payload(subpart.get_payload()) else: - cset = subpart.get_content_charset() - msg.set_payload(payload, charset=cset) + cset = subpart.get_content_charset() or 'us-ascii' + msg.set_payload(subpart.get_payload(decode=True).decode( + cset, errors='replace'), + charset=cset) # Don't restore Content-Transfer-Encoding; set_payload sets it based # on the charset. del msg['content-type'] ===================================== src/mailman/handlers/tests/test_mimedel.py ===================================== @@ -397,6 +397,37 @@ multipart/signed # Ensure we can flatten it. dummy = msg.as_bytes() # noqa: F841 + def test_collapse_alternatives_non_ascii_encoded(self): + msg = mfs("""\ +From: a...@example.com +To: t...@example.com +Subject: Testing mpa with transfer encoded subparts +Message-ID: <ant> +MIME-Version: 1.0 +Content-Type: multipart/alternative; boundary="AAAA" + +--AAAA +Content-Type: text/plain; charset="utf-8" +Content-Transfer-Encoding: quoted-printable + +Let=E2=80=99s also consider + +--AAAA +Content-Type: text/html; charset="utf-8" +Content-Transfer-Encoding: quoted-printable + +Let=E2=80=99s also consider + +--AAAA-- +""") + process = config.handlers['mime-delete'].process + process(self._mlist, msg, {}) + self.assertFalse(msg.is_multipart()) + self.assertEqual(msg.get_payload(decode=True), + b'Let\xe2\x80\x99s also consider\n') + # Ensure we can flatten it. + dummy = msg.as_bytes() # noqa: F841 + def test_reset_payload_multipart(self): msg = mfs("""\ From: a...@example.com View it on GitLab: https://gitlab.com/mailman/mailman/-/compare/7bd49cf9d1ff27870975eeaafbed79d9e3e79be8...1cbdb8ef10764537066ccbd88f1a0ff0e8f9903b -- View it on GitLab: https://gitlab.com/mailman/mailman/-/compare/7bd49cf9d1ff27870975eeaafbed79d9e3e79be8...1cbdb8ef10764537066ccbd88f1a0ff0e8f9903b You're receiving this email because of your account on gitlab.com.
_______________________________________________ Mailman-checkins mailing list -- mailman-checkins@python.org To unsubscribe send an email to mailman-checkins-le...@python.org https://mail.python.org/mailman3/lists/mailman-checkins.python.org/ Member address: arch...@jab.org