From e9ec77e3daca1779de124346a239c0e0fcfd74d7 Mon Sep 17 00:00:00 2001 From: Mark Sapiro Date: Tue, 12 Apr 2011 21:13:10 -0700 Subject: Fixed a problem where content filtering could remove the headers from an attached message/rfc822 part if the message in that part is multipart/alternative and collapse_alternatives is Yes. Bug #757062. --- Mailman/Handlers/MimeDel.py | 9 +- NEWS | 3 + tests/test_handlers.py | 252 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 263 insertions(+), 1 deletion(-) diff --git a/Mailman/Handlers/MimeDel.py b/Mailman/Handlers/MimeDel.py index 13845e4f..ab7483ba 100644 --- a/Mailman/Handlers/MimeDel.py +++ b/Mailman/Handlers/MimeDel.py @@ -187,7 +187,14 @@ def collapse_multipart_alternatives(msg): if subpart.get_content_type() == 'multipart/alternative': try: firstalt = subpart.get_payload(0) - newpayload.append(firstalt) + if msg.get_content_type() == 'message/rfc822': + # This is a multipart/alternative message in a + # message/rfc822 part. We treat it specially so as not to + # lose the headers. + reset_payload(subpart, firstalt) + newpayload.append(subpart) + else: + newpayload.append(firstalt) except (IndexError, TypeError): pass elif subpart.is_multipart(): diff --git a/NEWS b/NEWS index 5ec7c3f9..8f9308c0 100644 --- a/NEWS +++ b/NEWS @@ -37,6 +37,9 @@ Here is a history of user visible changes to Mailman. Bug #670988. Bug Fixes and other patches + - Fixed a problem where content filtering could remove the headers from + an attached message/rfc822 part if the message in that part is + multipart/alternative and collapse_alternatives is Yes. Bug #757062. - Changed the subscribe CGI to strip leading and trailing whitespace from the supplied email address. Bug #745432. diff --git a/tests/test_handlers.py b/tests/test_handlers.py index 04647764..aa73b3c1 100644 --- a/tests/test_handlers.py +++ b/tests/test_handlers.py @@ -1363,6 +1363,258 @@ PDF part outer eq(part2.get_content_type(), 'text/plain') eq(part2.get_payload(), 'second text') + def test_message_rfc822(self): + eq = self.assertEqual + msg = email.message_from_string("""\ +Message-ID: <4D9E6AEA.1060802@example.net> +Date: Thu, 07 Apr 2011 18:54:50 -0700 +From: User +MIME-Version: 1.0 +To: Someone +Subject: Message Subject +Content-Type: multipart/mixed; + boundary="------------050603050603060608020908" + +This is a multi-part message in MIME format. +--------------050603050603060608020908 +Content-Type: text/plain; charset=ISO-8859-1 +Content-Transfer-Encoding: 7bit + +Plain body. + +--------------050603050603060608020908 +Content-Type: message/rfc822 +Content-Transfer-Encoding: 7bit +Content-Disposition: attachment + +Message-ID: <4D9E647F.4050308@example.net> +Date: Thu, 07 Apr 2011 18:27:27 -0700 +From: User1 +MIME-Version: 1.0 +To: Someone1 +Content-Type: multipart/mixed; boundary="------------060107040402070208020705" +Subject: Attached Message 1 Subject + +This is a multi-part message in MIME format. +--------------060107040402070208020705 +Content-Type: text/plain; charset=ISO-8859-1 +Content-Transfer-Encoding: 7bit + +Attached Message 1 body. + +--------------060107040402070208020705 +Content-Type: message/rfc822 +Content-Transfer-Encoding: 7bit +Content-Disposition: attachment + +From: User2 +To: Someone2 +Subject: Attached Message 2 Subject +Date: Thu, 7 Apr 2011 19:09:35 -0500 +Message-ID: +MIME-Version: 1.0 +Content-Type: multipart/mixed; + boundary="----=_NextPart_000_0066_01CBF557.56C6F370" + +This is a multi-part message in MIME format. + +------=_NextPart_000_0066_01CBF557.56C6F370 +Content-Type: text/plain; + charset="us-ascii" +Content-Transfer-Encoding: 7bit + +Attached Message 2 body. + +------=_NextPart_000_0066_01CBF557.56C6F370 +Content-Type: message/rfc822 +Content-Transfer-Encoding: 7bit +Content-Disposition: attachment + +From: User3 +To: Someone3 +Subject: Attached Message 3 Subject +Date: Thu, 7 Apr 2011 17:22:04 -0500 +Message-ID: +MIME-Version: 1.0 +Content-Type: multipart/alternative; + boundary="----=_NextPart_000_0058_01CBF557.56C48270" + +This is a multi-part message in MIME format. + +------=_NextPart_000_0058_01CBF557.56C48270 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit + +Attached Message 3 plain body. + +------=_NextPart_000_0058_01CBF557.56C48270 +Content-Type: text/html; + charset="iso-8859-1" +Content-Transfer-Encoding: quoted-printable + + +Attached Message 3 html body. + +------=_NextPart_000_0058_01CBF557.56C48270-- + +------=_NextPart_000_0066_01CBF557.56C6F370 +Content-Type: message/rfc822 +Content-Transfer-Encoding: 7bit +Content-Disposition: attachment + +From: User4 +To: Someone4 +Subject: Attached Message 4 Subject +Date: Thu, 7 Apr 2011 17:24:26 -0500 +Message-ID: <19CC3BDF28CF49AD988FF43B2DBC5F1D@example> +MIME-Version: 1.0 +Content-Type: multipart/mixed; + boundary="----=_NextPart_000_0060_01CBF557.56C6F370" + +This is a multi-part message in MIME format. + +------=_NextPart_000_0060_01CBF557.56C6F370 +Content-Type: multipart/alternative; + boundary="----=_NextPart_001_0061_01CBF557.56C6F370" + +------=_NextPart_001_0061_01CBF557.56C6F370 +Content-Type: text/plain; + charset="us-ascii" +Content-Transfer-Encoding: 7bit + +Attached Message 4 plain body. + +------=_NextPart_001_0061_01CBF557.56C6F370 +Content-Type: text/html; + charset="us-ascii" +Content-Transfer-Encoding: quoted-printable + +Attached Message 4 html body. + +------=_NextPart_001_0061_01CBF557.56C6F370-- + +------=_NextPart_000_0060_01CBF557.56C6F370 +Content-Type: message/rfc822 +Content-Transfer-Encoding: 7bit +Content-Disposition: attachment + +From: User5 +To: Someone5 +Subject: Attached Message 5 Subject +Date: Thu, 7 Apr 2011 16:24:26 -0500 +Message-ID: +Content-Type: multipart/alternative; + boundary="----=_NextPart_000_005C_01CBF557.56C6F370" + +This is a multi-part message in MIME format. + +------=_NextPart_000_005C_01CBF557.56C6F370 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit + +Attached Message 5 plain body. + +------=_NextPart_000_005C_01CBF557.56C6F370 +Content-Type: text/html; + charset="iso-8859-1" +Content-Transfer-Encoding: quoted-printable + +Attached Message 5 html body. + +------=_NextPart_000_005C_01CBF557.56C6F370-- + +------=_NextPart_000_0060_01CBF557.56C6F370 +Content-Type: text/plain; + name="ATT00055.txt" +Content-Transfer-Encoding: quoted-printable +Content-Disposition: attachment; + filename="ATT00055.txt" + +Another plain part. + +------=_NextPart_000_0060_01CBF557.56C6F370-- + +------=_NextPart_000_0066_01CBF557.56C6F370-- + +--------------060107040402070208020705 +Content-Type: text/plain; charset="us-ascii" +MIME-Version: 1.0 +Content-Transfer-Encoding: 7bit +Content-Disposition: inline + +Final plain part. + +--------------060107040402070208020705-- + +--------------050603050603060608020908-- +""") + MimeDel.process(self._mlist, msg, {}) + payload = msg.get_payload() + eq(len(payload), 2) + part1 = msg.get_payload(0) + eq(part1.get_content_type(), 'text/plain') + eq(part1.get_payload(), 'Plain body.\n') + part2 = msg.get_payload(1) + eq(part2.get_content_type(), 'message/rfc822') + payload = part2.get_payload() + eq(len(payload), 1) + part1 = part2.get_payload(0) + eq(part1['subject'], 'Attached Message 1 Subject') + eq(part1.get_content_type(), 'multipart/mixed') + payload = part1.get_payload() + eq(len(payload), 3) + part3 = part1.get_payload(2) + eq(part3.get_content_type(), 'text/plain') + eq(part3.get_payload(), 'Final plain part.\n') + part2 = part1.get_payload(1) + eq(part2.get_content_type(), 'message/rfc822') + part1 = part1.get_payload(0) + eq(part1.get_content_type(), 'text/plain') + eq(part1.get_payload(), 'Attached Message 1 body.\n') + payload = part2.get_payload() + eq(len(payload), 1) + part1 = part2.get_payload(0) + eq(part1['subject'], 'Attached Message 2 Subject') + eq(part1.get_content_type(), 'multipart/mixed') + payload = part1.get_payload() + eq(len(payload), 3) + part3 = part1.get_payload(2) + eq(part3.get_content_type(), 'message/rfc822') + part2 = part1.get_payload(1) + eq(part2.get_content_type(), 'message/rfc822') + part1 = part1.get_payload(0) + eq(part1.get_content_type(), 'text/plain') + eq(part1.get_payload(), 'Attached Message 2 body.\n') + payload = part2.get_payload() + eq(len(payload), 1) + part1 = part2.get_payload(0) + eq(part1['subject'], 'Attached Message 3 Subject') + eq(part1.get_content_type(), 'text/plain') + eq(part1.get_payload(), 'Attached Message 3 plain body.\n') + payload = part3.get_payload() + eq(len(payload), 1) + part1 = part3.get_payload(0) + eq(part1['subject'], 'Attached Message 4 Subject') + eq(part1.get_content_type(), 'multipart/mixed') + payload = part1.get_payload() + eq(len(payload), 3) + part3 = part1.get_payload(2) + eq(part3.get_content_type(), 'text/plain') + eq(part3.get_filename(), 'ATT00055.txt') + eq(part3.get_payload(), 'Another plain part.\n') + part2 = part1.get_payload(1) + eq(part2.get_content_type(), 'message/rfc822') + part1 = part1.get_payload(0) + eq(part1.get_content_type(), 'text/plain') + eq(part1.get_payload(), 'Attached Message 4 plain body.\n') + payload = part2.get_payload() + eq(len(payload), 1) + part1 = part2.get_payload(0) + eq(part1['subject'], 'Attached Message 5 Subject') + eq(part1.get_content_type(), 'text/plain') + eq(part1.get_payload(), 'Attached Message 5 plain body.\n') class TestModerate(TestBase): -- cgit v1.2.3