aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/test_handlers.py252
1 files changed, 252 insertions, 0 deletions
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):