aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Sapiro <msapiro@value.net>2011-04-12 21:13:10 -0700
committerMark Sapiro <msapiro@value.net>2011-04-12 21:13:10 -0700
commite9ec77e3daca1779de124346a239c0e0fcfd74d7 (patch)
tree4cbcba527ed138ac3c1a410117980144052c5260
parentdcbf47f5dad04b1b879dfe4fdc40d9aa633d403b (diff)
downloadmailman2-e9ec77e3daca1779de124346a239c0e0fcfd74d7.tar.gz
mailman2-e9ec77e3daca1779de124346a239c0e0fcfd74d7.tar.xz
mailman2-e9ec77e3daca1779de124346a239c0e0fcfd74d7.zip
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.
-rw-r--r--Mailman/Handlers/MimeDel.py9
-rw-r--r--NEWS3
-rw-r--r--tests/test_handlers.py252
3 files changed, 263 insertions, 1 deletions
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 <user@example.com>
+MIME-Version: 1.0
+To: Someone <someone@example.net>
+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 <user1@example.com>
+MIME-Version: 1.0
+To: Someone1 <someone1@example.net>
+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 <user2@example.com>
+To: Someone2 <someone2@example.net>
+Subject: Attached Message 2 Subject
+Date: Thu, 7 Apr 2011 19:09:35 -0500
+Message-ID: <DAE689E1FD1D493BACD15180145B4151@example.net>
+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 <user3@example.com>
+To: Someone3 <someone3@example.net>
+Subject: Attached Message 3 Subject
+Date: Thu, 7 Apr 2011 17:22:04 -0500
+Message-ID: <BANLkTi=SzfNJo-V7cvrg3nE3uOi9uxXv3g@example.net>
+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 <user4@example.com>
+To: Someone4 <someone4@example.net>
+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 <user5@example.com>
+To: Someone5 <someone5@example.net>
+Subject: Attached Message 5 Subject
+Date: Thu, 7 Apr 2011 16:24:26 -0500
+Message-ID: <some_id@example>
+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):