summaryrefslogtreecommitdiffstats
path: root/Lib/email/test
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-08-25 13:43:02 (GMT)
committerGuido van Rossum <guido@python.org>2007-08-25 13:43:02 (GMT)
commit6398b7a351d04408fa8ce0204d78559e8d6ac98f (patch)
tree5f274983fa91009d1a7b4bfa26de59a83942581f /Lib/email/test
parentf616b224506ef17ac9ab4378c92b99ae816b88f7 (diff)
downloadcpython-6398b7a351d04408fa8ce0204d78559e8d6ac98f.zip
cpython-6398b7a351d04408fa8ce0204d78559e8d6ac98f.tar.gz
cpython-6398b7a351d04408fa8ce0204d78559e8d6ac98f.tar.bz2
Remove the email package for now.
Once Barry and the email-sig have a working new version we'll add it back. If it doesn't make the 3.0a deadline (release August 31), too bad.
Diffstat (limited to 'Lib/email/test')
-rw-r--r--Lib/email/test/__init__.py0
-rw-r--r--Lib/email/test/data/PyBanner048.gifbin954 -> 0 bytes
-rw-r--r--Lib/email/test/data/audiotest.aubin23493 -> 0 bytes
-rw-r--r--Lib/email/test/data/msg_01.txt19
-rw-r--r--Lib/email/test/data/msg_02.txt135
-rw-r--r--Lib/email/test/data/msg_03.txt16
-rw-r--r--Lib/email/test/data/msg_04.txt37
-rw-r--r--Lib/email/test/data/msg_05.txt28
-rw-r--r--Lib/email/test/data/msg_06.txt33
-rw-r--r--Lib/email/test/data/msg_07.txt83
-rw-r--r--Lib/email/test/data/msg_08.txt24
-rw-r--r--Lib/email/test/data/msg_09.txt24
-rw-r--r--Lib/email/test/data/msg_10.txt32
-rw-r--r--Lib/email/test/data/msg_11.txt7
-rw-r--r--Lib/email/test/data/msg_12.txt36
-rw-r--r--Lib/email/test/data/msg_12a.txt38
-rw-r--r--Lib/email/test/data/msg_13.txt94
-rw-r--r--Lib/email/test/data/msg_14.txt23
-rw-r--r--Lib/email/test/data/msg_15.txt52
-rw-r--r--Lib/email/test/data/msg_16.txt123
-rw-r--r--Lib/email/test/data/msg_17.txt12
-rw-r--r--Lib/email/test/data/msg_18.txt6
-rw-r--r--Lib/email/test/data/msg_19.txt43
-rw-r--r--Lib/email/test/data/msg_20.txt22
-rw-r--r--Lib/email/test/data/msg_21.txt20
-rw-r--r--Lib/email/test/data/msg_22.txt46
-rw-r--r--Lib/email/test/data/msg_23.txt8
-rw-r--r--Lib/email/test/data/msg_24.txt10
-rw-r--r--Lib/email/test/data/msg_25.txt117
-rw-r--r--Lib/email/test/data/msg_26.txt45
-rw-r--r--Lib/email/test/data/msg_27.txt15
-rw-r--r--Lib/email/test/data/msg_28.txt25
-rw-r--r--Lib/email/test/data/msg_29.txt22
-rw-r--r--Lib/email/test/data/msg_30.txt23
-rw-r--r--Lib/email/test/data/msg_31.txt15
-rw-r--r--Lib/email/test/data/msg_32.txt14
-rw-r--r--Lib/email/test/data/msg_33.txt29
-rw-r--r--Lib/email/test/data/msg_34.txt19
-rw-r--r--Lib/email/test/data/msg_35.txt4
-rw-r--r--Lib/email/test/data/msg_36.txt40
-rw-r--r--Lib/email/test/data/msg_37.txt22
-rw-r--r--Lib/email/test/data/msg_38.txt101
-rw-r--r--Lib/email/test/data/msg_39.txt83
-rw-r--r--Lib/email/test/data/msg_40.txt10
-rw-r--r--Lib/email/test/data/msg_41.txt8
-rw-r--r--Lib/email/test/data/msg_42.txt20
-rw-r--r--Lib/email/test/data/msg_43.txt217
-rw-r--r--Lib/email/test/data/msg_44.txt35
-rw-r--r--Lib/email/test/test_email.py3285
-rw-r--r--Lib/email/test/test_email_codecs.py77
-rw-r--r--Lib/email/test/test_email_codecs_renamed.py77
-rw-r--r--Lib/email/test/test_email_renamed.py3283
-rw-r--r--Lib/email/test/test_email_torture.py136
53 files changed, 0 insertions, 8693 deletions
diff --git a/Lib/email/test/__init__.py b/Lib/email/test/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/Lib/email/test/__init__.py
+++ /dev/null
diff --git a/Lib/email/test/data/PyBanner048.gif b/Lib/email/test/data/PyBanner048.gif
deleted file mode 100644
index 1a5c87f..0000000
--- a/Lib/email/test/data/PyBanner048.gif
+++ /dev/null
Binary files differ
diff --git a/Lib/email/test/data/audiotest.au b/Lib/email/test/data/audiotest.au
deleted file mode 100644
index 1ad28ce..0000000
--- a/Lib/email/test/data/audiotest.au
+++ /dev/null
Binary files differ
diff --git a/Lib/email/test/data/msg_01.txt b/Lib/email/test/data/msg_01.txt
deleted file mode 100644
index 7e33bcf..0000000
--- a/Lib/email/test/data/msg_01.txt
+++ /dev/null
@@ -1,19 +0,0 @@
-Return-Path: <bbb@zzz.org>
-Delivered-To: bbb@zzz.org
-Received: by mail.zzz.org (Postfix, from userid 889)
- id 27CEAD38CC; Fri, 4 May 2001 14:05:44 -0400 (EDT)
-MIME-Version: 1.0
-Content-Type: text/plain; charset=us-ascii
-Content-Transfer-Encoding: 7bit
-Message-ID: <15090.61304.110929.45684@aaa.zzz.org>
-From: bbb@ddd.com (John X. Doe)
-To: bbb@zzz.org
-Subject: This is a test message
-Date: Fri, 4 May 2001 14:05:44 -0400
-
-
-Hi,
-
-Do you like this message?
-
--Me
diff --git a/Lib/email/test/data/msg_02.txt b/Lib/email/test/data/msg_02.txt
deleted file mode 100644
index 43f2480..0000000
--- a/Lib/email/test/data/msg_02.txt
+++ /dev/null
@@ -1,135 +0,0 @@
-MIME-version: 1.0
-From: ppp-request@zzz.org
-Sender: ppp-admin@zzz.org
-To: ppp@zzz.org
-Subject: Ppp digest, Vol 1 #2 - 5 msgs
-Date: Fri, 20 Apr 2001 20:18:00 -0400 (EDT)
-X-Mailer: Mailman v2.0.4
-X-Mailman-Version: 2.0.4
-Content-Type: multipart/mixed; boundary="192.168.1.2.889.32614.987812255.500.21814"
-
---192.168.1.2.889.32614.987812255.500.21814
-Content-type: text/plain; charset=us-ascii
-Content-description: Masthead (Ppp digest, Vol 1 #2)
-
-Send Ppp mailing list submissions to
- ppp@zzz.org
-
-To subscribe or unsubscribe via the World Wide Web, visit
- http://www.zzz.org/mailman/listinfo/ppp
-or, via email, send a message with subject or body 'help' to
- ppp-request@zzz.org
-
-You can reach the person managing the list at
- ppp-admin@zzz.org
-
-When replying, please edit your Subject line so it is more specific
-than "Re: Contents of Ppp digest..."
-
-
---192.168.1.2.889.32614.987812255.500.21814
-Content-type: text/plain; charset=us-ascii
-Content-description: Today's Topics (5 msgs)
-
-Today's Topics:
-
- 1. testing #1 (Barry A. Warsaw)
- 2. testing #2 (Barry A. Warsaw)
- 3. testing #3 (Barry A. Warsaw)
- 4. testing #4 (Barry A. Warsaw)
- 5. testing #5 (Barry A. Warsaw)
-
---192.168.1.2.889.32614.987812255.500.21814
-Content-Type: multipart/digest; boundary="__--__--"
-
---__--__--
-
-Message: 1
-Content-Type: text/plain; charset=us-ascii
-Content-Transfer-Encoding: 7bit
-Date: Fri, 20 Apr 2001 20:16:13 -0400
-To: ppp@zzz.org
-From: barry@digicool.com (Barry A. Warsaw)
-Subject: [Ppp] testing #1
-Precedence: bulk
-
-
-hello
-
-
---__--__--
-
-Message: 2
-Date: Fri, 20 Apr 2001 20:16:21 -0400
-Content-Type: text/plain; charset=us-ascii
-Content-Transfer-Encoding: 7bit
-To: ppp@zzz.org
-From: barry@digicool.com (Barry A. Warsaw)
-Precedence: bulk
-
-
-hello
-
-
---__--__--
-
-Message: 3
-Date: Fri, 20 Apr 2001 20:16:25 -0400
-Content-Type: text/plain; charset=us-ascii
-Content-Transfer-Encoding: 7bit
-To: ppp@zzz.org
-From: barry@digicool.com (Barry A. Warsaw)
-Subject: [Ppp] testing #3
-Precedence: bulk
-
-
-hello
-
-
---__--__--
-
-Message: 4
-Date: Fri, 20 Apr 2001 20:16:28 -0400
-Content-Type: text/plain; charset=us-ascii
-Content-Transfer-Encoding: 7bit
-To: ppp@zzz.org
-From: barry@digicool.com (Barry A. Warsaw)
-Subject: [Ppp] testing #4
-Precedence: bulk
-
-
-hello
-
-
---__--__--
-
-Message: 5
-Date: Fri, 20 Apr 2001 20:16:32 -0400
-Content-Type: text/plain; charset=us-ascii
-Content-Transfer-Encoding: 7bit
-To: ppp@zzz.org
-From: barry@digicool.com (Barry A. Warsaw)
-Subject: [Ppp] testing #5
-Precedence: bulk
-
-
-hello
-
-
-
-
---__--__----
---192.168.1.2.889.32614.987812255.500.21814
-Content-type: text/plain; charset=us-ascii
-Content-description: Digest Footer
-
-_______________________________________________
-Ppp mailing list
-Ppp@zzz.org
-http://www.zzz.org/mailman/listinfo/ppp
-
-
---192.168.1.2.889.32614.987812255.500.21814--
-
-End of Ppp Digest
-
diff --git a/Lib/email/test/data/msg_03.txt b/Lib/email/test/data/msg_03.txt
deleted file mode 100644
index c748ebf..0000000
--- a/Lib/email/test/data/msg_03.txt
+++ /dev/null
@@ -1,16 +0,0 @@
-Return-Path: <bbb@zzz.org>
-Delivered-To: bbb@zzz.org
-Received: by mail.zzz.org (Postfix, from userid 889)
- id 27CEAD38CC; Fri, 4 May 2001 14:05:44 -0400 (EDT)
-Message-ID: <15090.61304.110929.45684@aaa.zzz.org>
-From: bbb@ddd.com (John X. Doe)
-To: bbb@zzz.org
-Subject: This is a test message
-Date: Fri, 4 May 2001 14:05:44 -0400
-
-
-Hi,
-
-Do you like this message?
-
--Me
diff --git a/Lib/email/test/data/msg_04.txt b/Lib/email/test/data/msg_04.txt
deleted file mode 100644
index 1f633c4..0000000
--- a/Lib/email/test/data/msg_04.txt
+++ /dev/null
@@ -1,37 +0,0 @@
-Return-Path: <barry@python.org>
-Delivered-To: barry@python.org
-Received: by mail.python.org (Postfix, from userid 889)
- id C2BF0D37C6; Tue, 11 Sep 2001 00:05:05 -0400 (EDT)
-MIME-Version: 1.0
-Content-Type: multipart/mixed; boundary="h90VIIIKmx"
-Content-Transfer-Encoding: 7bit
-Message-ID: <15261.36209.358846.118674@anthem.python.org>
-From: barry@python.org (Barry A. Warsaw)
-To: barry@python.org
-Subject: a simple multipart
-Date: Tue, 11 Sep 2001 00:05:05 -0400
-X-Mailer: VM 6.95 under 21.4 (patch 4) "Artificial Intelligence" XEmacs Lucid
-X-Attribution: BAW
-X-Oblique-Strategy: Make a door into a window
-
-
---h90VIIIKmx
-Content-Type: text/plain
-Content-Disposition: inline;
- filename="msg.txt"
-Content-Transfer-Encoding: 7bit
-
-a simple kind of mirror
-to reflect upon our own
-
---h90VIIIKmx
-Content-Type: text/plain
-Content-Disposition: inline;
- filename="msg.txt"
-Content-Transfer-Encoding: 7bit
-
-a simple kind of mirror
-to reflect upon our own
-
---h90VIIIKmx--
-
diff --git a/Lib/email/test/data/msg_05.txt b/Lib/email/test/data/msg_05.txt
deleted file mode 100644
index 87d5e9c..0000000
--- a/Lib/email/test/data/msg_05.txt
+++ /dev/null
@@ -1,28 +0,0 @@
-From: foo
-Subject: bar
-To: baz
-MIME-Version: 1.0
-Content-Type: multipart/report; report-type=delivery-status;
- boundary="D1690A7AC1.996856090/mail.example.com"
-Message-Id: <20010803162810.0CA8AA7ACC@mail.example.com>
-
-This is a MIME-encapsulated message.
-
---D1690A7AC1.996856090/mail.example.com
-Content-Type: text/plain
-
-Yadda yadda yadda
-
---D1690A7AC1.996856090/mail.example.com
-
-Yadda yadda yadda
-
---D1690A7AC1.996856090/mail.example.com
-Content-Type: message/rfc822
-
-From: nobody@python.org
-
-Yadda yadda yadda
-
---D1690A7AC1.996856090/mail.example.com--
-
diff --git a/Lib/email/test/data/msg_06.txt b/Lib/email/test/data/msg_06.txt
deleted file mode 100644
index 69f3a47..0000000
--- a/Lib/email/test/data/msg_06.txt
+++ /dev/null
@@ -1,33 +0,0 @@
-Return-Path: <barry@python.org>
-Delivered-To: barry@python.org
-MIME-Version: 1.0
-Content-Type: message/rfc822
-Content-Description: forwarded message
-Content-Transfer-Encoding: 7bit
-Message-ID: <15265.9482.641338.555352@python.org>
-From: barry@zope.com (Barry A. Warsaw)
-Sender: barry@python.org
-To: barry@python.org
-Subject: forwarded message from Barry A. Warsaw
-Date: Thu, 13 Sep 2001 17:28:42 -0400
-X-Mailer: VM 6.95 under 21.4 (patch 4) "Artificial Intelligence" XEmacs Lucid
-X-Attribution: BAW
-X-Oblique-Strategy: Be dirty
-X-Url: http://barry.wooz.org
-
-MIME-Version: 1.0
-Content-Type: text/plain; charset=us-ascii
-Return-Path: <barry@python.org>
-Delivered-To: barry@python.org
-Message-ID: <15265.9468.713530.98441@python.org>
-From: barry@zope.com (Barry A. Warsaw)
-Sender: barry@python.org
-To: barry@python.org
-Subject: testing
-Date: Thu, 13 Sep 2001 17:28:28 -0400
-X-Mailer: VM 6.95 under 21.4 (patch 4) "Artificial Intelligence" XEmacs Lucid
-X-Attribution: BAW
-X-Oblique-Strategy: Spectrum analysis
-X-Url: http://barry.wooz.org
-
-
diff --git a/Lib/email/test/data/msg_07.txt b/Lib/email/test/data/msg_07.txt
deleted file mode 100644
index 721f3a0..0000000
--- a/Lib/email/test/data/msg_07.txt
+++ /dev/null
@@ -1,83 +0,0 @@
-MIME-Version: 1.0
-From: Barry <barry@digicool.com>
-To: Dingus Lovers <cravindogs@cravindogs.com>
-Subject: Here is your dingus fish
-Date: Fri, 20 Apr 2001 19:35:02 -0400
-Content-Type: multipart/mixed; boundary="BOUNDARY"
-
---BOUNDARY
-Content-Type: text/plain; charset="us-ascii"
-
-Hi there,
-
-This is the dingus fish.
-
---BOUNDARY
-Content-Type: image/gif; name="dingusfish.gif"
-Content-Transfer-Encoding: base64
-content-disposition: attachment; filename="dingusfish.gif"
-
-R0lGODdhAAEAAfAAAP///wAAACwAAAAAAAEAAQAC/oSPqcvtD6OctNqLs968+w+G4kiW5omm6sq2
-7gvH8kzX9o3n+s73/g8MCofEovGITGICTKbyCV0FDNOo9SqpQqpOrJfXzTQj2vD3TGtqL+NtGQ2f
-qTXmxzuOd7WXdcc9DyjU53ewFni4s0fGhdiYaEhGBelICTNoV1j5NUnFcrmUqemjNifJVWpaOqaI
-oFq3SspZsSraE7sHq3jr1MZqWvi662vxV4tD+pvKW6aLDOCLyur8PDwbanyDeq0N3DctbQYeLDvR
-RY6t95m6UB0d3mwIrV7e2VGNvjjffukeJp4w7F65KecGFsTHQGAygOrgrWs1jt28Rc88KESYcGLA
-/obvTkH6p+CinWJiJmIMqXGQwH/y4qk0SYjgQTczT3ajKZGfuI0uJ4kkVI/DT5s3/ejkxI0aT4Y+
-YTYgWbImUaXk9nlLmnSh1qJiJFl0OpUqRK4oOy7NyRQtHWofhoYVxkwWXKUSn0YsS+fUV6lhqfYb
-6ayd3Z5qQdG1B7bvQzaJjwUV2lixMUZ7JVsOlfjWVr/3NB/uFvnySBN6Dcb6rGwaRM3wsormw5cC
-M9NxWy/bWdufudCvy8bOAjXjVVwta/uO21sE5RHBCzNFXtgq9ORtH4eYjVP4Yryo026nvkFmCeyA
-B29efV6ravCMK5JwWd5897Qrx7ll38o6iHDZ/rXPR//feevhF4l7wjUGX3xq1eeRfM4RSJGBIV1D
-z1gKPkfWag3mVBVvva1RlX5bAJTPR/2YqNtw/FkIYYEi/pIZiAdpcxpoHtmnYYoZtvhUftzdx5ZX
-JSKDW405zkGcZzzGZ6KEv4FI224oDmijlEf+xp6MJK5ojY/ASeVUR+wsKRuJ+XFZ5o7ZeEime8t1
-ouUsU6YjF5ZtUihhkGfCdFQLWQFJ3UXxmElfhQnR+eCdcDbkFZp6vTRmj56ApCihn5QGpaToNZmR
-n3NVSpZcQpZ2KEONusaiCsKAug0wkQbJSFO+PTSjneGxOuFjPlUk3ovWvdIerjUg9ZGIOtGq/qeX
-eCYrrCX+1UPsgTKGGRSbzd5q156d/gpfbJxe66eD5iQKrXj7RGgruGxs62qebBHUKS32CKluCiqZ
-qh+pmehmEb71noAUoe5e9Zm17S7773V10pjrtG4CmuurCV/n6zLK5turWNhqOvFXbjhZrMD0YhKe
-wR0zOyuvsh6MWrGoIuzvyWu5y1WIFAqmJselypxXh6dKLNOKEB98L88bS2rkNqqlKzCNJp9c0G0j
-Gzh0iRrCbHSXmPR643QS+4rWhgFmnSbSuXCjS0xAOWkU2UdLqyuUNfHSFdUouy3bm5i5GnDM3tG8
-doJ4r5tqu3pPbRSVfvs8uJzeNXhp3n4j/tZ42SwH7eaWUUOjc3qFV9453UHTXZfcLH+OeNs5g36x
-lBnHvTm7EbMbLeuaLncao8vWCXimfo1o+843Ak6y4ChNeGntvAYvfLK4ezmoyNIbNCLTCXO9ZV3A
-E8/s88RczPzDwI4Ob7XZyl7+9Miban29h+tJZPrE21wgvBphDfrrfPdCTPKJD/y98L1rZwHcV6Jq
-Zab0metpuNIX/qAFPoz171WUaUb4HAhBSzHuHfjzHb3kha/2Cctis/ORArVHNYfFyYRH2pYIRzic
-isVOfPWD1b6mRTqpCRBozzof6UZVvFXRxWIr3GGrEviGYgyPMfahheiSaLs/9QeFu7oZ/ndSY8DD
-ya9x+uPed+7mxN2IzIISBOMLFYWVqC3Pew1T2nFuuCiwZS5/v6II10i4t1OJcUH2U9zxKodHsGGv
-Oa+zkvNUYUOa/TCCRutF9MzDwdlUMJADTCGSbDQ5OV4PTamDoPEi6Ecc/RF5RWwkcdSXvSOaDWSn
-I9LlvubFTQpuc6JKXLcKeb+xdbKRBnwREemXyjg6ME65aJiOuBgrktzykfPLJBKR9ClMavJ62/Ff
-BlNIyod9yX9wcSXexnXFpvkrbXk64xsx5Db7wXKP5fSgsvwIMM/9631VLBfkmtbHRXpqmtei52hG
-pUwSlo+BASQoeILDOBgREECxBBh5/iYmNsQ9dIv5+OI++QkqdsJPc3uykz5fkM+OraeekcQF7X4n
-B5S67za5U967PmooGQhUXfF7afXyCD7ONdRe17QogYjVx38uLwtrS6nhTnm15LQUnu9E2uK6CNI/
-1HOABj0ESwOjut4FEpFQpdNAm4K2LHnDWHNcmKB2ioKBogysVZtMO2nSxUdZ8Yk2kJc7URioLVI0
-YgmtIwZj4LoeKemgnOnbUdGnzZ4Oa6scqiolBGqS6RgWNLu0RMhcaE6rhhU4hiuqFXPAG8fGwTPW
-FKeLMtdVmXLSs5YJGF/YeVm7rREMlY3UYE+yCxbaMXX8y15m5zVHq6GOKDMynzII/jdUHdyVqIy0
-ifX2+r/EgtZcvRzSb72gU9ui87M2VecjKildW/aFqaYhKoryUjfB/g4qtyVuc60xFDGmCxwjW+qu
-zjuwl2GkOWn66+3QiiEctvd04OVvcCVzjgT7lrkvjVGKKHmmlDUKowSeikb5kK/mJReuWOxONx+s
-ULsl+Lqb0CVn0SrVyJ6wt4t6yTeSCafhPhAf0OXn6L60UMxiLolFAtmN35S2Ob1lZpQ1r/n0Qb5D
-oQ1zJiRVDgF8N3Q8TYfbi3DyWCy3lT1nxyBs6FT3S2GOzWRlxwKvlRP0RPJA9SjxEy0UoEnkA+M4
-cnzLMJrBGWLFEaaUb5lvpqbq/loOaU5+DFuHPxo82/OZuM8FXG3oVNZhtWpMpb/0Xu5m/LfLhHZQ
-7yuVI0MqZ7NE43imC8jH3IwGZlbPm0xkJYs7+2U48hXTsFSMqgGDvai0kLxyynKNT/waj+q1c1tz
-GjOpPBgdCSq3UKZxCSsqFIY+O6JbAWGWcV1pwqLyj5sGqCF1xb1F3varUWqrJv6cN3PrUXzijtfZ
-FshpBL3Xwr4GIPvU2N8EjrJgS1zl21rbXQMXeXc5jjFyrhpCzijSv/RQtyPSzHCFMhlME95fHglt
-pRsX+dfSQjUeHAlpWzJ5iOo79Ldnaxai6bXTcGO3fp07ri7HLEmXXPlYi8bv/qVxvNcdra6m7Rlb
-6JBTb5fd66VhFRjGArh2n7R1rDW4P5NOT9K0I183T2scYkeZ3q/VFyLb09U9ajzXBS8Kgkhc4mBS
-kYY9cy3Vy9lUnuNJH8HGIclUilwnBtjUOH0gteGOZ4c/XNrhXLSYDyxfnD8z1pDy7rYRvDolhnbe
-UMzxCZUs40s6s7UIvBnLgc0+vKuOkIXeOrDymlp+Zxra4MZLBbVrqD/jTJ597pDmnw5c4+DbyB88
-9Cg9DodYcSuMZT/114pptqc/EuTjRPvH/z5slzI3tluOEBBLqOXLOX+0I5929tO97wkvl/atCz+y
-xJrdwteW2FNW/NSmBP+f/maYtVs/bYyBC7Ox3jsYZHL05CIrBa/nS+b3bHfiYm4Ueil1YZZSgAUI
-fFZ1dxUmeA2oQRQ3RuGXNGLFV9/XbGFGPV6kfzk1TBBCd+izc7q1H+OHMJwmaBX2IQNYVAKHYepV
-SSGCe6CnbYHHETKGNe43EDvFgZr0gB/nVHPHZ80VV1ojOiI3XDvYIkl4ayo4bxQIgrFXWTvBI0nH
-VElWMuw2aLUWCRHHf8ymVCHjFlJnOSojfevCYyyyZDH0IcvHhrsnQ5O1OsWzONuVVKIxSxiFZ/tR
-fKDAf6xFTnw4O9Qig2VCfW2hJQrmMOuHW0W3dLQmCMO2ccdUd/xyfflH/olTiHZVdGwb8nIwRzSE
-J15jFlOJuBZBZ4CiyHyd2IFylFlB+HgHhYabhWOGwYO1ZH/Og1dtQlFMk352CGRSIFTapnWQEUtN
-l4zv8S0aaCFDyGCBqDUxZYpxGHX01y/JuH1xhn7TOCnNCI4eKDs5WGX4R425F4vF1o3BJ4vO0otq
-I3rimI7jJY1jISqnBxknCIvruF83mF5wN4X7qGLIhR8A2Vg0yFERSIXn9Vv3GHy3Vj/WIkKddlYi
-yIMv2I/VMjTLpW7pt05SWIZR0RPyxpB4SIUM9lBPGBl0GC7oSEEwRYLe4pJpZY2P0zbI1n+Oc44w
-qY3PUnmF0ixjVpDD/mJ9wpOBGTVgXlaCaZiPcIWK5NiKBIiPdGaQ0TWGvAiG7nMchdZb7Vgf8zNi
-MuMyzRdy/lePe9iC4TRx7WhhOQI/QiSVNAmAa2lT/piFbuh7ofJoYSZzrSZ1bvmWw3eN2nKUPVky
-uPN5/VRfohRd0VYZoqhKIlU6TXYhJxmPUIloAwc1bPmHEpaZYZORHNlXUJM07hATwHR8MJYqkwWR
-WaIezFhxSFlc8/Fq82hEnpeRozg3ULhhr9lAGtVEkCg5ZNRuuVleBPaZadhG0ZgkyPmDOTOKzViM
-YgOcpukKqQcbjAWS0IleQ2ROjdh6A+md1qWdBRSX7iSYgFRTtRmBpJioieXJiHfJiMGIR9fJOn8I
-MSfXYhspn4ooSa2mSAj4n+8Bmg03fBJZoPOJgsVZRxu1oOMRPXYYjdqjihFaEoZpXBREanuJoRI6
-cibFinq4ngUKh/wQd/H5ofYCZ0HJXR62opZFaAT0iFIZo4DIiUojkjeqKiuoZirKo5Y1a7AWckGa
-BkuYoD5lpDK6eUs6CkDqpETwl1EqpfhJpVeKpVl6EgUAADs=
-
---BOUNDARY--
diff --git a/Lib/email/test/data/msg_08.txt b/Lib/email/test/data/msg_08.txt
deleted file mode 100644
index b563083..0000000
--- a/Lib/email/test/data/msg_08.txt
+++ /dev/null
@@ -1,24 +0,0 @@
-MIME-Version: 1.0
-From: Barry Warsaw <barry@zope.com>
-To: Dingus Lovers <cravindogs@cravindogs.com>
-Subject: Lyrics
-Date: Fri, 20 Apr 2001 19:35:02 -0400
-Content-Type: multipart/mixed; boundary="BOUNDARY"
-
---BOUNDARY
-Content-Type: text/plain; charset="us-ascii"
-
-
---BOUNDARY
-Content-Type: text/html; charset="iso-8859-1"
-
-
---BOUNDARY
-Content-Type: text/plain; charset="iso-8859-2"
-
-
---BOUNDARY
-Content-Type: text/plain; charset="koi8-r"
-
-
---BOUNDARY--
diff --git a/Lib/email/test/data/msg_09.txt b/Lib/email/test/data/msg_09.txt
deleted file mode 100644
index 575c4c2..0000000
--- a/Lib/email/test/data/msg_09.txt
+++ /dev/null
@@ -1,24 +0,0 @@
-MIME-Version: 1.0
-From: Barry Warsaw <barry@zope.com>
-To: Dingus Lovers <cravindogs@cravindogs.com>
-Subject: Lyrics
-Date: Fri, 20 Apr 2001 19:35:02 -0400
-Content-Type: multipart/mixed; boundary="BOUNDARY"
-
---BOUNDARY
-Content-Type: text/plain; charset="us-ascii"
-
-
---BOUNDARY
-Content-Type: text/html; charset="iso-8859-1"
-
-
---BOUNDARY
-Content-Type: text/plain
-
-
---BOUNDARY
-Content-Type: text/plain; charset="koi8-r"
-
-
---BOUNDARY--
diff --git a/Lib/email/test/data/msg_10.txt b/Lib/email/test/data/msg_10.txt
deleted file mode 100644
index bd30d13..0000000
--- a/Lib/email/test/data/msg_10.txt
+++ /dev/null
@@ -1,32 +0,0 @@
-MIME-Version: 1.0
-From: Barry Warsaw <barry@zope.com>
-To: Dingus Lovers <cravindogs@cravindogs.com>
-Subject: Lyrics
-Date: Fri, 20 Apr 2001 19:35:02 -0400
-Content-Type: multipart/mixed; boundary="BOUNDARY"
-
---BOUNDARY
-Content-Type: text/plain; charset="us-ascii"
-Content-Transfer-Encoding: 7bit
-
-This is a 7bit encoded message.
-
---BOUNDARY
-Content-Type: text/html; charset="iso-8859-1"
-Content-Transfer-Encoding: Quoted-Printable
-
-=A1This is a Quoted Printable encoded message!
-
---BOUNDARY
-Content-Type: text/plain; charset="iso-8859-1"
-Content-Transfer-Encoding: Base64
-
-VGhpcyBpcyBhIEJhc2U2NCBlbmNvZGVkIG1lc3NhZ2Uu
-
-
---BOUNDARY
-Content-Type: text/plain; charset="iso-8859-1"
-
-This has no Content-Transfer-Encoding: header.
-
---BOUNDARY--
diff --git a/Lib/email/test/data/msg_11.txt b/Lib/email/test/data/msg_11.txt
deleted file mode 100644
index 8f7f199..0000000
--- a/Lib/email/test/data/msg_11.txt
+++ /dev/null
@@ -1,7 +0,0 @@
-Content-Type: message/rfc822
-MIME-Version: 1.0
-Subject: The enclosing message
-
-Subject: An enclosed message
-
-Here is the body of the message.
diff --git a/Lib/email/test/data/msg_12.txt b/Lib/email/test/data/msg_12.txt
deleted file mode 100644
index 4bec8d9..0000000
--- a/Lib/email/test/data/msg_12.txt
+++ /dev/null
@@ -1,36 +0,0 @@
-MIME-Version: 1.0
-From: Barry Warsaw <barry@zope.com>
-To: Dingus Lovers <cravindogs@cravindogs.com>
-Subject: Lyrics
-Date: Fri, 20 Apr 2001 19:35:02 -0400
-Content-Type: multipart/mixed; boundary="BOUNDARY"
-
---BOUNDARY
-Content-Type: text/plain; charset="us-ascii"
-
-
---BOUNDARY
-Content-Type: text/html; charset="iso-8859-1"
-
-
---BOUNDARY
-Content-Type: multipart/mixed; boundary="ANOTHER"
-
---ANOTHER
-Content-Type: text/plain; charset="iso-8859-2"
-
-
---ANOTHER
-Content-Type: text/plain; charset="iso-8859-3"
-
---ANOTHER--
-
---BOUNDARY
-Content-Type: text/plain; charset="us-ascii"
-
-
---BOUNDARY
-Content-Type: text/plain; charset="koi8-r"
-
-
---BOUNDARY--
diff --git a/Lib/email/test/data/msg_12a.txt b/Lib/email/test/data/msg_12a.txt
deleted file mode 100644
index e94224e..0000000
--- a/Lib/email/test/data/msg_12a.txt
+++ /dev/null
@@ -1,38 +0,0 @@
-MIME-Version: 1.0
-From: Barry Warsaw <barry@zope.com>
-To: Dingus Lovers <cravindogs@cravindogs.com>
-Subject: Lyrics
-Date: Fri, 20 Apr 2001 19:35:02 -0400
-Content-Type: multipart/mixed; boundary="BOUNDARY"
-
---BOUNDARY
-Content-Type: text/plain; charset="us-ascii"
-
-
---BOUNDARY
-Content-Type: text/html; charset="iso-8859-1"
-
-
---BOUNDARY
-Content-Type: multipart/mixed; boundary="ANOTHER"
-
---ANOTHER
-Content-Type: text/plain; charset="iso-8859-2"
-
-
---ANOTHER
-Content-Type: text/plain; charset="iso-8859-3"
-
-
---ANOTHER--
-
-
---BOUNDARY
-Content-Type: text/plain; charset="us-ascii"
-
-
---BOUNDARY
-Content-Type: text/plain; charset="koi8-r"
-
-
---BOUNDARY--
diff --git a/Lib/email/test/data/msg_13.txt b/Lib/email/test/data/msg_13.txt
deleted file mode 100644
index 8e6d52d..0000000
--- a/Lib/email/test/data/msg_13.txt
+++ /dev/null
@@ -1,94 +0,0 @@
-MIME-Version: 1.0
-From: Barry <barry@digicool.com>
-To: Dingus Lovers <cravindogs@cravindogs.com>
-Subject: Here is your dingus fish
-Date: Fri, 20 Apr 2001 19:35:02 -0400
-Content-Type: multipart/mixed; boundary="OUTER"
-
---OUTER
-Content-Type: text/plain; charset="us-ascii"
-
-A text/plain part
-
---OUTER
-Content-Type: multipart/mixed; boundary=BOUNDARY
-
-
---BOUNDARY
-Content-Type: text/plain; charset="us-ascii"
-
-Hi there,
-
-This is the dingus fish.
-
---BOUNDARY
-Content-Type: image/gif; name="dingusfish.gif"
-Content-Transfer-Encoding: base64
-content-disposition: attachment; filename="dingusfish.gif"
-
-R0lGODdhAAEAAfAAAP///wAAACwAAAAAAAEAAQAC/oSPqcvtD6OctNqLs968+w+G4kiW5omm6sq2
-7gvH8kzX9o3n+s73/g8MCofEovGITGICTKbyCV0FDNOo9SqpQqpOrJfXzTQj2vD3TGtqL+NtGQ2f
-qTXmxzuOd7WXdcc9DyjU53ewFni4s0fGhdiYaEhGBelICTNoV1j5NUnFcrmUqemjNifJVWpaOqaI
-oFq3SspZsSraE7sHq3jr1MZqWvi662vxV4tD+pvKW6aLDOCLyur8PDwbanyDeq0N3DctbQYeLDvR
-RY6t95m6UB0d3mwIrV7e2VGNvjjffukeJp4w7F65KecGFsTHQGAygOrgrWs1jt28Rc88KESYcGLA
-/obvTkH6p+CinWJiJmIMqXGQwH/y4qk0SYjgQTczT3ajKZGfuI0uJ4kkVI/DT5s3/ejkxI0aT4Y+
-YTYgWbImUaXk9nlLmnSh1qJiJFl0OpUqRK4oOy7NyRQtHWofhoYVxkwWXKUSn0YsS+fUV6lhqfYb
-6ayd3Z5qQdG1B7bvQzaJjwUV2lixMUZ7JVsOlfjWVr/3NB/uFvnySBN6Dcb6rGwaRM3wsormw5cC
-M9NxWy/bWdufudCvy8bOAjXjVVwta/uO21sE5RHBCzNFXtgq9ORtH4eYjVP4Yryo026nvkFmCeyA
-B29efV6ravCMK5JwWd5897Qrx7ll38o6iHDZ/rXPR//feevhF4l7wjUGX3xq1eeRfM4RSJGBIV1D
-z1gKPkfWag3mVBVvva1RlX5bAJTPR/2YqNtw/FkIYYEi/pIZiAdpcxpoHtmnYYoZtvhUftzdx5ZX
-JSKDW405zkGcZzzGZ6KEv4FI224oDmijlEf+xp6MJK5ojY/ASeVUR+wsKRuJ+XFZ5o7ZeEime8t1
-ouUsU6YjF5ZtUihhkGfCdFQLWQFJ3UXxmElfhQnR+eCdcDbkFZp6vTRmj56ApCihn5QGpaToNZmR
-n3NVSpZcQpZ2KEONusaiCsKAug0wkQbJSFO+PTSjneGxOuFjPlUk3ovWvdIerjUg9ZGIOtGq/qeX
-eCYrrCX+1UPsgTKGGRSbzd5q156d/gpfbJxe66eD5iQKrXj7RGgruGxs62qebBHUKS32CKluCiqZ
-qh+pmehmEb71noAUoe5e9Zm17S7773V10pjrtG4CmuurCV/n6zLK5turWNhqOvFXbjhZrMD0YhKe
-wR0zOyuvsh6MWrGoIuzvyWu5y1WIFAqmJselypxXh6dKLNOKEB98L88bS2rkNqqlKzCNJp9c0G0j
-Gzh0iRrCbHSXmPR643QS+4rWhgFmnSbSuXCjS0xAOWkU2UdLqyuUNfHSFdUouy3bm5i5GnDM3tG8
-doJ4r5tqu3pPbRSVfvs8uJzeNXhp3n4j/tZ42SwH7eaWUUOjc3qFV9453UHTXZfcLH+OeNs5g36x
-lBnHvTm7EbMbLeuaLncao8vWCXimfo1o+843Ak6y4ChNeGntvAYvfLK4ezmoyNIbNCLTCXO9ZV3A
-E8/s88RczPzDwI4Ob7XZyl7+9Miban29h+tJZPrE21wgvBphDfrrfPdCTPKJD/y98L1rZwHcV6Jq
-Zab0metpuNIX/qAFPoz171WUaUb4HAhBSzHuHfjzHb3kha/2Cctis/ORArVHNYfFyYRH2pYIRzic
-isVOfPWD1b6mRTqpCRBozzof6UZVvFXRxWIr3GGrEviGYgyPMfahheiSaLs/9QeFu7oZ/ndSY8DD
-ya9x+uPed+7mxN2IzIISBOMLFYWVqC3Pew1T2nFuuCiwZS5/v6II10i4t1OJcUH2U9zxKodHsGGv
-Oa+zkvNUYUOa/TCCRutF9MzDwdlUMJADTCGSbDQ5OV4PTamDoPEi6Ecc/RF5RWwkcdSXvSOaDWSn
-I9LlvubFTQpuc6JKXLcKeb+xdbKRBnwREemXyjg6ME65aJiOuBgrktzykfPLJBKR9ClMavJ62/Ff
-BlNIyod9yX9wcSXexnXFpvkrbXk64xsx5Db7wXKP5fSgsvwIMM/9631VLBfkmtbHRXpqmtei52hG
-pUwSlo+BASQoeILDOBgREECxBBh5/iYmNsQ9dIv5+OI++QkqdsJPc3uykz5fkM+OraeekcQF7X4n
-B5S67za5U967PmooGQhUXfF7afXyCD7ONdRe17QogYjVx38uLwtrS6nhTnm15LQUnu9E2uK6CNI/
-1HOABj0ESwOjut4FEpFQpdNAm4K2LHnDWHNcmKB2ioKBogysVZtMO2nSxUdZ8Yk2kJc7URioLVI0
-YgmtIwZj4LoeKemgnOnbUdGnzZ4Oa6scqiolBGqS6RgWNLu0RMhcaE6rhhU4hiuqFXPAG8fGwTPW
-FKeLMtdVmXLSs5YJGF/YeVm7rREMlY3UYE+yCxbaMXX8y15m5zVHq6GOKDMynzII/jdUHdyVqIy0
-ifX2+r/EgtZcvRzSb72gU9ui87M2VecjKildW/aFqaYhKoryUjfB/g4qtyVuc60xFDGmCxwjW+qu
-zjuwl2GkOWn66+3QiiEctvd04OVvcCVzjgT7lrkvjVGKKHmmlDUKowSeikb5kK/mJReuWOxONx+s
-ULsl+Lqb0CVn0SrVyJ6wt4t6yTeSCafhPhAf0OXn6L60UMxiLolFAtmN35S2Ob1lZpQ1r/n0Qb5D
-oQ1zJiRVDgF8N3Q8TYfbi3DyWCy3lT1nxyBs6FT3S2GOzWRlxwKvlRP0RPJA9SjxEy0UoEnkA+M4
-cnzLMJrBGWLFEaaUb5lvpqbq/loOaU5+DFuHPxo82/OZuM8FXG3oVNZhtWpMpb/0Xu5m/LfLhHZQ
-7yuVI0MqZ7NE43imC8jH3IwGZlbPm0xkJYs7+2U48hXTsFSMqgGDvai0kLxyynKNT/waj+q1c1tz
-GjOpPBgdCSq3UKZxCSsqFIY+O6JbAWGWcV1pwqLyj5sGqCF1xb1F3varUWqrJv6cN3PrUXzijtfZ
-FshpBL3Xwr4GIPvU2N8EjrJgS1zl21rbXQMXeXc5jjFyrhpCzijSv/RQtyPSzHCFMhlME95fHglt
-pRsX+dfSQjUeHAlpWzJ5iOo79Ldnaxai6bXTcGO3fp07ri7HLEmXXPlYi8bv/qVxvNcdra6m7Rlb
-6JBTb5fd66VhFRjGArh2n7R1rDW4P5NOT9K0I183T2scYkeZ3q/VFyLb09U9ajzXBS8Kgkhc4mBS
-kYY9cy3Vy9lUnuNJH8HGIclUilwnBtjUOH0gteGOZ4c/XNrhXLSYDyxfnD8z1pDy7rYRvDolhnbe
-UMzxCZUs40s6s7UIvBnLgc0+vKuOkIXeOrDymlp+Zxra4MZLBbVrqD/jTJ597pDmnw5c4+DbyB88
-9Cg9DodYcSuMZT/114pptqc/EuTjRPvH/z5slzI3tluOEBBLqOXLOX+0I5929tO97wkvl/atCz+y
-xJrdwteW2FNW/NSmBP+f/maYtVs/bYyBC7Ox3jsYZHL05CIrBa/nS+b3bHfiYm4Ueil1YZZSgAUI
-fFZ1dxUmeA2oQRQ3RuGXNGLFV9/XbGFGPV6kfzk1TBBCd+izc7q1H+OHMJwmaBX2IQNYVAKHYepV
-SSGCe6CnbYHHETKGNe43EDvFgZr0gB/nVHPHZ80VV1ojOiI3XDvYIkl4ayo4bxQIgrFXWTvBI0nH
-VElWMuw2aLUWCRHHf8ymVCHjFlJnOSojfevCYyyyZDH0IcvHhrsnQ5O1OsWzONuVVKIxSxiFZ/tR
-fKDAf6xFTnw4O9Qig2VCfW2hJQrmMOuHW0W3dLQmCMO2ccdUd/xyfflH/olTiHZVdGwb8nIwRzSE
-J15jFlOJuBZBZ4CiyHyd2IFylFlB+HgHhYabhWOGwYO1ZH/Og1dtQlFMk352CGRSIFTapnWQEUtN
-l4zv8S0aaCFDyGCBqDUxZYpxGHX01y/JuH1xhn7TOCnNCI4eKDs5WGX4R425F4vF1o3BJ4vO0otq
-I3rimI7jJY1jISqnBxknCIvruF83mF5wN4X7qGLIhR8A2Vg0yFERSIXn9Vv3GHy3Vj/WIkKddlYi
-yIMv2I/VMjTLpW7pt05SWIZR0RPyxpB4SIUM9lBPGBl0GC7oSEEwRYLe4pJpZY2P0zbI1n+Oc44w
-qY3PUnmF0ixjVpDD/mJ9wpOBGTVgXlaCaZiPcIWK5NiKBIiPdGaQ0TWGvAiG7nMchdZb7Vgf8zNi
-MuMyzRdy/lePe9iC4TRx7WhhOQI/QiSVNAmAa2lT/piFbuh7ofJoYSZzrSZ1bvmWw3eN2nKUPVky
-uPN5/VRfohRd0VYZoqhKIlU6TXYhJxmPUIloAwc1bPmHEpaZYZORHNlXUJM07hATwHR8MJYqkwWR
-WaIezFhxSFlc8/Fq82hEnpeRozg3ULhhr9lAGtVEkCg5ZNRuuVleBPaZadhG0ZgkyPmDOTOKzViM
-YgOcpukKqQcbjAWS0IleQ2ROjdh6A+md1qWdBRSX7iSYgFRTtRmBpJioieXJiHfJiMGIR9fJOn8I
-MSfXYhspn4ooSa2mSAj4n+8Bmg03fBJZoPOJgsVZRxu1oOMRPXYYjdqjihFaEoZpXBREanuJoRI6
-cibFinq4ngUKh/wQd/H5ofYCZ0HJXR62opZFaAT0iFIZo4DIiUojkjeqKiuoZirKo5Y1a7AWckGa
-BkuYoD5lpDK6eUs6CkDqpETwl1EqpfhJpVeKpVl6EgUAADs=
-
---BOUNDARY--
-
---OUTER--
diff --git a/Lib/email/test/data/msg_14.txt b/Lib/email/test/data/msg_14.txt
deleted file mode 100644
index 5d98d2f..0000000
--- a/Lib/email/test/data/msg_14.txt
+++ /dev/null
@@ -1,23 +0,0 @@
-Return-Path: <bbb@zzz.org>
-Delivered-To: bbb@zzz.org
-Received: by mail.zzz.org (Postfix, from userid 889)
- id 27CEAD38CC; Fri, 4 May 2001 14:05:44 -0400 (EDT)
-MIME-Version: 1.0
-Content-Type: text; charset=us-ascii
-Content-Transfer-Encoding: 7bit
-Message-ID: <15090.61304.110929.45684@aaa.zzz.org>
-From: bbb@ddd.com (John X. Doe)
-To: bbb@zzz.org
-Subject: This is a test message
-Date: Fri, 4 May 2001 14:05:44 -0400
-
-
-Hi,
-
-I'm sorry but I'm using a drainbread ISP, which although big and
-wealthy can't seem to generate standard compliant email. :(
-
-This message has a Content-Type: header with no subtype. I hope you
-can still read it.
-
--Me
diff --git a/Lib/email/test/data/msg_15.txt b/Lib/email/test/data/msg_15.txt
deleted file mode 100644
index 33b8487..0000000
--- a/Lib/email/test/data/msg_15.txt
+++ /dev/null
@@ -1,52 +0,0 @@
-Return-Path: <xx@xx.dk>
-Received: from fepD.post.tele.dk (195.41.46.149) by mail.groupcare.dk (LSMTP for Windows NT v1.1b) with SMTP id <0.0014F8A2@mail.groupcare.dk>; Mon, 30 Apr 2001 12:17:50 +0200
-User-Agent: Microsoft-Outlook-Express-Macintosh-Edition/5.02.2106
-Subject: XX
-From: xx@xx.dk
-To: XX
-Message-ID: <xxxx>
-Mime-version: 1.0
-Content-type: multipart/mixed;
- boundary="MS_Mac_OE_3071477847_720252_MIME_Part"
-
-> Denne meddelelse er i MIME-format. Da dit postl¾sningsprogram ikke forstŒr dette format, kan del af eller hele meddelelsen v¾re ul¾selig.
-
---MS_Mac_OE_3071477847_720252_MIME_Part
-Content-type: multipart/alternative;
- boundary="MS_Mac_OE_3071477847_720252_MIME_Part"
-
-
---MS_Mac_OE_3071477847_720252_MIME_Part
-Content-type: text/plain; charset="ISO-8859-1"
-Content-transfer-encoding: quoted-printable
-
-Some removed test.
-
---MS_Mac_OE_3071477847_720252_MIME_Part
-Content-type: text/html; charset="ISO-8859-1"
-Content-transfer-encoding: quoted-printable
-
-<HTML>
-<HEAD>
-<TITLE>Some removed HTML</TITLE>
-</HEAD>
-<BODY>
-Some removed text.
-</BODY>
-</HTML>
-
-
---MS_Mac_OE_3071477847_720252_MIME_Part--
-
-
---MS_Mac_OE_3071477847_720252_MIME_Part
-Content-type: image/gif; name="xx.gif";
- x-mac-creator="6F676C65";
- x-mac-type="47494666"
-Content-disposition: attachment
-Content-transfer-encoding: base64
-
-Some removed base64 encoded chars.
-
---MS_Mac_OE_3071477847_720252_MIME_Part--
-
diff --git a/Lib/email/test/data/msg_16.txt b/Lib/email/test/data/msg_16.txt
deleted file mode 100644
index 56167e9..0000000
--- a/Lib/email/test/data/msg_16.txt
+++ /dev/null
@@ -1,123 +0,0 @@
-Return-Path: <>
-Delivered-To: scr-admin@socal-raves.org
-Received: from cougar.noc.ucla.edu (cougar.noc.ucla.edu [169.232.10.18])
- by babylon.socal-raves.org (Postfix) with ESMTP id CCC2C51B84
- for <scr-admin@socal-raves.org>; Sun, 23 Sep 2001 20:13:54 -0700 (PDT)
-Received: from sims-ms-daemon by cougar.noc.ucla.edu
- (Sun Internet Mail Server sims.3.5.2000.03.23.18.03.p10)
- id <0GK500B01D0B8Y@cougar.noc.ucla.edu> for scr-admin@socal-raves.org; Sun,
- 23 Sep 2001 20:14:35 -0700 (PDT)
-Received: from cougar.noc.ucla.edu
- (Sun Internet Mail Server sims.3.5.2000.03.23.18.03.p10)
- id <0GK500B01D0B8X@cougar.noc.ucla.edu>; Sun, 23 Sep 2001 20:14:35 -0700 (PDT)
-Date: Sun, 23 Sep 2001 20:14:35 -0700 (PDT)
-From: Internet Mail Delivery <postmaster@ucla.edu>
-Subject: Delivery Notification: Delivery has failed
-To: scr-admin@socal-raves.org
-Message-id: <0GK500B04D0B8X@cougar.noc.ucla.edu>
-MIME-version: 1.0
-Sender: scr-owner@socal-raves.org
-Errors-To: scr-owner@socal-raves.org
-X-BeenThere: scr@socal-raves.org
-X-Mailman-Version: 2.1a3
-Precedence: bulk
-List-Help: <mailto:scr-request@socal-raves.org?subject=help>
-List-Post: <mailto:scr@socal-raves.org>
-List-Subscribe: <http://socal-raves.org/mailman/listinfo/scr>,
- <mailto:scr-request@socal-raves.org?subject=subscribe>
-List-Id: SoCal-Raves <scr.socal-raves.org>
-List-Unsubscribe: <http://socal-raves.org/mailman/listinfo/scr>,
- <mailto:scr-request@socal-raves.org?subject=unsubscribe>
-List-Archive: <http://socal-raves.org/mailman/private/scr/>
-Content-Type: multipart/report; boundary="Boundary_(ID_PGS2F2a+z+/jL7hupKgRhA)"
-
-
---Boundary_(ID_PGS2F2a+z+/jL7hupKgRhA)
-Content-type: text/plain; charset=ISO-8859-1
-
-This report relates to a message you sent with the following header fields:
-
- Message-id: <002001c144a6$8752e060$56104586@oxy.edu>
- Date: Sun, 23 Sep 2001 20:10:55 -0700
- From: "Ian T. Henry" <henryi@oxy.edu>
- To: SoCal Raves <scr@socal-raves.org>
- Subject: [scr] yeah for Ians!!
-
-Your message cannot be delivered to the following recipients:
-
- Recipient address: jangel1@cougar.noc.ucla.edu
- Reason: recipient reached disk quota
-
-
---Boundary_(ID_PGS2F2a+z+/jL7hupKgRhA)
-Content-type: message/DELIVERY-STATUS
-
-Original-envelope-id: 0GK500B4HD0888@cougar.noc.ucla.edu
-Reporting-MTA: dns; cougar.noc.ucla.edu
-
-Action: failed
-Status: 5.0.0 (recipient reached disk quota)
-Original-recipient: rfc822;jangel1@cougar.noc.ucla.edu
-Final-recipient: rfc822;jangel1@cougar.noc.ucla.edu
-
---Boundary_(ID_PGS2F2a+z+/jL7hupKgRhA)
-Content-type: MESSAGE/RFC822
-
-Return-path: scr-admin@socal-raves.org
-Received: from sims-ms-daemon by cougar.noc.ucla.edu
- (Sun Internet Mail Server sims.3.5.2000.03.23.18.03.p10)
- id <0GK500B01D0B8X@cougar.noc.ucla.edu>; Sun, 23 Sep 2001 20:14:35 -0700 (PDT)
-Received: from panther.noc.ucla.edu by cougar.noc.ucla.edu
- (Sun Internet Mail Server sims.3.5.2000.03.23.18.03.p10)
- with ESMTP id <0GK500B4GD0888@cougar.noc.ucla.edu> for jangel1@sims-ms-daemon;
- Sun, 23 Sep 2001 20:14:33 -0700 (PDT)
-Received: from babylon.socal-raves.org
- (ip-209-85-222-117.dreamhost.com [209.85.222.117])
- by panther.noc.ucla.edu (8.9.1a/8.9.1) with ESMTP id UAA09793 for
- <jangel1@ucla.edu>; Sun, 23 Sep 2001 20:14:32 -0700 (PDT)
-Received: from babylon (localhost [127.0.0.1]) by babylon.socal-raves.org
- (Postfix) with ESMTP id D3B2951B70; Sun, 23 Sep 2001 20:13:47 -0700 (PDT)
-Received: by babylon.socal-raves.org (Postfix, from userid 60001)
- id A611F51B82; Sun, 23 Sep 2001 20:13:46 -0700 (PDT)
-Received: from tiger.cc.oxy.edu (tiger.cc.oxy.edu [134.69.3.112])
- by babylon.socal-raves.org (Postfix) with ESMTP id ADA7351B70 for
- <scr@socal-raves.org>; Sun, 23 Sep 2001 20:13:44 -0700 (PDT)
-Received: from ent (n16h86.dhcp.oxy.edu [134.69.16.86])
- by tiger.cc.oxy.edu (8.8.8/8.8.8) with SMTP id UAA08100 for
- <scr@socal-raves.org>; Sun, 23 Sep 2001 20:14:24 -0700 (PDT)
-Date: Sun, 23 Sep 2001 20:10:55 -0700
-From: "Ian T. Henry" <henryi@oxy.edu>
-Subject: [scr] yeah for Ians!!
-Sender: scr-admin@socal-raves.org
-To: SoCal Raves <scr@socal-raves.org>
-Errors-to: scr-admin@socal-raves.org
-Message-id: <002001c144a6$8752e060$56104586@oxy.edu>
-MIME-version: 1.0
-X-Mailer: Microsoft Outlook Express 5.50.4522.1200
-Content-type: text/plain; charset=us-ascii
-Precedence: bulk
-Delivered-to: scr-post@babylon.socal-raves.org
-Delivered-to: scr@socal-raves.org
-X-Converted-To-Plain-Text: from multipart/alternative by demime 0.98e
-X-Converted-To-Plain-Text: Alternative section used was text/plain
-X-BeenThere: scr@socal-raves.org
-X-Mailman-Version: 2.1a3
-List-Help: <mailto:scr-request@socal-raves.org?subject=help>
-List-Post: <mailto:scr@socal-raves.org>
-List-Subscribe: <http://socal-raves.org/mailman/listinfo/scr>,
- <mailto:scr-request@socal-raves.org?subject=subscribe>
-List-Id: SoCal-Raves <scr.socal-raves.org>
-List-Unsubscribe: <http://socal-raves.org/mailman/listinfo/scr>,
- <mailto:scr-request@socal-raves.org?subject=unsubscribe>
-List-Archive: <http://socal-raves.org/mailman/private/scr/>
-
-I always love to find more Ian's that are over 3 years old!!
-
-Ian
-_______________________________________________
-For event info, list questions, or to unsubscribe, see http://www.socal-raves.org/
-
-
-
---Boundary_(ID_PGS2F2a+z+/jL7hupKgRhA)--
-
diff --git a/Lib/email/test/data/msg_17.txt b/Lib/email/test/data/msg_17.txt
deleted file mode 100644
index 8d86e41..0000000
--- a/Lib/email/test/data/msg_17.txt
+++ /dev/null
@@ -1,12 +0,0 @@
-MIME-Version: 1.0
-From: Barry <barry@digicool.com>
-To: Dingus Lovers <cravindogs@cravindogs.com>
-Subject: Here is your dingus fish
-Date: Fri, 20 Apr 2001 19:35:02 -0400
-Content-Type: multipart/mixed; boundary="BOUNDARY"
-
-Hi there,
-
-This is the dingus fish.
-
-[Non-text (image/gif) part of message omitted, filename dingusfish.gif]
diff --git a/Lib/email/test/data/msg_18.txt b/Lib/email/test/data/msg_18.txt
deleted file mode 100644
index f9f4904..0000000
--- a/Lib/email/test/data/msg_18.txt
+++ /dev/null
@@ -1,6 +0,0 @@
-Content-Type: text/plain; charset="us-ascii"
-MIME-Version: 1.0
-Content-Transfer-Encoding: 7bit
-X-Foobar-Spoink-Defrobnit: wasnipoop; giraffes="very-long-necked-animals";
- spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"
-
diff --git a/Lib/email/test/data/msg_19.txt b/Lib/email/test/data/msg_19.txt
deleted file mode 100644
index 49bf7fc..0000000
--- a/Lib/email/test/data/msg_19.txt
+++ /dev/null
@@ -1,43 +0,0 @@
-Send Ppp mailing list submissions to
- ppp@zzz.org
-
-To subscribe or unsubscribe via the World Wide Web, visit
- http://www.zzz.org/mailman/listinfo/ppp
-or, via email, send a message with subject or body 'help' to
- ppp-request@zzz.org
-
-You can reach the person managing the list at
- ppp-admin@zzz.org
-
-When replying, please edit your Subject line so it is more specific
-than "Re: Contents of Ppp digest..."
-
-Today's Topics:
-
- 1. testing #1 (Barry A. Warsaw)
- 2. testing #2 (Barry A. Warsaw)
- 3. testing #3 (Barry A. Warsaw)
- 4. testing #4 (Barry A. Warsaw)
- 5. testing #5 (Barry A. Warsaw)
-
-hello
-
-
-hello
-
-
-hello
-
-
-hello
-
-
-hello
-
-
-
-_______________________________________________
-Ppp mailing list
-Ppp@zzz.org
-http://www.zzz.org/mailman/listinfo/ppp
-
diff --git a/Lib/email/test/data/msg_20.txt b/Lib/email/test/data/msg_20.txt
deleted file mode 100644
index 1a6a887..0000000
--- a/Lib/email/test/data/msg_20.txt
+++ /dev/null
@@ -1,22 +0,0 @@
-Return-Path: <bbb@zzz.org>
-Delivered-To: bbb@zzz.org
-Received: by mail.zzz.org (Postfix, from userid 889)
- id 27CEAD38CC; Fri, 4 May 2001 14:05:44 -0400 (EDT)
-MIME-Version: 1.0
-Content-Type: text/plain; charset=us-ascii
-Content-Transfer-Encoding: 7bit
-Message-ID: <15090.61304.110929.45684@aaa.zzz.org>
-From: bbb@ddd.com (John X. Doe)
-To: bbb@zzz.org
-Cc: ccc@zzz.org
-CC: ddd@zzz.org
-cc: eee@zzz.org
-Subject: This is a test message
-Date: Fri, 4 May 2001 14:05:44 -0400
-
-
-Hi,
-
-Do you like this message?
-
--Me
diff --git a/Lib/email/test/data/msg_21.txt b/Lib/email/test/data/msg_21.txt
deleted file mode 100644
index 23590b2..0000000
--- a/Lib/email/test/data/msg_21.txt
+++ /dev/null
@@ -1,20 +0,0 @@
-From: aperson@dom.ain
-To: bperson@dom.ain
-Subject: Test
-Content-Type: multipart/mixed; boundary="BOUNDARY"
-
-MIME message
---BOUNDARY
-Content-Type: text/plain; charset="us-ascii"
-MIME-Version: 1.0
-Content-Transfer-Encoding: 7bit
-
-One
---BOUNDARY
-Content-Type: text/plain; charset="us-ascii"
-MIME-Version: 1.0
-Content-Transfer-Encoding: 7bit
-
-Two
---BOUNDARY--
-End of MIME message
diff --git a/Lib/email/test/data/msg_22.txt b/Lib/email/test/data/msg_22.txt
deleted file mode 100644
index af9de5f..0000000
--- a/Lib/email/test/data/msg_22.txt
+++ /dev/null
@@ -1,46 +0,0 @@
-Mime-Version: 1.0
-Message-Id: <a05001902b7f1c33773e9@[134.84.183.138]>
-Date: Tue, 16 Oct 2001 13:59:25 +0300
-To: a@example.com
-From: b@example.com
-Content-Type: multipart/mixed; boundary="============_-1208892523==_============"
-
---============_-1208892523==_============
-Content-Type: text/plain; charset="us-ascii" ; format="flowed"
-
-Text text text.
---============_-1208892523==_============
-Content-Id: <a05001902b7f1c33773e9@[134.84.183.138].0.0>
-Content-Type: image/jpeg; name="wibble.JPG"
- ; x-mac-type="4A504547"
- ; x-mac-creator="474B4F4E"
-Content-Disposition: attachment; filename="wibble.JPG"
-Content-Transfer-Encoding: base64
-
-/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB
-AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/wAALCAXABIEBAREA
-g6bCjjw/pIZSjO6FWFpldjySOmCNrO7DBZibUXhTwtCixw+GtAijVdqxxaPp0aKvmGXa
-qrbBQvms0mAMeYS/3iTV1dG0hHaRNK01XblnWxtVdjkHLMIgTyqnk9VB7CrP2KzIINpa
-4O7I+zxYO9WV8jZg71Zlb+8rMDkEirAVQFAUAKAFAAAUAYAUDgADgY6DjpRtXj5RxjHA
-4wQRj0wQCMdCAewpaKKK/9k=
---============_-1208892523==_============
-Content-Id: <a05001902b7f1c33773e9@[134.84.183.138].0.1>
-Content-Type: image/jpeg; name="wibble2.JPG"
- ; x-mac-type="4A504547"
- ; x-mac-creator="474B4F4E"
-Content-Disposition: attachment; filename="wibble2.JPG"
-Content-Transfer-Encoding: base64
-
-/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB
-AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/wAALCAXABJ0BAREA
-/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQA
-W6NFJJBEkU10kKGTcWMDwxuU+0JHvk8qAtOpNwqSR0n8c3BlDyXHlqsUltHEiTvdXLxR
-7vMiGDNJAJWkAMk8ZkCFp5G2oo5W++INrbQtNfTQxJAuXlupz9oS4d5Y1W+E2XlWZJJE
-Y7LWYQxTLE1zuMbfBPxw8X2fibVdIbSbI6nLZxX635t9TjtYreWR7WGKJTLJFFKSlozO
-0ShxIXM43uC3/9k=
---============_-1208892523==_============
-Content-Type: text/plain; charset="us-ascii" ; format="flowed"
-
-Text text text.
---============_-1208892523==_============--
-
diff --git a/Lib/email/test/data/msg_23.txt b/Lib/email/test/data/msg_23.txt
deleted file mode 100644
index bb2e8ec..0000000
--- a/Lib/email/test/data/msg_23.txt
+++ /dev/null
@@ -1,8 +0,0 @@
-From: aperson@dom.ain
-Content-Type: multipart/mixed; boundary="BOUNDARY"
-
---BOUNDARY
-Content-Type: text/plain
-
-A message part
---BOUNDARY--
diff --git a/Lib/email/test/data/msg_24.txt b/Lib/email/test/data/msg_24.txt
deleted file mode 100644
index 4e52339..0000000
--- a/Lib/email/test/data/msg_24.txt
+++ /dev/null
@@ -1,10 +0,0 @@
-Content-Type: multipart/mixed; boundary="BOUNDARY"
-MIME-Version: 1.0
-Subject: A subject
-To: aperson@dom.ain
-From: bperson@dom.ain
-
---BOUNDARY
-
-
---BOUNDARY--
diff --git a/Lib/email/test/data/msg_25.txt b/Lib/email/test/data/msg_25.txt
deleted file mode 100644
index 9e35275..0000000
--- a/Lib/email/test/data/msg_25.txt
+++ /dev/null
@@ -1,117 +0,0 @@
-From MAILER-DAEMON Fri Apr 06 16:46:09 2001
-Received: from [204.245.199.98] (helo=zinfandel.lacita.com)
- by www.linux.org.uk with esmtp (Exim 3.13 #1)
- id 14lYR6-0008Iv-00
- for linuxuser-admin@www.linux.org.uk; Fri, 06 Apr 2001 16:46:09 +0100
-Received: from localhost (localhost) by zinfandel.lacita.com (8.7.3/8.6.10-MT4.00) with internal id JAB03225; Fri, 6 Apr 2001 09:23:06 -0800 (GMT-0800)
-Date: Fri, 6 Apr 2001 09:23:06 -0800 (GMT-0800)
-From: Mail Delivery Subsystem <MAILER-DAEMON@zinfandel.lacita.com>
-Subject: Returned mail: Too many hops 19 (17 max): from <linuxuser-admin@www.linux.org.uk> via [199.164.235.226], to <scoffman@wellpartner.com>
-Message-Id: <200104061723.JAB03225@zinfandel.lacita.com>
-To: <linuxuser-admin@www.linux.org.uk>
-To: postmaster@zinfandel.lacita.com
-MIME-Version: 1.0
-Content-Type: multipart/report; report-type=delivery-status;
- bo
-Auto-Submitted: auto-generated (failure)
-
-This is a MIME-encapsulated message
-
---JAB03225.986577786/zinfandel.lacita.com
-
-The original message was received at Fri, 6 Apr 2001 09:23:03 -0800 (GMT-0800)
-from [199.164.235.226]
-
- ----- The following addresses have delivery notifications -----
-<scoffman@wellpartner.com> (unrecoverable error)
-
- ----- Transcript of session follows -----
-554 Too many hops 19 (17 max): from <linuxuser-admin@www.linux.org.uk> via [199.164.235.226], to <scoffman@wellpartner.com>
-
---JAB03225.986577786/zinfandel.lacita.com
-Content-Type: message/delivery-status
-
-Reporting-MTA: dns; zinfandel.lacita.com
-Received-From-MTA: dns; [199.164.235.226]
-Arrival-Date: Fri, 6 Apr 2001 09:23:03 -0800 (GMT-0800)
-
-Final-Recipient: rfc822; scoffman@wellpartner.com
-Action: failed
-Status: 5.4.6
-Last-Attempt-Date: Fri, 6 Apr 2001 09:23:06 -0800 (GMT-0800)
-
---JAB03225.986577786/zinfandel.lacita.com
-Content-Type: text/rfc822-headers
-
-Return-Path: linuxuser-admin@www.linux.org.uk
-Received: from ns1.wellpartner.net ([199.164.235.226]) by zinfandel.lacita.com (8.7.3/8.6.10-MT4.00) with ESMTP id JAA03225 for <scoffman@wellpartner.com>; Fri, 6 Apr 2001 09:23:03 -0800 (GMT-0800)
-Received: from zinfandel.lacita.com ([204.245.199.98])
- by
- fo
-Received: from ns1.wellpartner.net ([199.164.235.226]) by zinfandel.lacita.com (8.7.3/8.6.10-MT4.00) with ESMTP id JAA03221 for <scoffman@wellpartner.com>; Fri, 6 Apr 2001 09:22:18 -0800 (GMT-0800)
-Received: from zinfandel.lacita.com ([204.245.199.98])
- by
- fo
-Received: from ns1.wellpartner.net ([199.164.235.226]) by zinfandel.lacita.com (8.7.3/8.6.10-MT4.00) with ESMTP id JAA03217 for <scoffman@wellpartner.com>; Fri, 6 Apr 2001 09:21:37 -0800 (GMT-0800)
-Received: from zinfandel.lacita.com ([204.245.199.98])
- by
- fo
-Received: from ns1.wellpartner.net ([199.164.235.226]) by zinfandel.lacita.com (8.7.3/8.6.10-MT4.00) with ESMTP id JAA03213 for <scoffman@wellpartner.com>; Fri, 6 Apr 2001 09:20:56 -0800 (GMT-0800)
-Received: from zinfandel.lacita.com ([204.245.199.98])
- by
- fo
-Received: from ns1.wellpartner.net ([199.164.235.226]) by zinfandel.lacita.com (8.7.3/8.6.10-MT4.00) with ESMTP id JAA03209 for <scoffman@wellpartner.com>; Fri, 6 Apr 2001 09:20:15 -0800 (GMT-0800)
-Received: from zinfandel.lacita.com ([204.245.199.98])
- by
- fo
-Received: from ns1.wellpartner.net ([199.164.235.226]) by zinfandel.lacita.com (8.7.3/8.6.10-MT4.00) with ESMTP id JAA03205 for <scoffman@wellpartner.com>; Fri, 6 Apr 2001 09:19:33 -0800 (GMT-0800)
-Received: from zinfandel.lacita.com ([204.245.199.98])
- by
- fo
-Received: from ns1.wellpartner.net ([199.164.235.226]) by zinfandel.lacita.com (8.7.3/8.6.10-MT4.00) with ESMTP id JAA03201 for <scoffman@wellpartner.com>; Fri, 6 Apr 2001 09:18:52 -0800 (GMT-0800)
-Received: from zinfandel.lacita.com ([204.245.199.98])
- by
- fo
-Received: from ns1.wellpartner.net ([199.164.235.226]) by zinfandel.lacita.com (8.7.3/8.6.10-MT4.00) with ESMTP id JAA03197 for <scoffman@wellpartner.com>; Fri, 6 Apr 2001 09:17:54 -0800 (GMT-0800)
-Received: from www.linux.org.uk (parcelfarce.linux.theplanet.co.uk [195.92.249.252])
- by
- fo
-Received: from localhost.localdomain
- ([
- by
- id
-Received: from [212.1.130.11] (helo=s1.uklinux.net ident=root)
- by
- id
- fo
-Received: from server (ppp-2-22.cvx4.telinco.net [212.1.149.22])
- by
- fo
-From: Daniel James <daniel@linuxuser.co.uk>
-Organization: LinuxUser
-To: linuxuser@www.linux.org.uk
-X-Mailer: KMail [version 1.1.99]
-Content-Type: text/plain;
- c
-MIME-Version: 1.0
-Message-Id: <01040616033903.00962@server>
-Content-Transfer-Encoding: 8bit
-Subject: [LinuxUser] bulletin no. 45
-Sender: linuxuser-admin@www.linux.org.uk
-Errors-To: linuxuser-admin@www.linux.org.uk
-X-BeenThere: linuxuser@www.linux.org.uk
-X-Mailman-Version: 2.0.3
-Precedence: bulk
-List-Help: <mailto:linuxuser-request@www.linux.org.uk?subject=help>
-List-Post: <mailto:linuxuser@www.linux.org.uk>
-List-Subscribe: <http://www.linux.org.uk/mailman/listinfo/linuxuser>,
- <m
-List-Id: bulletins from LinuxUser magazine <linuxuser.www.linux.org.uk>
-List-Unsubscribe: <http://www.linux.org.uk/mailman/listinfo/linuxuser>,
- <m
-List-Archive: <http://www.linux.org.uk/pipermail/linuxuser/>
-Date: Fri, 6 Apr 2001 16:03:39 +0100
-
---JAB03225.986577786/zinfandel.lacita.com--
-
-
diff --git a/Lib/email/test/data/msg_26.txt b/Lib/email/test/data/msg_26.txt
deleted file mode 100644
index 6c71bce..0000000
--- a/Lib/email/test/data/msg_26.txt
+++ /dev/null
@@ -1,45 +0,0 @@
-Received: from xcar [192.168.0.2] by jeeves.wooster.local
- (SMTPD32-7.07 EVAL) id AFF92F0214; Sun, 12 May 2002 08:55:37 +0100
-Date: Sun, 12 May 2002 08:56:15 +0100
-From: Father Time <father.time@xcar.wooster.local>
-To: timbo@jeeves.wooster.local
-Subject: IMAP file test
-Message-ID: <6df65d354b.father.time@rpc.wooster.local>
-X-Organization: Home
-User-Agent: Messenger-Pro/2.50a (MsgServe/1.50) (RISC-OS/4.02) POPstar/2.03
-MIME-Version: 1.0
-Content-Type: multipart/mixed; boundary="1618492860--2051301190--113853680"
-Status: R
-X-UIDL: 319998302
-
-This message is in MIME format which your mailer apparently does not support.
-You either require a newer version of your software which supports MIME, or
-a separate MIME decoding utility. Alternatively, ask the sender of this
-message to resend it in a different format.
-
---1618492860--2051301190--113853680
-Content-Type: text/plain; charset=us-ascii
-
-Simple email with attachment.
-
-
---1618492860--2051301190--113853680
-Content-Type: application/riscos; name="clock.bmp,69c"; type=BMP; load=&fff69c4b; exec=&355dd4d1; access=&03
-Content-Disposition: attachment; filename="clock.bmp"
-Content-Transfer-Encoding: base64
-
-Qk12AgAAAAAAAHYAAAAoAAAAIAAAACAAAAABAAQAAAAAAAAAAADXDQAA1w0AAAAAAAAA
-AAAAAAAAAAAAiAAAiAAAAIiIAIgAAACIAIgAiIgAALu7uwCIiIgAERHdACLuIgAz//8A
-zAAAAN0R3QDu7iIA////AAAAAAAAAAAAAAAAAAAAAAAAAAi3AAAAAAAAADeAAAAAAAAA
-C3ADMzMzMANwAAAAAAAAAAAHMAAAAANwAAAAAAAAAACAMAd3zPfwAwgAAAAAAAAIAwd/
-f8x/f3AwgAAAAAAAgDB0x/f3//zPAwgAAAAAAAcHfM9////8z/AwAAAAAAiwd/f3////
-////A4AAAAAAcEx/f///////zAMAAAAAiwfM9////3///8zwOAAAAAcHf3////B/////
-8DAAAAALB/f3///wd3d3//AwAAAABwTPf//wCQAAD/zAMAAAAAsEx/f///B////8wDAA
-AAAHB39////wf/////AwAAAACwf39///8H/////wMAAAAIcHfM9///B////M8DgAAAAA
-sHTH///wf///xAMAAAAACHB3f3//8H////cDgAAAAAALB3zH//D//M9wMAAAAAAAgLB0
-z39///xHAwgAAAAAAAgLB3d3RHd3cDCAAAAAAAAAgLAHd0R3cAMIAAAAAAAAgAgLcAAA
-AAMwgAgAAAAACDAAAAu7t7cwAAgDgAAAAABzcIAAAAAAAAgDMwAAAAAAN7uwgAAAAAgH
-MzMAAAAACH97tzAAAAALu3c3gAAAAAAL+7tzDABAu7f7cAAAAAAACA+3MA7EQAv/sIAA
-AAAAAAAIAAAAAAAAAIAAAAAA
-
---1618492860--2051301190--113853680--
diff --git a/Lib/email/test/data/msg_27.txt b/Lib/email/test/data/msg_27.txt
deleted file mode 100644
index d019176..0000000
--- a/Lib/email/test/data/msg_27.txt
+++ /dev/null
@@ -1,15 +0,0 @@
-Return-Path: <aperson@dom.ain>
-Received: by mail.dom.ain (Postfix, from userid 889)
- id B9D0AD35DB; Tue, 4 Jun 2002 21:46:59 -0400 (EDT)
-Message-ID: <15613.28051.707126.569693@dom.ain>
-Date: Tue, 4 Jun 2002 21:46:59 -0400
-MIME-Version: 1.0
-Content-Type: text/plain; charset=us-ascii
-Content-Transfer-Encoding: 7bit
-Subject: bug demonstration
- 12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789
- more text
-From: aperson@dom.ain (Anne P. Erson)
-To: bperson@dom.ain (Barney P. Erson)
-
-test
diff --git a/Lib/email/test/data/msg_28.txt b/Lib/email/test/data/msg_28.txt
deleted file mode 100644
index 1e4824c..0000000
--- a/Lib/email/test/data/msg_28.txt
+++ /dev/null
@@ -1,25 +0,0 @@
-From: aperson@dom.ain
-MIME-Version: 1.0
-Content-Type: multipart/digest; boundary=BOUNDARY
-
---BOUNDARY
-Content-Type: message/rfc822
-
-Content-Type: text/plain; charset=us-ascii
-To: aa@bb.org
-From: cc@dd.org
-Subject: ee
-
-message 1
-
---BOUNDARY
-Content-Type: message/rfc822
-
-Content-Type: text/plain; charset=us-ascii
-To: aa@bb.org
-From: cc@dd.org
-Subject: ee
-
-message 2
-
---BOUNDARY--
diff --git a/Lib/email/test/data/msg_29.txt b/Lib/email/test/data/msg_29.txt
deleted file mode 100644
index 1fab561..0000000
--- a/Lib/email/test/data/msg_29.txt
+++ /dev/null
@@ -1,22 +0,0 @@
-Return-Path: <bbb@zzz.org>
-Delivered-To: bbb@zzz.org
-Received: by mail.zzz.org (Postfix, from userid 889)
- id 27CEAD38CC; Fri, 4 May 2001 14:05:44 -0400 (EDT)
-MIME-Version: 1.0
-Content-Type: text/plain; charset=us-ascii;
- title*0*="us-ascii'en'This%20is%20even%20more%20";
- title*1*="%2A%2A%2Afun%2A%2A%2A%20";
- title*2="isn't it!"
-Content-Transfer-Encoding: 7bit
-Message-ID: <15090.61304.110929.45684@aaa.zzz.org>
-From: bbb@ddd.com (John X. Doe)
-To: bbb@zzz.org
-Subject: This is a test message
-Date: Fri, 4 May 2001 14:05:44 -0400
-
-
-Hi,
-
-Do you like this message?
-
--Me
diff --git a/Lib/email/test/data/msg_30.txt b/Lib/email/test/data/msg_30.txt
deleted file mode 100644
index 4334bb6..0000000
--- a/Lib/email/test/data/msg_30.txt
+++ /dev/null
@@ -1,23 +0,0 @@
-From: aperson@dom.ain
-MIME-Version: 1.0
-Content-Type: multipart/digest; boundary=BOUNDARY
-
---BOUNDARY
-
-Content-Type: text/plain; charset=us-ascii
-To: aa@bb.org
-From: cc@dd.org
-Subject: ee
-
-message 1
-
---BOUNDARY
-
-Content-Type: text/plain; charset=us-ascii
-To: aa@bb.org
-From: cc@dd.org
-Subject: ee
-
-message 2
-
---BOUNDARY--
diff --git a/Lib/email/test/data/msg_31.txt b/Lib/email/test/data/msg_31.txt
deleted file mode 100644
index 1e58e56..0000000
--- a/Lib/email/test/data/msg_31.txt
+++ /dev/null
@@ -1,15 +0,0 @@
-From: aperson@dom.ain
-MIME-Version: 1.0
-Content-Type: multipart/mixed; boundary=BOUNDARY_
-
---BOUNDARY
-Content-Type: text/plain
-
-message 1
-
---BOUNDARY
-Content-Type: text/plain
-
-message 2
-
---BOUNDARY--
diff --git a/Lib/email/test/data/msg_32.txt b/Lib/email/test/data/msg_32.txt
deleted file mode 100644
index 07ec5af..0000000
--- a/Lib/email/test/data/msg_32.txt
+++ /dev/null
@@ -1,14 +0,0 @@
-Delivered-To: freebsd-isp@freebsd.org
-Date: Tue, 26 Sep 2000 12:23:03 -0500
-From: Anne Person <aperson@example.com>
-To: Barney Dude <bdude@example.com>
-Subject: Re: Limiting Perl CPU Utilization...
-Mime-Version: 1.0
-Content-Type: text/plain; charset*=ansi-x3.4-1968''us-ascii
-Content-Disposition: inline
-User-Agent: Mutt/1.3.8i
-Sender: owner-freebsd-isp@FreeBSD.ORG
-Precedence: bulk
-X-Loop: FreeBSD.org
-
-Some message.
diff --git a/Lib/email/test/data/msg_33.txt b/Lib/email/test/data/msg_33.txt
deleted file mode 100644
index 042787a..0000000
--- a/Lib/email/test/data/msg_33.txt
+++ /dev/null
@@ -1,29 +0,0 @@
-Delivered-To: freebsd-isp@freebsd.org
-Date: Wed, 27 Sep 2000 11:11:09 -0500
-From: Anne Person <aperson@example.com>
-To: Barney Dude <bdude@example.com>
-Subject: Re: Limiting Perl CPU Utilization...
-Mime-Version: 1.0
-Content-Type: multipart/signed; micalg*=ansi-x3.4-1968''pgp-md5;
- protocol*=ansi-x3.4-1968''application%2Fpgp-signature;
- boundary*="ansi-x3.4-1968''EeQfGwPcQSOJBaQU"
-Content-Disposition: inline
-Sender: owner-freebsd-isp@FreeBSD.ORG
-Precedence: bulk
-X-Loop: FreeBSD.org
-
-
---EeQfGwPcQSOJBaQU
-Content-Type: text/plain; charset*=ansi-x3.4-1968''us-ascii
-Content-Disposition: inline
-Content-Transfer-Encoding: quoted-printable
-
-part 1
-
---EeQfGwPcQSOJBaQU
-Content-Type: text/plain
-Content-Disposition: inline
-
-part 2
-
---EeQfGwPcQSOJBaQU--
diff --git a/Lib/email/test/data/msg_34.txt b/Lib/email/test/data/msg_34.txt
deleted file mode 100644
index 055dfea..0000000
--- a/Lib/email/test/data/msg_34.txt
+++ /dev/null
@@ -1,19 +0,0 @@
-From: aperson@dom.ain
-To: bperson@dom.ain
-Content-Type: multipart/digest; boundary=XYZ
-
---XYZ
-Content-Type: text/plain
-
-
-This is a text plain part that is counter to recommended practice in
-RFC 2046, $5.1.5, but is not illegal
-
---XYZ
-
-From: cperson@dom.ain
-To: dperson@dom.ain
-
-A submessage
-
---XYZ--
diff --git a/Lib/email/test/data/msg_35.txt b/Lib/email/test/data/msg_35.txt
deleted file mode 100644
index be7d5a2..0000000
--- a/Lib/email/test/data/msg_35.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-From: aperson@dom.ain
-To: bperson@dom.ain
-Subject: here's something interesting
-counter to RFC 2822, there's no separating newline here
diff --git a/Lib/email/test/data/msg_36.txt b/Lib/email/test/data/msg_36.txt
deleted file mode 100644
index 5632c30..0000000
--- a/Lib/email/test/data/msg_36.txt
+++ /dev/null
@@ -1,40 +0,0 @@
-Mime-Version: 1.0
-Content-Type: Multipart/Mixed; Boundary="NextPart"
-To: IETF-Announce:;
-From: Internet-Drafts@ietf.org
-Subject: I-D ACTION:draft-ietf-mboned-mix-00.txt
-Date: Tue, 22 Dec 1998 16:55:06 -0500
-
---NextPart
-
-Blah blah blah
-
---NextPart
-Content-Type: Multipart/Alternative; Boundary="OtherAccess"
-
---OtherAccess
-Content-Type: Message/External-body;
- access-type="mail-server";
- server="mailserv@ietf.org"
-
-Content-Type: text/plain
-Content-ID: <19981222151406.I-D@ietf.org>
-
-ENCODING mime
-FILE /internet-drafts/draft-ietf-mboned-mix-00.txt
-
---OtherAccess
-Content-Type: Message/External-body;
- name="draft-ietf-mboned-mix-00.txt";
- site="ftp.ietf.org";
- access-type="anon-ftp";
- directory="internet-drafts"
-
-Content-Type: text/plain
-Content-ID: <19981222151406.I-D@ietf.org>
-
-
---OtherAccess--
-
---NextPart--
-
diff --git a/Lib/email/test/data/msg_37.txt b/Lib/email/test/data/msg_37.txt
deleted file mode 100644
index 038d34a..0000000
--- a/Lib/email/test/data/msg_37.txt
+++ /dev/null
@@ -1,22 +0,0 @@
-Content-Type: multipart/mixed; boundary=ABCDE
-
---ABCDE
-Content-Type: text/x-one
-
-Blah
-
---ABCDE
---ABCDE
-Content-Type: text/x-two
-
-Blah
-
---ABCDE
---ABCDE
---ABCDE
---ABCDE
-Content-Type: text/x-two
-
-Blah
-
---ABCDE--
diff --git a/Lib/email/test/data/msg_38.txt b/Lib/email/test/data/msg_38.txt
deleted file mode 100644
index 006df81..0000000
--- a/Lib/email/test/data/msg_38.txt
+++ /dev/null
@@ -1,101 +0,0 @@
-MIME-Version: 1.0
-Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
-
-------- =_aaaaaaaaaa0
-Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa1"
-Content-ID: <20592.1022586929.1@example.com>
-
-------- =_aaaaaaaaaa1
-Content-Type: multipart/alternative; boundary="----- =_aaaaaaaaaa2"
-Content-ID: <20592.1022586929.2@example.com>
-
-------- =_aaaaaaaaaa2
-Content-Type: text/plain
-Content-ID: <20592.1022586929.3@example.com>
-Content-Description: very tricky
-Content-Transfer-Encoding: 7bit
-
-
-Unlike the test test_nested-multiples-with-internal-boundary, this
-piece of text not only contains the outer boundary tags
-------- =_aaaaaaaaaa1
-and
-------- =_aaaaaaaaaa0
-but puts them at the start of a line! And, to be even nastier, it
-even includes a couple of end tags, such as this one:
-
-------- =_aaaaaaaaaa1--
-
-and this one, which is from a multipart we haven't even seen yet!
-
-------- =_aaaaaaaaaa4--
-
-This will, I'm sure, cause much breakage of MIME parsers. But, as
-far as I can tell, it's perfectly legal. I have not yet ever seen
-a case of this in the wild, but I've seen *similar* things.
-
-
-------- =_aaaaaaaaaa2
-Content-Type: application/octet-stream
-Content-ID: <20592.1022586929.4@example.com>
-Content-Description: patch2
-Content-Transfer-Encoding: base64
-
-XXX
-
-------- =_aaaaaaaaaa2--
-
-------- =_aaaaaaaaaa1
-Content-Type: multipart/alternative; boundary="----- =_aaaaaaaaaa3"
-Content-ID: <20592.1022586929.6@example.com>
-
-------- =_aaaaaaaaaa3
-Content-Type: application/octet-stream
-Content-ID: <20592.1022586929.7@example.com>
-Content-Description: patch3
-Content-Transfer-Encoding: base64
-
-XXX
-
-------- =_aaaaaaaaaa3
-Content-Type: application/octet-stream
-Content-ID: <20592.1022586929.8@example.com>
-Content-Description: patch4
-Content-Transfer-Encoding: base64
-
-XXX
-
-------- =_aaaaaaaaaa3--
-
-------- =_aaaaaaaaaa1
-Content-Type: multipart/alternative; boundary="----- =_aaaaaaaaaa4"
-Content-ID: <20592.1022586929.10@example.com>
-
-------- =_aaaaaaaaaa4
-Content-Type: application/octet-stream
-Content-ID: <20592.1022586929.11@example.com>
-Content-Description: patch5
-Content-Transfer-Encoding: base64
-
-XXX
-
-------- =_aaaaaaaaaa4
-Content-Type: application/octet-stream
-Content-ID: <20592.1022586929.12@example.com>
-Content-Description: patch6
-Content-Transfer-Encoding: base64
-
-XXX
-
-------- =_aaaaaaaaaa4--
-
-------- =_aaaaaaaaaa1--
-
-------- =_aaaaaaaaaa0
-Content-Type: text/plain; charset="us-ascii"
-Content-ID: <20592.1022586929.15@example.com>
-
---
-It's never too late to have a happy childhood.
-
-------- =_aaaaaaaaaa0--
diff --git a/Lib/email/test/data/msg_39.txt b/Lib/email/test/data/msg_39.txt
deleted file mode 100644
index 124b269..0000000
--- a/Lib/email/test/data/msg_39.txt
+++ /dev/null
@@ -1,83 +0,0 @@
-MIME-Version: 1.0
-Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
-
-------- =_aaaaaaaaaa0
-Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa1"
-Content-ID: <20592.1022586929.1@example.com>
-
-------- =_aaaaaaaaaa1
-Content-Type: multipart/alternative; boundary="----- =_aaaaaaaaaa1"
-Content-ID: <20592.1022586929.2@example.com>
-
-------- =_aaaaaaaaaa1
-Content-Type: application/octet-stream
-Content-ID: <20592.1022586929.3@example.com>
-Content-Description: patch1
-Content-Transfer-Encoding: base64
-
-XXX
-
-------- =_aaaaaaaaaa1
-Content-Type: application/octet-stream
-Content-ID: <20592.1022586929.4@example.com>
-Content-Description: patch2
-Content-Transfer-Encoding: base64
-
-XXX
-
-------- =_aaaaaaaaaa1--
-
-------- =_aaaaaaaaaa1
-Content-Type: multipart/alternative; boundary="----- =_aaaaaaaaaa1"
-Content-ID: <20592.1022586929.6@example.com>
-
-------- =_aaaaaaaaaa1
-Content-Type: application/octet-stream
-Content-ID: <20592.1022586929.7@example.com>
-Content-Description: patch3
-Content-Transfer-Encoding: base64
-
-XXX
-
-------- =_aaaaaaaaaa1
-Content-Type: application/octet-stream
-Content-ID: <20592.1022586929.8@example.com>
-Content-Description: patch4
-Content-Transfer-Encoding: base64
-
-XXX
-
-------- =_aaaaaaaaaa1--
-
-------- =_aaaaaaaaaa1
-Content-Type: multipart/alternative; boundary="----- =_aaaaaaaaaa1"
-Content-ID: <20592.1022586929.10@example.com>
-
-------- =_aaaaaaaaaa1
-Content-Type: application/octet-stream
-Content-ID: <20592.1022586929.11@example.com>
-Content-Description: patch5
-Content-Transfer-Encoding: base64
-
-XXX
-
-------- =_aaaaaaaaaa1
-Content-Type: application/octet-stream
-Content-ID: <20592.1022586929.12@example.com>
-Content-Description: patch6
-Content-Transfer-Encoding: base64
-
-XXX
-
-------- =_aaaaaaaaaa1--
-
-------- =_aaaaaaaaaa1--
-
-------- =_aaaaaaaaaa0
-Content-Type: text/plain; charset="us-ascii"
-Content-ID: <20592.1022586929.15@example.com>
-
---
-It's never too late to have a happy childhood.
-
-------- =_aaaaaaaaaa0--
diff --git a/Lib/email/test/data/msg_40.txt b/Lib/email/test/data/msg_40.txt
deleted file mode 100644
index 1435fa1..0000000
--- a/Lib/email/test/data/msg_40.txt
+++ /dev/null
@@ -1,10 +0,0 @@
-MIME-Version: 1.0
-Content-Type: text/html; boundary="--961284236552522269"
-
-----961284236552522269
-Content-Type: text/html;
-Content-Transfer-Encoding: 7Bit
-
-<html></html>
-
-----961284236552522269--
diff --git a/Lib/email/test/data/msg_41.txt b/Lib/email/test/data/msg_41.txt
deleted file mode 100644
index 76cdd1c..0000000
--- a/Lib/email/test/data/msg_41.txt
+++ /dev/null
@@ -1,8 +0,0 @@
-From: "Allison Dunlap" <xxx@example.com>
-To: yyy@example.com
-Subject: 64423
-Date: Sun, 11 Jul 2004 16:09:27 -0300
-MIME-Version: 1.0
-Content-Type: multipart/alternative;
-
-Blah blah blah
diff --git a/Lib/email/test/data/msg_42.txt b/Lib/email/test/data/msg_42.txt
deleted file mode 100644
index a75f8f4..0000000
--- a/Lib/email/test/data/msg_42.txt
+++ /dev/null
@@ -1,20 +0,0 @@
-Content-Type: multipart/mixed; boundary="AAA"
-From: Mail Delivery Subsystem <xxx@example.com>
-To: yyy@example.com
-
-This is a MIME-encapsulated message
-
---AAA
-
-Stuff
-
---AAA
-Content-Type: message/rfc822
-
-From: webmaster@python.org
-To: zzz@example.com
-Content-Type: multipart/mixed; boundary="BBB"
-
---BBB--
-
---AAA--
diff --git a/Lib/email/test/data/msg_43.txt b/Lib/email/test/data/msg_43.txt
deleted file mode 100644
index 797d12c..0000000
--- a/Lib/email/test/data/msg_43.txt
+++ /dev/null
@@ -1,217 +0,0 @@
-From SRS0=aO/p=ON=bag.python.org=None@bounce2.pobox.com Fri Nov 26 21:40:36 2004
-X-VM-v5-Data: ([nil nil nil nil nil nil nil nil nil]
- [nil nil nil nil nil nil nil "MAILER DAEMON <>" "MAILER DAEMON <>" nil nil "Banned file: auto__mail.python.bat in mail from you" "^From:" nil nil nil nil "Banned file: auto__mail.python.bat in mail from you" nil nil nil nil nil nil nil]
- nil)
-MIME-Version: 1.0
-Message-Id: <edab.7804f5cb8070@python.org>
-Content-Type: multipart/report; report-type=delivery-status;
- charset=utf-8;
- boundary="----------=_1101526904-1956-5"
-X-Virus-Scanned: by XS4ALL Virus Scanner
-X-UIDL: 4\G!!!<c"!UV["!M7C!!
-From: MAILER DAEMON <>
-To: <webmaster@python.org>
-Subject: Banned file: auto__mail.python.bat in mail from you
-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST)
-
-This is a multi-part message in MIME format...
-
-------------=_1101526904-1956-5
-Content-Type: text/plain; charset="utf-8"
-Content-Disposition: inline
-Content-Transfer-Encoding: 7bit
-
-BANNED FILENAME ALERT
-
-Your message to: xxxxxxx@dot.ca.gov, xxxxxxxxxxxxx@dot.ca.gov, xxxxxxxxxx@dot.ca.gov, xxxxxxxx@dot.ca.gov, xxxxxxxxxx@dot.ca.gov, xxxxxx@dot.ca.gov, xxxxxxxxxx@dot.ca.gov, xxxxxx@dot.ca.gov, xxxxxx@dot.ca.gov, xxxxxxxxxxxxxxxx@dot.ca.gov, xxxxxxxxxxx@dot.ca.gov, xxxxxxxxxx@dot.ca.gov, xxxxxxxxxx@dot.ca.gov, xxxxxxxxxxxx@dot.ca.gov, xxxxxxxxxxxx@dot.ca.gov, xxxxxxx@dot.ca.gov, xxxxxxxxx@dot.ca.gov, xxxxxxxxxx@dot.ca.gov, xxxxxx@dot.ca.gov, xxx@dot.ca.gov, xxxxxxx@dot.ca.gov, xxxxxxx@dot.ca.gov, xxxxxxxxxxxxxxx@dot.ca.gov, xxxxxxxxxx@dot.ca.gov, xxxxxxx@dot.ca.gov, xxx@dot.ca.gov, xxxxxxxx@dot.ca.gov, xxxxxxxxxxxxx@dot.ca.gov, xxxxxxxxxxxxx@dot.ca.gov, xxxxxxxxxxx@dot.ca.gov, xxxxxxxxx@dot.ca.gov, xxxxxxxxxx@dot.ca.gov, xxxxxxxxxxxx@dot.ca.gov, xxxxxxx@dot.ca.gov, xxxxxxxxxxxxxxx@dot.ca.gov, xxxxxxxxxxxxx@dot.ca.gov, xxxx@dot.ca.gov, xxxxxxxx@dot.ca.gov, xxxxxxxxxx@dot.ca.gov, xxxxxxxxxxxxxxxxxx@dot.ca.gov
-was blocked by our Spam Firewall. The email you sent with the following subject has NOT BEEN DELIVERED:
-
-Subject: Delivery_failure_notice
-
-An attachment in that mail was of a file type that the Spam Firewall is set to block.
-
-
-
-------------=_1101526904-1956-5
-Content-Type: message/delivery-status
-Content-Disposition: inline
-Content-Transfer-Encoding: 7bit
-Content-Description: Delivery error report
-
-Reporting-MTA: dns; sacspam01.dot.ca.gov
-Received-From-MTA: smtp; sacspam01.dot.ca.gov ([127.0.0.1])
-Arrival-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST)
-
-Final-Recipient: rfc822; xxxxxxx@dot.ca.gov
-Action: failed
-Status: 5.7.1
-Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat
-Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST)
-
-Final-Recipient: rfc822; xxxxxxxxxxxxx@dot.ca.gov
-Action: failed
-Status: 5.7.1
-Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat
-Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST)
-
-Final-Recipient: rfc822; xxxxxxxxxx@dot.ca.gov
-Action: failed
-Status: 5.7.1
-Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat
-Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST)
-
-Final-Recipient: rfc822; xxxxxxxx@dot.ca.gov
-Action: failed
-Status: 5.7.1
-Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat
-Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST)
-
-Final-Recipient: rfc822; xxxxxxxxxx@dot.ca.gov
-Action: failed
-Status: 5.7.1
-Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat
-Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST)
-
-Final-Recipient: rfc822; xxxxxx@dot.ca.gov
-Action: failed
-Status: 5.7.1
-Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat
-Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST)
-
-Final-Recipient: rfc822; xxxxxxxxxx@dot.ca.gov
-Action: failed
-Status: 5.7.1
-Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat
-Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST)
-
-Final-Recipient: rfc822; xxxxxx@dot.ca.gov
-Action: failed
-Status: 5.7.1
-Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat
-Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST)
-
-Final-Recipient: rfc822; xxxxxx@dot.ca.gov
-Action: failed
-Status: 5.7.1
-Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat
-Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST)
-
-Final-Recipient: rfc822; xxxxxxxxxxxxxxxx@dot.ca.gov
-Action: failed
-Status: 5.7.1
-Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat
-Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST)
-
-Final-Recipient: rfc822; xxxxxxxxxxx@dot.ca.gov
-Action: failed
-Status: 5.7.1
-Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat
-Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST)
-
-Final-Recipient: rfc822; xxxxxxxxxx@dot.ca.gov
-Action: failed
-Status: 5.7.1
-Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat
-Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST)
-
-Final-Recipient: rfc822; xxxxxxxxxx@dot.ca.gov
-Action: failed
-Status: 5.7.1
-Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat
-Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST)
-
-Final-Recipient: rfc822; xxxxxxxxxxxx@dot.ca.gov
-Action: failed
-Status: 5.7.1
-Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat
-Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST)
-
-Final-Recipient: rfc822; xxxxxxxxxxxx@dot.ca.gov
-Action: failed
-Status: 5.7.1
-Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat
-Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST)
-
-Final-Recipient: rfc822; xxxxxxx@dot.ca.gov
-Action: failed
-Status: 5.7.1
-Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat
-Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST)
-
-Final-Recipient: rfc822; xxxxxxxxx@dot.ca.gov
-Action: failed
-Status: 5.7.1
-Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat
-Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST)
-
-Final-Recipient: rfc822; xxxxxxxxxx@dot.ca.gov
-Action: failed
-Status: 5.7.1
-Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat
-Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST)
-
-Final-Recipient: rfc822; xxxxxx@dot.ca.gov
-Action: failed
-Status: 5.7.1
-Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat
-Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST)
-
-Final-Recipient: rfc822; xxx@dot.ca.gov
-Action: failed
-Status: 5.7.1
-Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat
-Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST)
-
-Final-Recipient: rfc822; xxxxxxx@dot.ca.gov
-Action: failed
-Status: 5.7.1
-Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat
-Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST)
-
-Final-Recipient: rfc822; xxxxxxx@dot.ca.gov
-Action: failed
-Status: 5.7.1
-Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat
-Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST)
-
-Final-Recipient: rfc822; xxxxxxxxxxxxxxx@dot.ca.gov
-Action: failed
-Status: 5.7.1
-Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat
-Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST)
-
-Final-Recipient: rfc822; xxxxxxxxxx@dot.ca.gov
-Action: failed
-Status: 5.7.1
-Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat
-Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST)
-
-Final-Recipient: rfc822; xxxxxxx@dot.ca.gov
-Action: failed
-Status: 5.7.1
-Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat
-Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST)
-
-------------=_1101526904-1956-5
-Content-Type: text/rfc822-headers
-Content-Disposition: inline
-Content-Transfer-Encoding: 7bit
-Content-Description: Undelivered-message headers
-
-Received: from kgsav.org (ppp-70-242-162-63.dsl.spfdmo.swbell.net [70.242.162.63])
- by sacspam01.dot.ca.gov (Spam Firewall) with SMTP
- id A232AD03DE3A; Fri, 26 Nov 2004 19:41:35 -0800 (PST)
-From: webmaster@python.org
-To: xxxxx@dot.ca.gov
-Date: Sat, 27 Nov 2004 03:35:30 UTC
-Subject: Delivery_failure_notice
-Importance: Normal
-X-Priority: 3 (Normal)
-X-MSMail-Priority: Normal
-Message-ID: <edab.7804f5cb8070@python.org>
-MIME-Version: 1.0
-Content-Type: multipart/mixed; boundary="====67bd2b7a5.f99f7"
-Content-Transfer-Encoding: 7bit
-
-------------=_1101526904-1956-5--
-
diff --git a/Lib/email/test/data/msg_44.txt b/Lib/email/test/data/msg_44.txt
deleted file mode 100644
index ae462a6..0000000
--- a/Lib/email/test/data/msg_44.txt
+++ /dev/null
@@ -1,35 +0,0 @@
-Return-Path: <barry@python.org>
-Delivered-To: barry@python.org
-Received: by mail.python.org (Postfix, from userid 889)
- id C2BF0D37C6; Tue, 11 Sep 2001 00:05:05 -0400 (EDT)
-MIME-Version: 1.0
-Content-Type: multipart/mixed; boundary="h90VIIIKmx"
-Content-Transfer-Encoding: 7bit
-Message-ID: <15261.36209.358846.118674@anthem.python.org>
-From: barry@python.org (Barry A. Warsaw)
-To: barry@python.org
-Subject: a simple multipart
-Date: Tue, 11 Sep 2001 00:05:05 -0400
-X-Mailer: VM 6.95 under 21.4 (patch 4) "Artificial Intelligence" XEmacs Lucid
-X-Attribution: BAW
-X-Oblique-Strategy: Make a door into a window
-
-
---h90VIIIKmx
-Content-Type: text/plain
-Content-Disposition: inline; name="msg.txt"
-Content-Transfer-Encoding: 7bit
-
-a simple kind of mirror
-to reflect upon our own
-
---h90VIIIKmx
-Content-Type: text/plain
-Content-Disposition: inline; name="msg.txt"
-Content-Transfer-Encoding: 7bit
-
-a simple kind of mirror
-to reflect upon our own
-
---h90VIIIKmx--
-
diff --git a/Lib/email/test/test_email.py b/Lib/email/test/test_email.py
deleted file mode 100644
index 5e8d652..0000000
--- a/Lib/email/test/test_email.py
+++ /dev/null
@@ -1,3285 +0,0 @@
-# Copyright (C) 2001-2007 Python Software Foundation
-# Contact: email-sig@python.org
-# email package unit tests
-
-import os
-import sys
-import time
-import base64
-import difflib
-import unittest
-import warnings
-from io import StringIO
-
-import email
-
-from email.Charset import Charset
-from email.Header import Header, decode_header, make_header
-from email.Parser import Parser, HeaderParser
-from email.Generator import Generator, DecodedGenerator
-from email.Message import Message
-from email.MIMEAudio import MIMEAudio
-from email.MIMEText import MIMEText
-from email.MIMEImage import MIMEImage
-from email.MIMEBase import MIMEBase
-from email.MIMEMessage import MIMEMessage
-from email.MIMEMultipart import MIMEMultipart
-from email import Utils
-from email import Errors
-from email import Encoders
-from email import Iterators
-from email import base64MIME
-from email import quopriMIME
-
-from test.test_support import findfile, run_unittest
-from email.test import __file__ as landmark
-
-
-NL = '\n'
-EMPTYSTRING = ''
-SPACE = ' '
-
-
-
-def openfile(filename, mode='r'):
- path = os.path.join(os.path.dirname(landmark), 'data', filename)
- return open(path, mode)
-
-
-
-# Base test class
-class TestEmailBase(unittest.TestCase):
- def ndiffAssertEqual(self, first, second):
- """Like failUnlessEqual except use ndiff for readable output."""
- if first != second:
- sfirst = str(first)
- ssecond = str(second)
- diff = difflib.ndiff(sfirst.splitlines(True),
- ssecond.splitlines(True))
- raise self.failureException(NL + "".join(diff))
-
- def _msgobj(self, filename):
- fp = openfile(findfile(filename))
- try:
- msg = email.message_from_file(fp)
- finally:
- fp.close()
- return msg
-
-
-
-# Test various aspects of the Message class's API
-class TestMessageAPI(TestEmailBase):
- def test_get_all(self):
- eq = self.assertEqual
- msg = self._msgobj('msg_20.txt')
- eq(msg.get_all('cc'), ['ccc@zzz.org', 'ddd@zzz.org', 'eee@zzz.org'])
- eq(msg.get_all('xx', 'n/a'), 'n/a')
-
- def test_getset_charset(self):
- eq = self.assertEqual
- msg = Message()
- eq(msg.get_charset(), None)
- charset = Charset('iso-8859-1')
- msg.set_charset(charset)
- eq(msg['mime-version'], '1.0')
- eq(msg.get_content_type(), 'text/plain')
- eq(msg['content-type'], 'text/plain; charset="iso-8859-1"')
- eq(msg.get_param('charset'), 'iso-8859-1')
- eq(msg['content-transfer-encoding'], 'quoted-printable')
- eq(msg.get_charset().input_charset, 'iso-8859-1')
- # Remove the charset
- msg.set_charset(None)
- eq(msg.get_charset(), None)
- eq(msg['content-type'], 'text/plain')
- # Try adding a charset when there's already MIME headers present
- msg = Message()
- msg['MIME-Version'] = '2.0'
- msg['Content-Type'] = 'text/x-weird'
- msg['Content-Transfer-Encoding'] = 'quinted-puntable'
- msg.set_charset(charset)
- eq(msg['mime-version'], '2.0')
- eq(msg['content-type'], 'text/x-weird; charset="iso-8859-1"')
- eq(msg['content-transfer-encoding'], 'quinted-puntable')
-
- def test_set_charset_from_string(self):
- eq = self.assertEqual
- msg = Message()
- msg.set_charset('us-ascii')
- eq(msg.get_charset().input_charset, 'us-ascii')
- eq(msg['content-type'], 'text/plain; charset="us-ascii"')
-
- def test_set_payload_with_charset(self):
- msg = Message()
- charset = Charset('iso-8859-1')
- msg.set_payload('This is a string payload', charset)
- self.assertEqual(msg.get_charset().input_charset, 'iso-8859-1')
-
- def test_get_charsets(self):
- eq = self.assertEqual
-
- msg = self._msgobj('msg_08.txt')
- charsets = msg.get_charsets()
- eq(charsets, [None, 'us-ascii', 'iso-8859-1', 'iso-8859-2', 'koi8-r'])
-
- msg = self._msgobj('msg_09.txt')
- charsets = msg.get_charsets('dingbat')
- eq(charsets, ['dingbat', 'us-ascii', 'iso-8859-1', 'dingbat',
- 'koi8-r'])
-
- msg = self._msgobj('msg_12.txt')
- charsets = msg.get_charsets()
- eq(charsets, [None, 'us-ascii', 'iso-8859-1', None, 'iso-8859-2',
- 'iso-8859-3', 'us-ascii', 'koi8-r'])
-
- def test_get_filename(self):
- eq = self.assertEqual
-
- msg = self._msgobj('msg_04.txt')
- filenames = [p.get_filename() for p in msg.get_payload()]
- eq(filenames, ['msg.txt', 'msg.txt'])
-
- msg = self._msgobj('msg_07.txt')
- subpart = msg.get_payload(1)
- eq(subpart.get_filename(), 'dingusfish.gif')
-
- def test_get_filename_with_name_parameter(self):
- eq = self.assertEqual
-
- msg = self._msgobj('msg_44.txt')
- filenames = [p.get_filename() for p in msg.get_payload()]
- eq(filenames, ['msg.txt', 'msg.txt'])
-
- def test_get_boundary(self):
- eq = self.assertEqual
- msg = self._msgobj('msg_07.txt')
- # No quotes!
- eq(msg.get_boundary(), 'BOUNDARY')
-
- def test_set_boundary(self):
- eq = self.assertEqual
- # This one has no existing boundary parameter, but the Content-Type:
- # header appears fifth.
- msg = self._msgobj('msg_01.txt')
- msg.set_boundary('BOUNDARY')
- header, value = msg.items()[4]
- eq(header.lower(), 'content-type')
- eq(value, 'text/plain; charset="us-ascii"; boundary="BOUNDARY"')
- # This one has a Content-Type: header, with a boundary, stuck in the
- # middle of its headers. Make sure the order is preserved; it should
- # be fifth.
- msg = self._msgobj('msg_04.txt')
- msg.set_boundary('BOUNDARY')
- header, value = msg.items()[4]
- eq(header.lower(), 'content-type')
- eq(value, 'multipart/mixed; boundary="BOUNDARY"')
- # And this one has no Content-Type: header at all.
- msg = self._msgobj('msg_03.txt')
- self.assertRaises(Errors.HeaderParseError,
- msg.set_boundary, 'BOUNDARY')
-
- def test_get_decoded_payload(self):
- eq = self.assertEqual
- msg = self._msgobj('msg_10.txt')
- # The outer message is a multipart
- eq(msg.get_payload(decode=True), None)
- # Subpart 1 is 7bit encoded
- eq(msg.get_payload(0).get_payload(decode=True),
- 'This is a 7bit encoded message.\n')
- # Subpart 2 is quopri
- eq(msg.get_payload(1).get_payload(decode=True),
- '\xa1This is a Quoted Printable encoded message!\n')
- # Subpart 3 is base64
- eq(msg.get_payload(2).get_payload(decode=True),
- 'This is a Base64 encoded message.')
- # Subpart 4 has no Content-Transfer-Encoding: header.
- eq(msg.get_payload(3).get_payload(decode=True),
- 'This has no Content-Transfer-Encoding: header.\n')
-
- def test_get_decoded_uu_payload(self):
- eq = self.assertEqual
- msg = Message()
- msg.set_payload('begin 666 -\n+:&5L;&\\@=V]R;&0 \n \nend\n')
- for cte in ('x-uuencode', 'uuencode', 'uue', 'x-uue'):
- msg['content-transfer-encoding'] = cte
- eq(msg.get_payload(decode=True), 'hello world')
- # Now try some bogus data
- msg.set_payload('foo')
- eq(msg.get_payload(decode=True), 'foo')
-
- def test_decode_bogus_uu_payload_quietly(self):
- msg = Message()
- msg.set_payload('begin 664 foo.txt\n%<W1F=0000H \n \nend\n')
- msg['Content-Transfer-Encoding'] = 'x-uuencode'
- old_stderr = sys.stderr
- try:
- sys.stderr = sfp = StringIO()
- # We don't care about the payload
- msg.get_payload(decode=True)
- finally:
- sys.stderr = old_stderr
- self.assertEqual(sfp.getvalue(), '')
-
- def test_decoded_generator(self):
- eq = self.assertEqual
- msg = self._msgobj('msg_07.txt')
- fp = openfile('msg_17.txt')
- try:
- text = fp.read()
- finally:
- fp.close()
- s = StringIO()
- g = DecodedGenerator(s)
- g.flatten(msg)
- eq(s.getvalue(), text)
-
- def test__contains__(self):
- msg = Message()
- msg['From'] = 'Me'
- msg['to'] = 'You'
- # Check for case insensitivity
- self.failUnless('from' in msg)
- self.failUnless('From' in msg)
- self.failUnless('FROM' in msg)
- self.failUnless('to' in msg)
- self.failUnless('To' in msg)
- self.failUnless('TO' in msg)
-
- def test_as_string(self):
- eq = self.assertEqual
- msg = self._msgobj('msg_01.txt')
- fp = openfile('msg_01.txt')
- try:
- text = fp.read()
- finally:
- fp.close()
- eq(text, msg.as_string())
- fullrepr = str(msg)
- lines = fullrepr.split('\n')
- self.failUnless(lines[0].startswith('From '))
- eq(text, NL.join(lines[1:]))
-
- def test_bad_param(self):
- msg = email.message_from_string("Content-Type: blarg; baz; boo\n")
- self.assertEqual(msg.get_param('baz'), '')
-
- def test_missing_filename(self):
- msg = email.message_from_string("From: foo\n")
- self.assertEqual(msg.get_filename(), None)
-
- def test_bogus_filename(self):
- msg = email.message_from_string(
- "Content-Disposition: blarg; filename\n")
- self.assertEqual(msg.get_filename(), '')
-
- def test_missing_boundary(self):
- msg = email.message_from_string("From: foo\n")
- self.assertEqual(msg.get_boundary(), None)
-
- def test_get_params(self):
- eq = self.assertEqual
- msg = email.message_from_string(
- 'X-Header: foo=one; bar=two; baz=three\n')
- eq(msg.get_params(header='x-header'),
- [('foo', 'one'), ('bar', 'two'), ('baz', 'three')])
- msg = email.message_from_string(
- 'X-Header: foo; bar=one; baz=two\n')
- eq(msg.get_params(header='x-header'),
- [('foo', ''), ('bar', 'one'), ('baz', 'two')])
- eq(msg.get_params(), None)
- msg = email.message_from_string(
- 'X-Header: foo; bar="one"; baz=two\n')
- eq(msg.get_params(header='x-header'),
- [('foo', ''), ('bar', 'one'), ('baz', 'two')])
-
- def test_get_param_liberal(self):
- msg = Message()
- msg['Content-Type'] = 'Content-Type: Multipart/mixed; boundary = "CPIMSSMTPC06p5f3tG"'
- self.assertEqual(msg.get_param('boundary'), 'CPIMSSMTPC06p5f3tG')
-
- def test_get_param(self):
- eq = self.assertEqual
- msg = email.message_from_string(
- "X-Header: foo=one; bar=two; baz=three\n")
- eq(msg.get_param('bar', header='x-header'), 'two')
- eq(msg.get_param('quuz', header='x-header'), None)
- eq(msg.get_param('quuz'), None)
- msg = email.message_from_string(
- 'X-Header: foo; bar="one"; baz=two\n')
- eq(msg.get_param('foo', header='x-header'), '')
- eq(msg.get_param('bar', header='x-header'), 'one')
- eq(msg.get_param('baz', header='x-header'), 'two')
- # XXX: We are not RFC-2045 compliant! We cannot parse:
- # msg["Content-Type"] = 'text/plain; weird="hey; dolly? [you] @ <\\"home\\">?"'
- # msg.get_param("weird")
- # yet.
-
- def test_get_param_funky_continuation_lines(self):
- msg = self._msgobj('msg_22.txt')
- self.assertEqual(msg.get_payload(1).get_param('name'), 'wibble.JPG')
-
- def test_get_param_with_semis_in_quotes(self):
- msg = email.message_from_string(
- 'Content-Type: image/pjpeg; name="Jim&amp;&amp;Jill"\n')
- self.assertEqual(msg.get_param('name'), 'Jim&amp;&amp;Jill')
- self.assertEqual(msg.get_param('name', unquote=False),
- '"Jim&amp;&amp;Jill"')
-
- def test_has_key(self):
- msg = email.message_from_string('Header: exists')
- self.failUnless(msg.has_key('header'))
- self.failUnless(msg.has_key('Header'))
- self.failUnless(msg.has_key('HEADER'))
- self.failIf(msg.has_key('headeri'))
-
- def test_set_param(self):
- eq = self.assertEqual
- msg = Message()
- msg.set_param('charset', 'iso-2022-jp')
- eq(msg.get_param('charset'), 'iso-2022-jp')
- msg.set_param('importance', 'high value')
- eq(msg.get_param('importance'), 'high value')
- eq(msg.get_param('importance', unquote=False), '"high value"')
- eq(msg.get_params(), [('text/plain', ''),
- ('charset', 'iso-2022-jp'),
- ('importance', 'high value')])
- eq(msg.get_params(unquote=False), [('text/plain', ''),
- ('charset', '"iso-2022-jp"'),
- ('importance', '"high value"')])
- msg.set_param('charset', 'iso-9999-xx', header='X-Jimmy')
- eq(msg.get_param('charset', header='X-Jimmy'), 'iso-9999-xx')
-
- def test_del_param(self):
- eq = self.assertEqual
- msg = self._msgobj('msg_05.txt')
- eq(msg.get_params(),
- [('multipart/report', ''), ('report-type', 'delivery-status'),
- ('boundary', 'D1690A7AC1.996856090/mail.example.com')])
- old_val = msg.get_param("report-type")
- msg.del_param("report-type")
- eq(msg.get_params(),
- [('multipart/report', ''),
- ('boundary', 'D1690A7AC1.996856090/mail.example.com')])
- msg.set_param("report-type", old_val)
- eq(msg.get_params(),
- [('multipart/report', ''),
- ('boundary', 'D1690A7AC1.996856090/mail.example.com'),
- ('report-type', old_val)])
-
- def test_del_param_on_other_header(self):
- msg = Message()
- msg.add_header('Content-Disposition', 'attachment', filename='bud.gif')
- msg.del_param('filename', 'content-disposition')
- self.assertEqual(msg['content-disposition'], 'attachment')
-
- def test_set_type(self):
- eq = self.assertEqual
- msg = Message()
- self.assertRaises(ValueError, msg.set_type, 'text')
- msg.set_type('text/plain')
- eq(msg['content-type'], 'text/plain')
- msg.set_param('charset', 'us-ascii')
- eq(msg['content-type'], 'text/plain; charset="us-ascii"')
- msg.set_type('text/html')
- eq(msg['content-type'], 'text/html; charset="us-ascii"')
-
- def test_set_type_on_other_header(self):
- msg = Message()
- msg['X-Content-Type'] = 'text/plain'
- msg.set_type('application/octet-stream', 'X-Content-Type')
- self.assertEqual(msg['x-content-type'], 'application/octet-stream')
-
- def test_get_content_type_missing(self):
- msg = Message()
- self.assertEqual(msg.get_content_type(), 'text/plain')
-
- def test_get_content_type_missing_with_default_type(self):
- msg = Message()
- msg.set_default_type('message/rfc822')
- self.assertEqual(msg.get_content_type(), 'message/rfc822')
-
- def test_get_content_type_from_message_implicit(self):
- msg = self._msgobj('msg_30.txt')
- self.assertEqual(msg.get_payload(0).get_content_type(),
- 'message/rfc822')
-
- def test_get_content_type_from_message_explicit(self):
- msg = self._msgobj('msg_28.txt')
- self.assertEqual(msg.get_payload(0).get_content_type(),
- 'message/rfc822')
-
- def test_get_content_type_from_message_text_plain_implicit(self):
- msg = self._msgobj('msg_03.txt')
- self.assertEqual(msg.get_content_type(), 'text/plain')
-
- def test_get_content_type_from_message_text_plain_explicit(self):
- msg = self._msgobj('msg_01.txt')
- self.assertEqual(msg.get_content_type(), 'text/plain')
-
- def test_get_content_maintype_missing(self):
- msg = Message()
- self.assertEqual(msg.get_content_maintype(), 'text')
-
- def test_get_content_maintype_missing_with_default_type(self):
- msg = Message()
- msg.set_default_type('message/rfc822')
- self.assertEqual(msg.get_content_maintype(), 'message')
-
- def test_get_content_maintype_from_message_implicit(self):
- msg = self._msgobj('msg_30.txt')
- self.assertEqual(msg.get_payload(0).get_content_maintype(), 'message')
-
- def test_get_content_maintype_from_message_explicit(self):
- msg = self._msgobj('msg_28.txt')
- self.assertEqual(msg.get_payload(0).get_content_maintype(), 'message')
-
- def test_get_content_maintype_from_message_text_plain_implicit(self):
- msg = self._msgobj('msg_03.txt')
- self.assertEqual(msg.get_content_maintype(), 'text')
-
- def test_get_content_maintype_from_message_text_plain_explicit(self):
- msg = self._msgobj('msg_01.txt')
- self.assertEqual(msg.get_content_maintype(), 'text')
-
- def test_get_content_subtype_missing(self):
- msg = Message()
- self.assertEqual(msg.get_content_subtype(), 'plain')
-
- def test_get_content_subtype_missing_with_default_type(self):
- msg = Message()
- msg.set_default_type('message/rfc822')
- self.assertEqual(msg.get_content_subtype(), 'rfc822')
-
- def test_get_content_subtype_from_message_implicit(self):
- msg = self._msgobj('msg_30.txt')
- self.assertEqual(msg.get_payload(0).get_content_subtype(), 'rfc822')
-
- def test_get_content_subtype_from_message_explicit(self):
- msg = self._msgobj('msg_28.txt')
- self.assertEqual(msg.get_payload(0).get_content_subtype(), 'rfc822')
-
- def test_get_content_subtype_from_message_text_plain_implicit(self):
- msg = self._msgobj('msg_03.txt')
- self.assertEqual(msg.get_content_subtype(), 'plain')
-
- def test_get_content_subtype_from_message_text_plain_explicit(self):
- msg = self._msgobj('msg_01.txt')
- self.assertEqual(msg.get_content_subtype(), 'plain')
-
- def test_get_content_maintype_error(self):
- msg = Message()
- msg['Content-Type'] = 'no-slash-in-this-string'
- self.assertEqual(msg.get_content_maintype(), 'text')
-
- def test_get_content_subtype_error(self):
- msg = Message()
- msg['Content-Type'] = 'no-slash-in-this-string'
- self.assertEqual(msg.get_content_subtype(), 'plain')
-
- def test_replace_header(self):
- eq = self.assertEqual
- msg = Message()
- msg.add_header('First', 'One')
- msg.add_header('Second', 'Two')
- msg.add_header('Third', 'Three')
- eq(msg.keys(), ['First', 'Second', 'Third'])
- eq(msg.values(), ['One', 'Two', 'Three'])
- msg.replace_header('Second', 'Twenty')
- eq(msg.keys(), ['First', 'Second', 'Third'])
- eq(msg.values(), ['One', 'Twenty', 'Three'])
- msg.add_header('First', 'Eleven')
- msg.replace_header('First', 'One Hundred')
- eq(msg.keys(), ['First', 'Second', 'Third', 'First'])
- eq(msg.values(), ['One Hundred', 'Twenty', 'Three', 'Eleven'])
- self.assertRaises(KeyError, msg.replace_header, 'Fourth', 'Missing')
-
- def test_broken_base64_payload(self):
- x = 'AwDp0P7//y6LwKEAcPa/6Q=9'
- msg = Message()
- msg['content-type'] = 'audio/x-midi'
- msg['content-transfer-encoding'] = 'base64'
- msg.set_payload(x)
- self.assertEqual(msg.get_payload(decode=True), x)
-
- def test_get_content_charset(self):
- msg = Message()
- msg.set_charset('us-ascii')
- self.assertEqual('us-ascii', msg.get_content_charset())
- msg.set_charset('us-ascii')
- self.assertEqual('us-ascii', msg.get_content_charset())
-
-
-
-# Test the email.Encoders module
-class TestEncoders(unittest.TestCase):
- def test_encode_empty_payload(self):
- eq = self.assertEqual
- msg = Message()
- msg.set_charset('us-ascii')
- eq(msg['content-transfer-encoding'], '7bit')
-
- def test_default_cte(self):
- eq = self.assertEqual
- msg = MIMEText('hello world')
- eq(msg['content-transfer-encoding'], '7bit')
-
- def test_default_cte(self):
- eq = self.assertEqual
- # With no explicit _charset its us-ascii, and all are 7-bit
- msg = MIMEText('hello world')
- eq(msg['content-transfer-encoding'], '7bit')
- # Similar, but with 8-bit data
- msg = MIMEText('hello \xf8 world')
- eq(msg['content-transfer-encoding'], '8bit')
- # And now with a different charset
- msg = MIMEText('hello \xf8 world', _charset='iso-8859-1')
- eq(msg['content-transfer-encoding'], 'quoted-printable')
-
-
-
-# Test long header wrapping
-class TestLongHeaders(TestEmailBase):
- def test_split_long_continuation(self):
- eq = self.ndiffAssertEqual
- msg = email.message_from_string("""\
-Subject: bug demonstration
-\t12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789
-\tmore text
-
-test
-""")
- sfp = StringIO()
- g = Generator(sfp)
- g.flatten(msg)
- eq(sfp.getvalue(), """\
-Subject: bug demonstration
-\t12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789
-\tmore text
-
-test
-""")
-
- def test_another_long_almost_unsplittable_header(self):
- eq = self.ndiffAssertEqual
- hstr = """\
-bug demonstration
-\t12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789
-\tmore text"""
- h = Header(hstr, continuation_ws='\t')
- eq(h.encode(), """\
-bug demonstration
-\t12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789
-\tmore text""")
- h = Header(hstr)
- eq(h.encode(), """\
-bug demonstration
- 12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789
- more text""")
-
- def test_long_nonstring(self):
- eq = self.ndiffAssertEqual
- g = Charset("iso-8859-1")
- cz = Charset("iso-8859-2")
- utf8 = Charset("utf-8")
- g_head = "Die Mieter treten hier ein werden mit einem Foerderband komfortabel den Korridor entlang, an s\xfcdl\xfcndischen Wandgem\xe4lden vorbei, gegen die rotierenden Klingen bef\xf6rdert. "
- cz_head = "Finan\xe8ni metropole se hroutily pod tlakem jejich d\xf9vtipu.. "
- utf8_head = "\u6b63\u78ba\u306b\u8a00\u3046\u3068\u7ffb\u8a33\u306f\u3055\u308c\u3066\u3044\u307e\u305b\u3093\u3002\u4e00\u90e8\u306f\u30c9\u30a4\u30c4\u8a9e\u3067\u3059\u304c\u3001\u3042\u3068\u306f\u3067\u305f\u3089\u3081\u3067\u3059\u3002\u5b9f\u969b\u306b\u306f\u300cWenn ist das Nunstuck git und Slotermeyer? Ja! Beiherhund das Oder die Flipperwaldt gersput.\u300d\u3068\u8a00\u3063\u3066\u3044\u307e\u3059\u3002".encode("utf-8")
- h = Header(g_head, g, header_name='Subject')
- h.append(cz_head, cz)
- h.append(utf8_head, utf8)
- msg = Message()
- msg['Subject'] = h
- sfp = StringIO()
- g = Generator(sfp)
- g.flatten(msg)
- eq(sfp.getvalue(), """\
-Subject: =?iso-8859-1?q?Die_Mieter_treten_hier_ein_werden_mit_einem_Foerd?=
- =?iso-8859-1?q?erband_komfortabel_den_Korridor_entlang=2C_an_s=FCdl=FCndi?=
- =?iso-8859-1?q?schen_Wandgem=E4lden_vorbei=2C_gegen_die_rotierenden_Kling?=
- =?iso-8859-1?q?en_bef=F6rdert=2E_?= =?iso-8859-2?q?Finan=E8ni_met?=
- =?iso-8859-2?q?ropole_se_hroutily_pod_tlakem_jejich_d=F9vtipu=2E=2E_?=
- =?utf-8?b?5q2j56K644Gr6KiA44GG44Go57+76Kiz44Gv44GV44KM44Gm44GE?=
- =?utf-8?b?44G+44Gb44KT44CC5LiA6YOo44Gv44OJ44Kk44OE6Kqe44Gn44GZ44GM44CB?=
- =?utf-8?b?44GC44Go44Gv44Gn44Gf44KJ44KB44Gn44GZ44CC5a6f6Zqb44Gr44Gv44CM?=
- =?utf-8?q?Wenn_ist_das_Nunstuck_git_und_Slotermeyer=3F_Ja!_Beiherhund_das?=
- =?utf-8?b?IE9kZXIgZGllIEZsaXBwZXJ3YWxkdCBnZXJzcHV0LuOAjeOBqOiogOOBow==?=
- =?utf-8?b?44Gm44GE44G+44GZ44CC?=
-
-""")
- eq(h.encode(), """\
-=?iso-8859-1?q?Die_Mieter_treten_hier_ein_werden_mit_einem_Foerd?=
- =?iso-8859-1?q?erband_komfortabel_den_Korridor_entlang=2C_an_s=FCdl=FCndi?=
- =?iso-8859-1?q?schen_Wandgem=E4lden_vorbei=2C_gegen_die_rotierenden_Kling?=
- =?iso-8859-1?q?en_bef=F6rdert=2E_?= =?iso-8859-2?q?Finan=E8ni_met?=
- =?iso-8859-2?q?ropole_se_hroutily_pod_tlakem_jejich_d=F9vtipu=2E=2E_?=
- =?utf-8?b?5q2j56K644Gr6KiA44GG44Go57+76Kiz44Gv44GV44KM44Gm44GE?=
- =?utf-8?b?44G+44Gb44KT44CC5LiA6YOo44Gv44OJ44Kk44OE6Kqe44Gn44GZ44GM44CB?=
- =?utf-8?b?44GC44Go44Gv44Gn44Gf44KJ44KB44Gn44GZ44CC5a6f6Zqb44Gr44Gv44CM?=
- =?utf-8?q?Wenn_ist_das_Nunstuck_git_und_Slotermeyer=3F_Ja!_Beiherhund_das?=
- =?utf-8?b?IE9kZXIgZGllIEZsaXBwZXJ3YWxkdCBnZXJzcHV0LuOAjeOBqOiogOOBow==?=
- =?utf-8?b?44Gm44GE44G+44GZ44CC?=""")
-
- def test_long_header_encode(self):
- eq = self.ndiffAssertEqual
- h = Header('wasnipoop; giraffes="very-long-necked-animals"; '
- 'spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"',
- header_name='X-Foobar-Spoink-Defrobnit')
- eq(h.encode(), '''\
-wasnipoop; giraffes="very-long-necked-animals";
- spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"''')
-
- def test_long_header_encode_with_tab_continuation(self):
- eq = self.ndiffAssertEqual
- h = Header('wasnipoop; giraffes="very-long-necked-animals"; '
- 'spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"',
- header_name='X-Foobar-Spoink-Defrobnit',
- continuation_ws='\t')
- eq(h.encode(), '''\
-wasnipoop; giraffes="very-long-necked-animals";
-\tspooge="yummy"; hippos="gargantuan"; marshmallows="gooey"''')
-
- def test_header_splitter(self):
- eq = self.ndiffAssertEqual
- msg = MIMEText('')
- # It'd be great if we could use add_header() here, but that doesn't
- # guarantee an order of the parameters.
- msg['X-Foobar-Spoink-Defrobnit'] = (
- 'wasnipoop; giraffes="very-long-necked-animals"; '
- 'spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"')
- sfp = StringIO()
- g = Generator(sfp)
- g.flatten(msg)
- eq(sfp.getvalue(), '''\
-Content-Type: text/plain; charset="us-ascii"
-MIME-Version: 1.0
-Content-Transfer-Encoding: 7bit
-X-Foobar-Spoink-Defrobnit: wasnipoop; giraffes="very-long-necked-animals";
-\tspooge="yummy"; hippos="gargantuan"; marshmallows="gooey"
-
-''')
-
- def test_no_semis_header_splitter(self):
- eq = self.ndiffAssertEqual
- msg = Message()
- msg['From'] = 'test@dom.ain'
- msg['References'] = SPACE.join(['<%d@dom.ain>' % i for i in range(10)])
- msg.set_payload('Test')
- sfp = StringIO()
- g = Generator(sfp)
- g.flatten(msg)
- eq(sfp.getvalue(), """\
-From: test@dom.ain
-References: <0@dom.ain> <1@dom.ain> <2@dom.ain> <3@dom.ain> <4@dom.ain>
-\t<5@dom.ain> <6@dom.ain> <7@dom.ain> <8@dom.ain> <9@dom.ain>
-
-Test""")
-
- def test_no_split_long_header(self):
- eq = self.ndiffAssertEqual
- hstr = 'References: ' + 'x' * 80
- h = Header(hstr, continuation_ws='\t')
- eq(h.encode(), """\
-References: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx""")
-
- def test_splitting_multiple_long_lines(self):
- eq = self.ndiffAssertEqual
- hstr = """\
-from babylon.socal-raves.org (localhost [127.0.0.1]); by babylon.socal-raves.org (Postfix) with ESMTP id B570E51B81; for <mailman-admin@babylon.socal-raves.org>; Sat, 2 Feb 2002 17:00:06 -0800 (PST)
-\tfrom babylon.socal-raves.org (localhost [127.0.0.1]); by babylon.socal-raves.org (Postfix) with ESMTP id B570E51B81; for <mailman-admin@babylon.socal-raves.org>; Sat, 2 Feb 2002 17:00:06 -0800 (PST)
-\tfrom babylon.socal-raves.org (localhost [127.0.0.1]); by babylon.socal-raves.org (Postfix) with ESMTP id B570E51B81; for <mailman-admin@babylon.socal-raves.org>; Sat, 2 Feb 2002 17:00:06 -0800 (PST)
-"""
- h = Header(hstr, continuation_ws='\t')
- eq(h.encode(), """\
-from babylon.socal-raves.org (localhost [127.0.0.1]);
-\tby babylon.socal-raves.org (Postfix) with ESMTP id B570E51B81;
-\tfor <mailman-admin@babylon.socal-raves.org>;
-\tSat, 2 Feb 2002 17:00:06 -0800 (PST)
-\tfrom babylon.socal-raves.org (localhost [127.0.0.1]);
-\tby babylon.socal-raves.org (Postfix) with ESMTP id B570E51B81;
-\tfor <mailman-admin@babylon.socal-raves.org>;
-\tSat, 2 Feb 2002 17:00:06 -0800 (PST)
-\tfrom babylon.socal-raves.org (localhost [127.0.0.1]);
-\tby babylon.socal-raves.org (Postfix) with ESMTP id B570E51B81;
-\tfor <mailman-admin@babylon.socal-raves.org>;
-\tSat, 2 Feb 2002 17:00:06 -0800 (PST)""")
-
- def test_splitting_first_line_only_is_long(self):
- eq = self.ndiffAssertEqual
- hstr = """\
-from modemcable093.139-201-24.que.mc.videotron.ca ([24.201.139.93] helo=cthulhu.gerg.ca)
-\tby kronos.mems-exchange.org with esmtp (Exim 4.05)
-\tid 17k4h5-00034i-00
-\tfor test@mems-exchange.org; Wed, 28 Aug 2002 11:25:20 -0400"""
- h = Header(hstr, maxlinelen=78, header_name='Received',
- continuation_ws='\t')
- eq(h.encode(), """\
-from modemcable093.139-201-24.que.mc.videotron.ca ([24.201.139.93]
-\thelo=cthulhu.gerg.ca)
-\tby kronos.mems-exchange.org with esmtp (Exim 4.05)
-\tid 17k4h5-00034i-00
-\tfor test@mems-exchange.org; Wed, 28 Aug 2002 11:25:20 -0400""")
-
- def test_long_8bit_header(self):
- eq = self.ndiffAssertEqual
- msg = Message()
- h = Header('Britische Regierung gibt', 'iso-8859-1',
- header_name='Subject')
- h.append('gr\xfcnes Licht f\xfcr Offshore-Windkraftprojekte')
- msg['Subject'] = h
- eq(msg.as_string(), """\
-Subject: =?iso-8859-1?q?Britische_Regierung_gibt?= =?iso-8859-1?q?gr=FCnes?=
- =?iso-8859-1?q?_Licht_f=FCr_Offshore-Windkraftprojekte?=
-
-""")
-
- def test_long_8bit_header_no_charset(self):
- eq = self.ndiffAssertEqual
- msg = Message()
- msg['Reply-To'] = 'Britische Regierung gibt gr\xfcnes Licht f\xfcr Offshore-Windkraftprojekte <a-very-long-address@example.com>'
- eq(msg.as_string(), """\
-Reply-To: Britische Regierung gibt gr\xfcnes Licht f\xfcr Offshore-Windkraftprojekte <a-very-long-address@example.com>
-
-""")
-
- def test_long_to_header(self):
- eq = self.ndiffAssertEqual
- to = '"Someone Test #A" <someone@eecs.umich.edu>,<someone@eecs.umich.edu>,"Someone Test #B" <someone@umich.edu>, "Someone Test #C" <someone@eecs.umich.edu>, "Someone Test #D" <someone@eecs.umich.edu>'
- msg = Message()
- msg['To'] = to
- eq(msg.as_string(0), '''\
-To: "Someone Test #A" <someone@eecs.umich.edu>, <someone@eecs.umich.edu>,
-\t"Someone Test #B" <someone@umich.edu>,
-\t"Someone Test #C" <someone@eecs.umich.edu>,
-\t"Someone Test #D" <someone@eecs.umich.edu>
-
-''')
-
- def test_long_line_after_append(self):
- eq = self.ndiffAssertEqual
- s = 'This is an example of string which has almost the limit of header length.'
- h = Header(s)
- h.append('Add another line.')
- eq(h.encode(), """\
-This is an example of string which has almost the limit of header length.
- Add another line.""")
-
- def test_shorter_line_with_append(self):
- eq = self.ndiffAssertEqual
- s = 'This is a shorter line.'
- h = Header(s)
- h.append('Add another sentence. (Surprise?)')
- eq(h.encode(),
- 'This is a shorter line. Add another sentence. (Surprise?)')
-
- def test_long_field_name(self):
- eq = self.ndiffAssertEqual
- fn = 'X-Very-Very-Very-Long-Header-Name'
- gs = "Die Mieter treten hier ein werden mit einem Foerderband komfortabel den Korridor entlang, an s\xfcdl\xfcndischen Wandgem\xe4lden vorbei, gegen die rotierenden Klingen bef\xf6rdert. "
- h = Header(gs, 'iso-8859-1', header_name=fn)
- # BAW: this seems broken because the first line is too long
- eq(h.encode(), """\
-=?iso-8859-1?q?Die_Mieter_treten_hier_?=
- =?iso-8859-1?q?ein_werden_mit_einem_Foerderband_komfortabel_den_Korridor_?=
- =?iso-8859-1?q?entlang=2C_an_s=FCdl=FCndischen_Wandgem=E4lden_vorbei=2C_g?=
- =?iso-8859-1?q?egen_die_rotierenden_Klingen_bef=F6rdert=2E_?=""")
-
- def test_long_received_header(self):
- h = 'from FOO.TLD (vizworld.acl.foo.tld [123.452.678.9]) by hrothgar.la.mastaler.com (tmda-ofmipd) with ESMTP; Wed, 05 Mar 2003 18:10:18 -0700'
- msg = Message()
- msg['Received-1'] = Header(h, continuation_ws='\t')
- msg['Received-2'] = h
- self.assertEqual(msg.as_string(), """\
-Received-1: from FOO.TLD (vizworld.acl.foo.tld [123.452.678.9]) by
-\throthgar.la.mastaler.com (tmda-ofmipd) with ESMTP;
-\tWed, 05 Mar 2003 18:10:18 -0700
-Received-2: from FOO.TLD (vizworld.acl.foo.tld [123.452.678.9]) by
-\throthgar.la.mastaler.com (tmda-ofmipd) with ESMTP;
-\tWed, 05 Mar 2003 18:10:18 -0700
-
-""")
-
- def test_string_headerinst_eq(self):
- h = '<15975.17901.207240.414604@sgigritzmann1.mathematik.tu-muenchen.de> (David Bremner\'s message of "Thu, 6 Mar 2003 13:58:21 +0100")'
- msg = Message()
- msg['Received-1'] = Header(h, header_name='Received-1',
- continuation_ws='\t')
- msg['Received-2'] = h
- self.assertEqual(msg.as_string(), """\
-Received-1: <15975.17901.207240.414604@sgigritzmann1.mathematik.tu-muenchen.de>
-\t(David Bremner's message of "Thu, 6 Mar 2003 13:58:21 +0100")
-Received-2: <15975.17901.207240.414604@sgigritzmann1.mathematik.tu-muenchen.de>
-\t(David Bremner's message of "Thu, 6 Mar 2003 13:58:21 +0100")
-
-""")
-
- def test_long_unbreakable_lines_with_continuation(self):
- eq = self.ndiffAssertEqual
- msg = Message()
- t = """\
- iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
- locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp"""
- msg['Face-1'] = t
- msg['Face-2'] = Header(t, header_name='Face-2')
- eq(msg.as_string(), """\
-Face-1: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
-\tlocQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp
-Face-2: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
- locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp
-
-""")
-
- def test_another_long_multiline_header(self):
- eq = self.ndiffAssertEqual
- m = '''\
-Received: from siimage.com ([172.25.1.3]) by zima.siliconimage.com with Microsoft SMTPSVC(5.0.2195.4905);
-\tWed, 16 Oct 2002 07:41:11 -0700'''
- msg = email.message_from_string(m)
- eq(msg.as_string(), '''\
-Received: from siimage.com ([172.25.1.3]) by zima.siliconimage.com with
-\tMicrosoft SMTPSVC(5.0.2195.4905); Wed, 16 Oct 2002 07:41:11 -0700
-
-''')
-
- def test_long_lines_with_different_header(self):
- eq = self.ndiffAssertEqual
- h = """\
-List-Unsubscribe: <https://lists.sourceforge.net/lists/listinfo/spamassassin-talk>,
- <mailto:spamassassin-talk-request@lists.sourceforge.net?subject=unsubscribe>"""
- msg = Message()
- msg['List'] = h
- msg['List'] = Header(h, header_name='List')
- eq(msg.as_string(), """\
-List: List-Unsubscribe: <https://lists.sourceforge.net/lists/listinfo/spamassassin-talk>,
-\t<mailto:spamassassin-talk-request@lists.sourceforge.net?subject=unsubscribe>
-List: List-Unsubscribe: <https://lists.sourceforge.net/lists/listinfo/spamassassin-talk>,
- <mailto:spamassassin-talk-request@lists.sourceforge.net?subject=unsubscribe>
-
-""")
-
-
-
-# Test mangling of "From " lines in the body of a message
-class TestFromMangling(unittest.TestCase):
- def setUp(self):
- self.msg = Message()
- self.msg['From'] = 'aaa@bbb.org'
- self.msg.set_payload("""\
-From the desk of A.A.A.:
-Blah blah blah
-""")
-
- def test_mangled_from(self):
- s = StringIO()
- g = Generator(s, mangle_from_=True)
- g.flatten(self.msg)
- self.assertEqual(s.getvalue(), """\
-From: aaa@bbb.org
-
->From the desk of A.A.A.:
-Blah blah blah
-""")
-
- def test_dont_mangle_from(self):
- s = StringIO()
- g = Generator(s, mangle_from_=False)
- g.flatten(self.msg)
- self.assertEqual(s.getvalue(), """\
-From: aaa@bbb.org
-
-From the desk of A.A.A.:
-Blah blah blah
-""")
-
-
-
-# Test the basic MIMEAudio class
-class TestMIMEAudio(unittest.TestCase):
- def setUp(self):
- # Make sure we pick up the audiotest.au that lives in email/test/data.
- # In Python, there's an audiotest.au living in Lib/test but that isn't
- # included in some binary distros that don't include the test
- # package. The trailing empty string on the .join() is significant
- # since findfile() will do a dirname().
- datadir = os.path.join(os.path.dirname(landmark), 'data', '')
- fp = open(findfile('audiotest.au', datadir), 'rb')
- try:
- self._audiodata = fp.read()
- finally:
- fp.close()
- self._au = MIMEAudio(self._audiodata)
-
- def test_guess_minor_type(self):
- self.assertEqual(self._au.get_content_type(), 'audio/basic')
-
- def test_encoding(self):
- payload = self._au.get_payload()
- self.assertEqual(base64.decodestring(payload), self._audiodata)
-
- def test_checkSetMinor(self):
- au = MIMEAudio(self._audiodata, 'fish')
- self.assertEqual(au.get_content_type(), 'audio/fish')
-
- def test_add_header(self):
- eq = self.assertEqual
- unless = self.failUnless
- self._au.add_header('Content-Disposition', 'attachment',
- filename='audiotest.au')
- eq(self._au['content-disposition'],
- 'attachment; filename="audiotest.au"')
- eq(self._au.get_params(header='content-disposition'),
- [('attachment', ''), ('filename', 'audiotest.au')])
- eq(self._au.get_param('filename', header='content-disposition'),
- 'audiotest.au')
- missing = []
- eq(self._au.get_param('attachment', header='content-disposition'), '')
- unless(self._au.get_param('foo', failobj=missing,
- header='content-disposition') is missing)
- # Try some missing stuff
- unless(self._au.get_param('foobar', missing) is missing)
- unless(self._au.get_param('attachment', missing,
- header='foobar') is missing)
-
-
-
-# Test the basic MIMEImage class
-class TestMIMEImage(unittest.TestCase):
- def setUp(self):
- fp = openfile('PyBanner048.gif')
- try:
- self._imgdata = fp.read()
- finally:
- fp.close()
- self._im = MIMEImage(self._imgdata)
-
- def test_guess_minor_type(self):
- self.assertEqual(self._im.get_content_type(), 'image/gif')
-
- def test_encoding(self):
- payload = self._im.get_payload()
- self.assertEqual(base64.decodestring(payload), self._imgdata)
-
- def test_checkSetMinor(self):
- im = MIMEImage(self._imgdata, 'fish')
- self.assertEqual(im.get_content_type(), 'image/fish')
-
- def test_add_header(self):
- eq = self.assertEqual
- unless = self.failUnless
- self._im.add_header('Content-Disposition', 'attachment',
- filename='dingusfish.gif')
- eq(self._im['content-disposition'],
- 'attachment; filename="dingusfish.gif"')
- eq(self._im.get_params(header='content-disposition'),
- [('attachment', ''), ('filename', 'dingusfish.gif')])
- eq(self._im.get_param('filename', header='content-disposition'),
- 'dingusfish.gif')
- missing = []
- eq(self._im.get_param('attachment', header='content-disposition'), '')
- unless(self._im.get_param('foo', failobj=missing,
- header='content-disposition') is missing)
- # Try some missing stuff
- unless(self._im.get_param('foobar', missing) is missing)
- unless(self._im.get_param('attachment', missing,
- header='foobar') is missing)
-
-
-
-# Test the basic MIMEText class
-class TestMIMEText(unittest.TestCase):
- def setUp(self):
- self._msg = MIMEText('hello there')
-
- def test_types(self):
- eq = self.assertEqual
- unless = self.failUnless
- eq(self._msg.get_content_type(), 'text/plain')
- eq(self._msg.get_param('charset'), 'us-ascii')
- missing = []
- unless(self._msg.get_param('foobar', missing) is missing)
- unless(self._msg.get_param('charset', missing, header='foobar')
- is missing)
-
- def test_payload(self):
- self.assertEqual(self._msg.get_payload(), 'hello there')
- self.failUnless(not self._msg.is_multipart())
-
- def test_charset(self):
- eq = self.assertEqual
- msg = MIMEText('hello there', _charset='us-ascii')
- eq(msg.get_charset().input_charset, 'us-ascii')
- eq(msg['content-type'], 'text/plain; charset="us-ascii"')
-
-
-
-# Test complicated multipart/* messages
-class TestMultipart(TestEmailBase):
- def setUp(self):
- fp = openfile('PyBanner048.gif')
- try:
- data = fp.read()
- finally:
- fp.close()
-
- container = MIMEBase('multipart', 'mixed', boundary='BOUNDARY')
- image = MIMEImage(data, name='dingusfish.gif')
- image.add_header('content-disposition', 'attachment',
- filename='dingusfish.gif')
- intro = MIMEText('''\
-Hi there,
-
-This is the dingus fish.
-''')
- container.attach(intro)
- container.attach(image)
- container['From'] = 'Barry <barry@digicool.com>'
- container['To'] = 'Dingus Lovers <cravindogs@cravindogs.com>'
- container['Subject'] = 'Here is your dingus fish'
-
- now = 987809702.54848599
- timetuple = time.localtime(now)
- if timetuple[-1] == 0:
- tzsecs = time.timezone
- else:
- tzsecs = time.altzone
- if tzsecs > 0:
- sign = '-'
- else:
- sign = '+'
- tzoffset = ' %s%04d' % (sign, tzsecs / 36)
- container['Date'] = time.strftime(
- '%a, %d %b %Y %H:%M:%S',
- time.localtime(now)) + tzoffset
- self._msg = container
- self._im = image
- self._txt = intro
-
- def test_hierarchy(self):
- # convenience
- eq = self.assertEqual
- unless = self.failUnless
- raises = self.assertRaises
- # tests
- m = self._msg
- unless(m.is_multipart())
- eq(m.get_content_type(), 'multipart/mixed')
- eq(len(m.get_payload()), 2)
- raises(IndexError, m.get_payload, 2)
- m0 = m.get_payload(0)
- m1 = m.get_payload(1)
- unless(m0 is self._txt)
- unless(m1 is self._im)
- eq(m.get_payload(), [m0, m1])
- unless(not m0.is_multipart())
- unless(not m1.is_multipart())
-
- def test_empty_multipart_idempotent(self):
- text = """\
-Content-Type: multipart/mixed; boundary="BOUNDARY"
-MIME-Version: 1.0
-Subject: A subject
-To: aperson@dom.ain
-From: bperson@dom.ain
-
-
---BOUNDARY
-
-
---BOUNDARY--
-"""
- msg = Parser().parsestr(text)
- self.ndiffAssertEqual(text, msg.as_string())
-
- def test_no_parts_in_a_multipart_with_none_epilogue(self):
- outer = MIMEBase('multipart', 'mixed')
- outer['Subject'] = 'A subject'
- outer['To'] = 'aperson@dom.ain'
- outer['From'] = 'bperson@dom.ain'
- outer.set_boundary('BOUNDARY')
- self.ndiffAssertEqual(outer.as_string(), '''\
-Content-Type: multipart/mixed; boundary="BOUNDARY"
-MIME-Version: 1.0
-Subject: A subject
-To: aperson@dom.ain
-From: bperson@dom.ain
-
---BOUNDARY
-
---BOUNDARY--''')
-
- def test_no_parts_in_a_multipart_with_empty_epilogue(self):
- outer = MIMEBase('multipart', 'mixed')
- outer['Subject'] = 'A subject'
- outer['To'] = 'aperson@dom.ain'
- outer['From'] = 'bperson@dom.ain'
- outer.preamble = ''
- outer.epilogue = ''
- outer.set_boundary('BOUNDARY')
- self.ndiffAssertEqual(outer.as_string(), '''\
-Content-Type: multipart/mixed; boundary="BOUNDARY"
-MIME-Version: 1.0
-Subject: A subject
-To: aperson@dom.ain
-From: bperson@dom.ain
-
-
---BOUNDARY
-
---BOUNDARY--
-''')
-
- def test_one_part_in_a_multipart(self):
- eq = self.ndiffAssertEqual
- outer = MIMEBase('multipart', 'mixed')
- outer['Subject'] = 'A subject'
- outer['To'] = 'aperson@dom.ain'
- outer['From'] = 'bperson@dom.ain'
- outer.set_boundary('BOUNDARY')
- msg = MIMEText('hello world')
- outer.attach(msg)
- eq(outer.as_string(), '''\
-Content-Type: multipart/mixed; boundary="BOUNDARY"
-MIME-Version: 1.0
-Subject: A subject
-To: aperson@dom.ain
-From: bperson@dom.ain
-
---BOUNDARY
-Content-Type: text/plain; charset="us-ascii"
-MIME-Version: 1.0
-Content-Transfer-Encoding: 7bit
-
-hello world
---BOUNDARY--''')
-
- def test_seq_parts_in_a_multipart_with_empty_preamble(self):
- eq = self.ndiffAssertEqual
- outer = MIMEBase('multipart', 'mixed')
- outer['Subject'] = 'A subject'
- outer['To'] = 'aperson@dom.ain'
- outer['From'] = 'bperson@dom.ain'
- outer.preamble = ''
- msg = MIMEText('hello world')
- outer.attach(msg)
- outer.set_boundary('BOUNDARY')
- eq(outer.as_string(), '''\
-Content-Type: multipart/mixed; boundary="BOUNDARY"
-MIME-Version: 1.0
-Subject: A subject
-To: aperson@dom.ain
-From: bperson@dom.ain
-
-
---BOUNDARY
-Content-Type: text/plain; charset="us-ascii"
-MIME-Version: 1.0
-Content-Transfer-Encoding: 7bit
-
-hello world
---BOUNDARY--''')
-
-
- def test_seq_parts_in_a_multipart_with_none_preamble(self):
- eq = self.ndiffAssertEqual
- outer = MIMEBase('multipart', 'mixed')
- outer['Subject'] = 'A subject'
- outer['To'] = 'aperson@dom.ain'
- outer['From'] = 'bperson@dom.ain'
- outer.preamble = None
- msg = MIMEText('hello world')
- outer.attach(msg)
- outer.set_boundary('BOUNDARY')
- eq(outer.as_string(), '''\
-Content-Type: multipart/mixed; boundary="BOUNDARY"
-MIME-Version: 1.0
-Subject: A subject
-To: aperson@dom.ain
-From: bperson@dom.ain
-
---BOUNDARY
-Content-Type: text/plain; charset="us-ascii"
-MIME-Version: 1.0
-Content-Transfer-Encoding: 7bit
-
-hello world
---BOUNDARY--''')
-
-
- def test_seq_parts_in_a_multipart_with_none_epilogue(self):
- eq = self.ndiffAssertEqual
- outer = MIMEBase('multipart', 'mixed')
- outer['Subject'] = 'A subject'
- outer['To'] = 'aperson@dom.ain'
- outer['From'] = 'bperson@dom.ain'
- outer.epilogue = None
- msg = MIMEText('hello world')
- outer.attach(msg)
- outer.set_boundary('BOUNDARY')
- eq(outer.as_string(), '''\
-Content-Type: multipart/mixed; boundary="BOUNDARY"
-MIME-Version: 1.0
-Subject: A subject
-To: aperson@dom.ain
-From: bperson@dom.ain
-
---BOUNDARY
-Content-Type: text/plain; charset="us-ascii"
-MIME-Version: 1.0
-Content-Transfer-Encoding: 7bit
-
-hello world
---BOUNDARY--''')
-
-
- def test_seq_parts_in_a_multipart_with_empty_epilogue(self):
- eq = self.ndiffAssertEqual
- outer = MIMEBase('multipart', 'mixed')
- outer['Subject'] = 'A subject'
- outer['To'] = 'aperson@dom.ain'
- outer['From'] = 'bperson@dom.ain'
- outer.epilogue = ''
- msg = MIMEText('hello world')
- outer.attach(msg)
- outer.set_boundary('BOUNDARY')
- eq(outer.as_string(), '''\
-Content-Type: multipart/mixed; boundary="BOUNDARY"
-MIME-Version: 1.0
-Subject: A subject
-To: aperson@dom.ain
-From: bperson@dom.ain
-
---BOUNDARY
-Content-Type: text/plain; charset="us-ascii"
-MIME-Version: 1.0
-Content-Transfer-Encoding: 7bit
-
-hello world
---BOUNDARY--
-''')
-
-
- def test_seq_parts_in_a_multipart_with_nl_epilogue(self):
- eq = self.ndiffAssertEqual
- outer = MIMEBase('multipart', 'mixed')
- outer['Subject'] = 'A subject'
- outer['To'] = 'aperson@dom.ain'
- outer['From'] = 'bperson@dom.ain'
- outer.epilogue = '\n'
- msg = MIMEText('hello world')
- outer.attach(msg)
- outer.set_boundary('BOUNDARY')
- eq(outer.as_string(), '''\
-Content-Type: multipart/mixed; boundary="BOUNDARY"
-MIME-Version: 1.0
-Subject: A subject
-To: aperson@dom.ain
-From: bperson@dom.ain
-
---BOUNDARY
-Content-Type: text/plain; charset="us-ascii"
-MIME-Version: 1.0
-Content-Transfer-Encoding: 7bit
-
-hello world
---BOUNDARY--
-
-''')
-
- def test_message_external_body(self):
- eq = self.assertEqual
- msg = self._msgobj('msg_36.txt')
- eq(len(msg.get_payload()), 2)
- msg1 = msg.get_payload(1)
- eq(msg1.get_content_type(), 'multipart/alternative')
- eq(len(msg1.get_payload()), 2)
- for subpart in msg1.get_payload():
- eq(subpart.get_content_type(), 'message/external-body')
- eq(len(subpart.get_payload()), 1)
- subsubpart = subpart.get_payload(0)
- eq(subsubpart.get_content_type(), 'text/plain')
-
- def test_double_boundary(self):
- # msg_37.txt is a multipart that contains two dash-boundary's in a
- # row. Our interpretation of RFC 2046 calls for ignoring the second
- # and subsequent boundaries.
- msg = self._msgobj('msg_37.txt')
- self.assertEqual(len(msg.get_payload()), 3)
-
- def test_nested_inner_contains_outer_boundary(self):
- eq = self.ndiffAssertEqual
- # msg_38.txt has an inner part that contains outer boundaries. My
- # interpretation of RFC 2046 (based on sections 5.1 and 5.1.2) say
- # these are illegal and should be interpreted as unterminated inner
- # parts.
- msg = self._msgobj('msg_38.txt')
- sfp = StringIO()
- Iterators._structure(msg, sfp)
- eq(sfp.getvalue(), """\
-multipart/mixed
- multipart/mixed
- multipart/alternative
- text/plain
- text/plain
- text/plain
- text/plain
-""")
-
- def test_nested_with_same_boundary(self):
- eq = self.ndiffAssertEqual
- # msg 39.txt is similarly evil in that it's got inner parts that use
- # the same boundary as outer parts. Again, I believe the way this is
- # parsed is closest to the spirit of RFC 2046
- msg = self._msgobj('msg_39.txt')
- sfp = StringIO()
- Iterators._structure(msg, sfp)
- eq(sfp.getvalue(), """\
-multipart/mixed
- multipart/mixed
- multipart/alternative
- application/octet-stream
- application/octet-stream
- text/plain
-""")
-
- def test_boundary_in_non_multipart(self):
- msg = self._msgobj('msg_40.txt')
- self.assertEqual(msg.as_string(), '''\
-MIME-Version: 1.0
-Content-Type: text/html; boundary="--961284236552522269"
-
-----961284236552522269
-Content-Type: text/html;
-Content-Transfer-Encoding: 7Bit
-
-<html></html>
-
-----961284236552522269--
-''')
-
- def test_boundary_with_leading_space(self):
- eq = self.assertEqual
- msg = email.message_from_string('''\
-MIME-Version: 1.0
-Content-Type: multipart/mixed; boundary=" XXXX"
-
--- XXXX
-Content-Type: text/plain
-
-
--- XXXX
-Content-Type: text/plain
-
--- XXXX--
-''')
- self.failUnless(msg.is_multipart())
- eq(msg.get_boundary(), ' XXXX')
- eq(len(msg.get_payload()), 2)
-
- def test_boundary_without_trailing_newline(self):
- m = Parser().parsestr("""\
-Content-Type: multipart/mixed; boundary="===============0012394164=="
-MIME-Version: 1.0
-
---===============0012394164==
-Content-Type: image/file1.jpg
-MIME-Version: 1.0
-Content-Transfer-Encoding: base64
-
-YXNkZg==
---===============0012394164==--""")
- self.assertEquals(m.get_payload(0).get_payload(), 'YXNkZg==')
-
-
-
-# Test some badly formatted messages
-class TestNonConformant(TestEmailBase):
- def test_parse_missing_minor_type(self):
- eq = self.assertEqual
- msg = self._msgobj('msg_14.txt')
- eq(msg.get_content_type(), 'text/plain')
- eq(msg.get_content_maintype(), 'text')
- eq(msg.get_content_subtype(), 'plain')
-
- def test_same_boundary_inner_outer(self):
- unless = self.failUnless
- msg = self._msgobj('msg_15.txt')
- # XXX We can probably eventually do better
- inner = msg.get_payload(0)
- unless(hasattr(inner, 'defects'))
- self.assertEqual(len(inner.defects), 1)
- unless(isinstance(inner.defects[0],
- Errors.StartBoundaryNotFoundDefect))
-
- def test_multipart_no_boundary(self):
- unless = self.failUnless
- msg = self._msgobj('msg_25.txt')
- unless(isinstance(msg.get_payload(), str))
- self.assertEqual(len(msg.defects), 2)
- unless(isinstance(msg.defects[0], Errors.NoBoundaryInMultipartDefect))
- unless(isinstance(msg.defects[1],
- Errors.MultipartInvariantViolationDefect))
-
- def test_invalid_content_type(self):
- eq = self.assertEqual
- neq = self.ndiffAssertEqual
- msg = Message()
- # RFC 2045, $5.2 says invalid yields text/plain
- msg['Content-Type'] = 'text'
- eq(msg.get_content_maintype(), 'text')
- eq(msg.get_content_subtype(), 'plain')
- eq(msg.get_content_type(), 'text/plain')
- # Clear the old value and try something /really/ invalid
- del msg['content-type']
- msg['Content-Type'] = 'foo'
- eq(msg.get_content_maintype(), 'text')
- eq(msg.get_content_subtype(), 'plain')
- eq(msg.get_content_type(), 'text/plain')
- # Still, make sure that the message is idempotently generated
- s = StringIO()
- g = Generator(s)
- g.flatten(msg)
- neq(s.getvalue(), 'Content-Type: foo\n\n')
-
- def test_no_start_boundary(self):
- eq = self.ndiffAssertEqual
- msg = self._msgobj('msg_31.txt')
- eq(msg.get_payload(), """\
---BOUNDARY
-Content-Type: text/plain
-
-message 1
-
---BOUNDARY
-Content-Type: text/plain
-
-message 2
-
---BOUNDARY--
-""")
-
- def test_no_separating_blank_line(self):
- eq = self.ndiffAssertEqual
- msg = self._msgobj('msg_35.txt')
- eq(msg.as_string(), """\
-From: aperson@dom.ain
-To: bperson@dom.ain
-Subject: here's something interesting
-
-counter to RFC 2822, there's no separating newline here
-""")
-
- def test_lying_multipart(self):
- unless = self.failUnless
- msg = self._msgobj('msg_41.txt')
- unless(hasattr(msg, 'defects'))
- self.assertEqual(len(msg.defects), 2)
- unless(isinstance(msg.defects[0], Errors.NoBoundaryInMultipartDefect))
- unless(isinstance(msg.defects[1],
- Errors.MultipartInvariantViolationDefect))
-
- def test_missing_start_boundary(self):
- outer = self._msgobj('msg_42.txt')
- # The message structure is:
- #
- # multipart/mixed
- # text/plain
- # message/rfc822
- # multipart/mixed [*]
- #
- # [*] This message is missing its start boundary
- bad = outer.get_payload(1).get_payload(0)
- self.assertEqual(len(bad.defects), 1)
- self.failUnless(isinstance(bad.defects[0],
- Errors.StartBoundaryNotFoundDefect))
-
- def test_first_line_is_continuation_header(self):
- eq = self.assertEqual
- m = ' Line 1\nLine 2\nLine 3'
- msg = email.message_from_string(m)
- eq(msg.keys(), [])
- eq(msg.get_payload(), 'Line 2\nLine 3')
- eq(len(msg.defects), 1)
- self.failUnless(isinstance(msg.defects[0],
- Errors.FirstHeaderLineIsContinuationDefect))
- eq(msg.defects[0].line, ' Line 1\n')
-
-
-
-
-# Test RFC 2047 header encoding and decoding
-class TestRFC2047(unittest.TestCase):
- def test_rfc2047_multiline(self):
- eq = self.assertEqual
- s = """Re: =?mac-iceland?q?r=8Aksm=9Arg=8Cs?= baz
- foo bar =?mac-iceland?q?r=8Aksm=9Arg=8Cs?="""
- dh = decode_header(s)
- eq(dh, [
- ('Re:', None),
- ('r\x8aksm\x9arg\x8cs', 'mac-iceland'),
- ('baz foo bar', None),
- ('r\x8aksm\x9arg\x8cs', 'mac-iceland')])
- eq(str(make_header(dh)),
- """Re: =?mac-iceland?q?r=8Aksm=9Arg=8Cs?= baz foo bar
- =?mac-iceland?q?r=8Aksm=9Arg=8Cs?=""")
-
- def test_whitespace_eater_unicode(self):
- eq = self.assertEqual
- s = '=?ISO-8859-1?Q?Andr=E9?= Pirard <pirard@dom.ain>'
- dh = decode_header(s)
- eq(dh, [('Andr\xe9', 'iso-8859-1'), ('Pirard <pirard@dom.ain>', None)])
- hu = str(make_header(dh)).encode('latin-1')
- eq(hu, 'Andr\xe9 Pirard <pirard@dom.ain>')
-
- def test_whitespace_eater_unicode_2(self):
- eq = self.assertEqual
- s = 'The =?iso-8859-1?b?cXVpY2sgYnJvd24gZm94?= jumped over the =?iso-8859-1?b?bGF6eSBkb2c=?='
- dh = decode_header(s)
- eq(dh, [('The', None), ('quick brown fox', 'iso-8859-1'),
- ('jumped over the', None), ('lazy dog', 'iso-8859-1')])
- hu = make_header(dh).__unicode__()
- eq(hu, 'The quick brown fox jumped over the lazy dog')
-
- def test_rfc2047_without_whitespace(self):
- s = 'Sm=?ISO-8859-1?B?9g==?=rg=?ISO-8859-1?B?5Q==?=sbord'
- dh = decode_header(s)
- self.assertEqual(dh, [(s, None)])
-
- def test_rfc2047_with_whitespace(self):
- s = 'Sm =?ISO-8859-1?B?9g==?= rg =?ISO-8859-1?B?5Q==?= sbord'
- dh = decode_header(s)
- self.assertEqual(dh, [('Sm', None), ('\xf6', 'iso-8859-1'),
- ('rg', None), ('\xe5', 'iso-8859-1'),
- ('sbord', None)])
-
-
-
-# Test the MIMEMessage class
-class TestMIMEMessage(TestEmailBase):
- def setUp(self):
- fp = openfile('msg_11.txt')
- try:
- self._text = fp.read()
- finally:
- fp.close()
-
- def test_type_error(self):
- self.assertRaises(TypeError, MIMEMessage, 'a plain string')
-
- def test_valid_argument(self):
- eq = self.assertEqual
- unless = self.failUnless
- subject = 'A sub-message'
- m = Message()
- m['Subject'] = subject
- r = MIMEMessage(m)
- eq(r.get_content_type(), 'message/rfc822')
- payload = r.get_payload()
- unless(isinstance(payload, list))
- eq(len(payload), 1)
- subpart = payload[0]
- unless(subpart is m)
- eq(subpart['subject'], subject)
-
- def test_bad_multipart(self):
- eq = self.assertEqual
- msg1 = Message()
- msg1['Subject'] = 'subpart 1'
- msg2 = Message()
- msg2['Subject'] = 'subpart 2'
- r = MIMEMessage(msg1)
- self.assertRaises(Errors.MultipartConversionError, r.attach, msg2)
-
- def test_generate(self):
- # First craft the message to be encapsulated
- m = Message()
- m['Subject'] = 'An enclosed message'
- m.set_payload('Here is the body of the message.\n')
- r = MIMEMessage(m)
- r['Subject'] = 'The enclosing message'
- s = StringIO()
- g = Generator(s)
- g.flatten(r)
- self.assertEqual(s.getvalue(), """\
-Content-Type: message/rfc822
-MIME-Version: 1.0
-Subject: The enclosing message
-
-Subject: An enclosed message
-
-Here is the body of the message.
-""")
-
- def test_parse_message_rfc822(self):
- eq = self.assertEqual
- unless = self.failUnless
- msg = self._msgobj('msg_11.txt')
- eq(msg.get_content_type(), 'message/rfc822')
- payload = msg.get_payload()
- unless(isinstance(payload, list))
- eq(len(payload), 1)
- submsg = payload[0]
- self.failUnless(isinstance(submsg, Message))
- eq(submsg['subject'], 'An enclosed message')
- eq(submsg.get_payload(), 'Here is the body of the message.\n')
-
- def test_dsn(self):
- eq = self.assertEqual
- unless = self.failUnless
- # msg 16 is a Delivery Status Notification, see RFC 1894
- msg = self._msgobj('msg_16.txt')
- eq(msg.get_content_type(), 'multipart/report')
- unless(msg.is_multipart())
- eq(len(msg.get_payload()), 3)
- # Subpart 1 is a text/plain, human readable section
- subpart = msg.get_payload(0)
- eq(subpart.get_content_type(), 'text/plain')
- eq(subpart.get_payload(), """\
-This report relates to a message you sent with the following header fields:
-
- Message-id: <002001c144a6$8752e060$56104586@oxy.edu>
- Date: Sun, 23 Sep 2001 20:10:55 -0700
- From: "Ian T. Henry" <henryi@oxy.edu>
- To: SoCal Raves <scr@socal-raves.org>
- Subject: [scr] yeah for Ians!!
-
-Your message cannot be delivered to the following recipients:
-
- Recipient address: jangel1@cougar.noc.ucla.edu
- Reason: recipient reached disk quota
-
-""")
- # Subpart 2 contains the machine parsable DSN information. It
- # consists of two blocks of headers, represented by two nested Message
- # objects.
- subpart = msg.get_payload(1)
- eq(subpart.get_content_type(), 'message/delivery-status')
- eq(len(subpart.get_payload()), 2)
- # message/delivery-status should treat each block as a bunch of
- # headers, i.e. a bunch of Message objects.
- dsn1 = subpart.get_payload(0)
- unless(isinstance(dsn1, Message))
- eq(dsn1['original-envelope-id'], '0GK500B4HD0888@cougar.noc.ucla.edu')
- eq(dsn1.get_param('dns', header='reporting-mta'), '')
- # Try a missing one <wink>
- eq(dsn1.get_param('nsd', header='reporting-mta'), None)
- dsn2 = subpart.get_payload(1)
- unless(isinstance(dsn2, Message))
- eq(dsn2['action'], 'failed')
- eq(dsn2.get_params(header='original-recipient'),
- [('rfc822', ''), ('jangel1@cougar.noc.ucla.edu', '')])
- eq(dsn2.get_param('rfc822', header='final-recipient'), '')
- # Subpart 3 is the original message
- subpart = msg.get_payload(2)
- eq(subpart.get_content_type(), 'message/rfc822')
- payload = subpart.get_payload()
- unless(isinstance(payload, list))
- eq(len(payload), 1)
- subsubpart = payload[0]
- unless(isinstance(subsubpart, Message))
- eq(subsubpart.get_content_type(), 'text/plain')
- eq(subsubpart['message-id'],
- '<002001c144a6$8752e060$56104586@oxy.edu>')
-
- def test_epilogue(self):
- eq = self.ndiffAssertEqual
- fp = openfile('msg_21.txt')
- try:
- text = fp.read()
- finally:
- fp.close()
- msg = Message()
- msg['From'] = 'aperson@dom.ain'
- msg['To'] = 'bperson@dom.ain'
- msg['Subject'] = 'Test'
- msg.preamble = 'MIME message'
- msg.epilogue = 'End of MIME message\n'
- msg1 = MIMEText('One')
- msg2 = MIMEText('Two')
- msg.add_header('Content-Type', 'multipart/mixed', boundary='BOUNDARY')
- msg.attach(msg1)
- msg.attach(msg2)
- sfp = StringIO()
- g = Generator(sfp)
- g.flatten(msg)
- eq(sfp.getvalue(), text)
-
- def test_no_nl_preamble(self):
- eq = self.ndiffAssertEqual
- msg = Message()
- msg['From'] = 'aperson@dom.ain'
- msg['To'] = 'bperson@dom.ain'
- msg['Subject'] = 'Test'
- msg.preamble = 'MIME message'
- msg.epilogue = ''
- msg1 = MIMEText('One')
- msg2 = MIMEText('Two')
- msg.add_header('Content-Type', 'multipart/mixed', boundary='BOUNDARY')
- msg.attach(msg1)
- msg.attach(msg2)
- eq(msg.as_string(), """\
-From: aperson@dom.ain
-To: bperson@dom.ain
-Subject: Test
-Content-Type: multipart/mixed; boundary="BOUNDARY"
-
-MIME message
---BOUNDARY
-Content-Type: text/plain; charset="us-ascii"
-MIME-Version: 1.0
-Content-Transfer-Encoding: 7bit
-
-One
---BOUNDARY
-Content-Type: text/plain; charset="us-ascii"
-MIME-Version: 1.0
-Content-Transfer-Encoding: 7bit
-
-Two
---BOUNDARY--
-""")
-
- def test_default_type(self):
- eq = self.assertEqual
- fp = openfile('msg_30.txt')
- try:
- msg = email.message_from_file(fp)
- finally:
- fp.close()
- container1 = msg.get_payload(0)
- eq(container1.get_default_type(), 'message/rfc822')
- eq(container1.get_content_type(), 'message/rfc822')
- container2 = msg.get_payload(1)
- eq(container2.get_default_type(), 'message/rfc822')
- eq(container2.get_content_type(), 'message/rfc822')
- container1a = container1.get_payload(0)
- eq(container1a.get_default_type(), 'text/plain')
- eq(container1a.get_content_type(), 'text/plain')
- container2a = container2.get_payload(0)
- eq(container2a.get_default_type(), 'text/plain')
- eq(container2a.get_content_type(), 'text/plain')
-
- def test_default_type_with_explicit_container_type(self):
- eq = self.assertEqual
- fp = openfile('msg_28.txt')
- try:
- msg = email.message_from_file(fp)
- finally:
- fp.close()
- container1 = msg.get_payload(0)
- eq(container1.get_default_type(), 'message/rfc822')
- eq(container1.get_content_type(), 'message/rfc822')
- container2 = msg.get_payload(1)
- eq(container2.get_default_type(), 'message/rfc822')
- eq(container2.get_content_type(), 'message/rfc822')
- container1a = container1.get_payload(0)
- eq(container1a.get_default_type(), 'text/plain')
- eq(container1a.get_content_type(), 'text/plain')
- container2a = container2.get_payload(0)
- eq(container2a.get_default_type(), 'text/plain')
- eq(container2a.get_content_type(), 'text/plain')
-
- def test_default_type_non_parsed(self):
- eq = self.assertEqual
- neq = self.ndiffAssertEqual
- # Set up container
- container = MIMEMultipart('digest', 'BOUNDARY')
- container.epilogue = ''
- # Set up subparts
- subpart1a = MIMEText('message 1\n')
- subpart2a = MIMEText('message 2\n')
- subpart1 = MIMEMessage(subpart1a)
- subpart2 = MIMEMessage(subpart2a)
- container.attach(subpart1)
- container.attach(subpart2)
- eq(subpart1.get_content_type(), 'message/rfc822')
- eq(subpart1.get_default_type(), 'message/rfc822')
- eq(subpart2.get_content_type(), 'message/rfc822')
- eq(subpart2.get_default_type(), 'message/rfc822')
- neq(container.as_string(0), '''\
-Content-Type: multipart/digest; boundary="BOUNDARY"
-MIME-Version: 1.0
-
---BOUNDARY
-Content-Type: message/rfc822
-MIME-Version: 1.0
-
-Content-Type: text/plain; charset="us-ascii"
-MIME-Version: 1.0
-Content-Transfer-Encoding: 7bit
-
-message 1
-
---BOUNDARY
-Content-Type: message/rfc822
-MIME-Version: 1.0
-
-Content-Type: text/plain; charset="us-ascii"
-MIME-Version: 1.0
-Content-Transfer-Encoding: 7bit
-
-message 2
-
---BOUNDARY--
-''')
- del subpart1['content-type']
- del subpart1['mime-version']
- del subpart2['content-type']
- del subpart2['mime-version']
- eq(subpart1.get_content_type(), 'message/rfc822')
- eq(subpart1.get_default_type(), 'message/rfc822')
- eq(subpart2.get_content_type(), 'message/rfc822')
- eq(subpart2.get_default_type(), 'message/rfc822')
- neq(container.as_string(0), '''\
-Content-Type: multipart/digest; boundary="BOUNDARY"
-MIME-Version: 1.0
-
---BOUNDARY
-
-Content-Type: text/plain; charset="us-ascii"
-MIME-Version: 1.0
-Content-Transfer-Encoding: 7bit
-
-message 1
-
---BOUNDARY
-
-Content-Type: text/plain; charset="us-ascii"
-MIME-Version: 1.0
-Content-Transfer-Encoding: 7bit
-
-message 2
-
---BOUNDARY--
-''')
-
- def test_mime_attachments_in_constructor(self):
- eq = self.assertEqual
- text1 = MIMEText('')
- text2 = MIMEText('')
- msg = MIMEMultipart(_subparts=(text1, text2))
- eq(len(msg.get_payload()), 2)
- eq(msg.get_payload(0), text1)
- eq(msg.get_payload(1), text2)
-
-
-
-# A general test of parser->model->generator idempotency. IOW, read a message
-# in, parse it into a message object tree, then without touching the tree,
-# regenerate the plain text. The original text and the transformed text
-# should be identical. Note: that we ignore the Unix-From since that may
-# contain a changed date.
-class TestIdempotent(TestEmailBase):
- def _msgobj(self, filename):
- fp = openfile(filename)
- try:
- data = fp.read()
- finally:
- fp.close()
- msg = email.message_from_string(data)
- return msg, data
-
- def _idempotent(self, msg, text):
- eq = self.ndiffAssertEqual
- s = StringIO()
- g = Generator(s, maxheaderlen=0)
- g.flatten(msg)
- eq(text, s.getvalue())
-
- def test_parse_text_message(self):
- eq = self.assertEquals
- msg, text = self._msgobj('msg_01.txt')
- eq(msg.get_content_type(), 'text/plain')
- eq(msg.get_content_maintype(), 'text')
- eq(msg.get_content_subtype(), 'plain')
- eq(msg.get_params()[1], ('charset', 'us-ascii'))
- eq(msg.get_param('charset'), 'us-ascii')
- eq(msg.preamble, None)
- eq(msg.epilogue, None)
- self._idempotent(msg, text)
-
- def test_parse_untyped_message(self):
- eq = self.assertEquals
- msg, text = self._msgobj('msg_03.txt')
- eq(msg.get_content_type(), 'text/plain')
- eq(msg.get_params(), None)
- eq(msg.get_param('charset'), None)
- self._idempotent(msg, text)
-
- def test_simple_multipart(self):
- msg, text = self._msgobj('msg_04.txt')
- self._idempotent(msg, text)
-
- def test_MIME_digest(self):
- msg, text = self._msgobj('msg_02.txt')
- self._idempotent(msg, text)
-
- def test_long_header(self):
- msg, text = self._msgobj('msg_27.txt')
- self._idempotent(msg, text)
-
- def test_MIME_digest_with_part_headers(self):
- msg, text = self._msgobj('msg_28.txt')
- self._idempotent(msg, text)
-
- def test_mixed_with_image(self):
- msg, text = self._msgobj('msg_06.txt')
- self._idempotent(msg, text)
-
- def test_multipart_report(self):
- msg, text = self._msgobj('msg_05.txt')
- self._idempotent(msg, text)
-
- def test_dsn(self):
- msg, text = self._msgobj('msg_16.txt')
- self._idempotent(msg, text)
-
- def test_preamble_epilogue(self):
- msg, text = self._msgobj('msg_21.txt')
- self._idempotent(msg, text)
-
- def test_multipart_one_part(self):
- msg, text = self._msgobj('msg_23.txt')
- self._idempotent(msg, text)
-
- def test_multipart_no_parts(self):
- msg, text = self._msgobj('msg_24.txt')
- self._idempotent(msg, text)
-
- def test_no_start_boundary(self):
- msg, text = self._msgobj('msg_31.txt')
- self._idempotent(msg, text)
-
- def test_rfc2231_charset(self):
- msg, text = self._msgobj('msg_32.txt')
- self._idempotent(msg, text)
-
- def test_more_rfc2231_parameters(self):
- msg, text = self._msgobj('msg_33.txt')
- self._idempotent(msg, text)
-
- def test_text_plain_in_a_multipart_digest(self):
- msg, text = self._msgobj('msg_34.txt')
- self._idempotent(msg, text)
-
- def test_nested_multipart_mixeds(self):
- msg, text = self._msgobj('msg_12a.txt')
- self._idempotent(msg, text)
-
- def test_message_external_body_idempotent(self):
- msg, text = self._msgobj('msg_36.txt')
- self._idempotent(msg, text)
-
- def test_content_type(self):
- eq = self.assertEquals
- unless = self.failUnless
- # Get a message object and reset the seek pointer for other tests
- msg, text = self._msgobj('msg_05.txt')
- eq(msg.get_content_type(), 'multipart/report')
- # Test the Content-Type: parameters
- params = {}
- for pk, pv in msg.get_params():
- params[pk] = pv
- eq(params['report-type'], 'delivery-status')
- eq(params['boundary'], 'D1690A7AC1.996856090/mail.example.com')
- eq(msg.preamble, 'This is a MIME-encapsulated message.\n')
- eq(msg.epilogue, '\n')
- eq(len(msg.get_payload()), 3)
- # Make sure the subparts are what we expect
- msg1 = msg.get_payload(0)
- eq(msg1.get_content_type(), 'text/plain')
- eq(msg1.get_payload(), 'Yadda yadda yadda\n')
- msg2 = msg.get_payload(1)
- eq(msg2.get_content_type(), 'text/plain')
- eq(msg2.get_payload(), 'Yadda yadda yadda\n')
- msg3 = msg.get_payload(2)
- eq(msg3.get_content_type(), 'message/rfc822')
- self.failUnless(isinstance(msg3, Message))
- payload = msg3.get_payload()
- unless(isinstance(payload, list))
- eq(len(payload), 1)
- msg4 = payload[0]
- unless(isinstance(msg4, Message))
- eq(msg4.get_payload(), 'Yadda yadda yadda\n')
-
- def test_parser(self):
- eq = self.assertEquals
- unless = self.failUnless
- msg, text = self._msgobj('msg_06.txt')
- # Check some of the outer headers
- eq(msg.get_content_type(), 'message/rfc822')
- # Make sure the payload is a list of exactly one sub-Message, and that
- # that submessage has a type of text/plain
- payload = msg.get_payload()
- unless(isinstance(payload, list))
- eq(len(payload), 1)
- msg1 = payload[0]
- self.failUnless(isinstance(msg1, Message))
- eq(msg1.get_content_type(), 'text/plain')
- self.failUnless(isinstance(msg1.get_payload(), str))
- eq(msg1.get_payload(), '\n')
-
-
-
-# Test various other bits of the package's functionality
-class TestMiscellaneous(TestEmailBase):
- def test_message_from_string(self):
- fp = openfile('msg_01.txt')
- try:
- text = fp.read()
- finally:
- fp.close()
- msg = email.message_from_string(text)
- s = StringIO()
- # Don't wrap/continue long headers since we're trying to test
- # idempotency.
- g = Generator(s, maxheaderlen=0)
- g.flatten(msg)
- self.assertEqual(text, s.getvalue())
-
- def test_message_from_file(self):
- fp = openfile('msg_01.txt')
- try:
- text = fp.read()
- fp.seek(0)
- msg = email.message_from_file(fp)
- s = StringIO()
- # Don't wrap/continue long headers since we're trying to test
- # idempotency.
- g = Generator(s, maxheaderlen=0)
- g.flatten(msg)
- self.assertEqual(text, s.getvalue())
- finally:
- fp.close()
-
- def test_message_from_string_with_class(self):
- unless = self.failUnless
- fp = openfile('msg_01.txt')
- try:
- text = fp.read()
- finally:
- fp.close()
- # Create a subclass
- class MyMessage(Message):
- pass
-
- msg = email.message_from_string(text, MyMessage)
- unless(isinstance(msg, MyMessage))
- # Try something more complicated
- fp = openfile('msg_02.txt')
- try:
- text = fp.read()
- finally:
- fp.close()
- msg = email.message_from_string(text, MyMessage)
- for subpart in msg.walk():
- unless(isinstance(subpart, MyMessage))
-
- def test_message_from_file_with_class(self):
- unless = self.failUnless
- # Create a subclass
- class MyMessage(Message):
- pass
-
- fp = openfile('msg_01.txt')
- try:
- msg = email.message_from_file(fp, MyMessage)
- finally:
- fp.close()
- unless(isinstance(msg, MyMessage))
- # Try something more complicated
- fp = openfile('msg_02.txt')
- try:
- msg = email.message_from_file(fp, MyMessage)
- finally:
- fp.close()
- for subpart in msg.walk():
- unless(isinstance(subpart, MyMessage))
-
- def test__all__(self):
- module = __import__('email')
- all = module.__all__
- all.sort()
- self.assertEqual(all, [
- # Old names
- 'Charset', 'Encoders', 'Errors', 'Generator',
- 'Header', 'Iterators', 'MIMEAudio', 'MIMEBase',
- 'MIMEImage', 'MIMEMessage', 'MIMEMultipart',
- 'MIMENonMultipart', 'MIMEText', 'Message',
- 'Parser', 'Utils', 'base64MIME',
- # new names
- 'base64mime', 'charset', 'encoders', 'errors', 'generator',
- 'header', 'iterators', 'message', 'message_from_file',
- 'message_from_string', 'mime', 'parser',
- 'quopriMIME', 'quoprimime', 'utils',
- ])
-
- def test_formatdate(self):
- now = time.time()
- self.assertEqual(Utils.parsedate(Utils.formatdate(now))[:6],
- time.gmtime(now)[:6])
-
- def test_formatdate_localtime(self):
- now = time.time()
- self.assertEqual(
- Utils.parsedate(Utils.formatdate(now, localtime=True))[:6],
- time.localtime(now)[:6])
-
- def test_formatdate_usegmt(self):
- now = time.time()
- self.assertEqual(
- Utils.formatdate(now, localtime=False),
- time.strftime('%a, %d %b %Y %H:%M:%S -0000', time.gmtime(now)))
- self.assertEqual(
- Utils.formatdate(now, localtime=False, usegmt=True),
- time.strftime('%a, %d %b %Y %H:%M:%S GMT', time.gmtime(now)))
-
- def test_parsedate_none(self):
- self.assertEqual(Utils.parsedate(''), None)
-
- def test_parsedate_compact(self):
- # The FWS after the comma is optional
- self.assertEqual(Utils.parsedate('Wed,3 Apr 2002 14:58:26 +0800'),
- Utils.parsedate('Wed, 3 Apr 2002 14:58:26 +0800'))
-
- def test_parsedate_no_dayofweek(self):
- eq = self.assertEqual
- eq(Utils.parsedate_tz('25 Feb 2003 13:47:26 -0800'),
- (2003, 2, 25, 13, 47, 26, 0, 1, -1, -28800))
-
- def test_parsedate_compact_no_dayofweek(self):
- eq = self.assertEqual
- eq(Utils.parsedate_tz('5 Feb 2003 13:47:26 -0800'),
- (2003, 2, 5, 13, 47, 26, 0, 1, -1, -28800))
-
- def test_parsedate_acceptable_to_time_functions(self):
- eq = self.assertEqual
- timetup = Utils.parsedate('5 Feb 2003 13:47:26 -0800')
- t = int(time.mktime(timetup))
- eq(time.localtime(t)[:6], timetup[:6])
- eq(int(time.strftime('%Y', timetup)), 2003)
- timetup = Utils.parsedate_tz('5 Feb 2003 13:47:26 -0800')
- t = int(time.mktime(timetup[:9]))
- eq(time.localtime(t)[:6], timetup[:6])
- eq(int(time.strftime('%Y', timetup[:9])), 2003)
-
- def test_parseaddr_empty(self):
- self.assertEqual(Utils.parseaddr('<>'), ('', ''))
- self.assertEqual(Utils.formataddr(Utils.parseaddr('<>')), '')
-
- def test_noquote_dump(self):
- self.assertEqual(
- Utils.formataddr(('A Silly Person', 'person@dom.ain')),
- 'A Silly Person <person@dom.ain>')
-
- def test_escape_dump(self):
- self.assertEqual(
- Utils.formataddr(('A (Very) Silly Person', 'person@dom.ain')),
- r'"A \(Very\) Silly Person" <person@dom.ain>')
- a = r'A \(Special\) Person'
- b = 'person@dom.ain'
- self.assertEqual(Utils.parseaddr(Utils.formataddr((a, b))), (a, b))
-
- def test_escape_backslashes(self):
- self.assertEqual(
- Utils.formataddr(('Arthur \Backslash\ Foobar', 'person@dom.ain')),
- r'"Arthur \\Backslash\\ Foobar" <person@dom.ain>')
- a = r'Arthur \Backslash\ Foobar'
- b = 'person@dom.ain'
- self.assertEqual(Utils.parseaddr(Utils.formataddr((a, b))), (a, b))
-
- def test_name_with_dot(self):
- x = 'John X. Doe <jxd@example.com>'
- y = '"John X. Doe" <jxd@example.com>'
- a, b = ('John X. Doe', 'jxd@example.com')
- self.assertEqual(Utils.parseaddr(x), (a, b))
- self.assertEqual(Utils.parseaddr(y), (a, b))
- # formataddr() quotes the name if there's a dot in it
- self.assertEqual(Utils.formataddr((a, b)), y)
-
- def test_multiline_from_comment(self):
- x = """\
-Foo
-\tBar <foo@example.com>"""
- self.assertEqual(Utils.parseaddr(x), ('Foo Bar', 'foo@example.com'))
-
- def test_quote_dump(self):
- self.assertEqual(
- Utils.formataddr(('A Silly; Person', 'person@dom.ain')),
- r'"A Silly; Person" <person@dom.ain>')
-
- def test_fix_eols(self):
- eq = self.assertEqual
- eq(Utils.fix_eols('hello'), 'hello')
- eq(Utils.fix_eols('hello\n'), 'hello\r\n')
- eq(Utils.fix_eols('hello\r'), 'hello\r\n')
- eq(Utils.fix_eols('hello\r\n'), 'hello\r\n')
- eq(Utils.fix_eols('hello\n\r'), 'hello\r\n\r\n')
-
- def test_charset_richcomparisons(self):
- eq = self.assertEqual
- ne = self.failIfEqual
- cset1 = Charset()
- cset2 = Charset()
- eq(cset1, 'us-ascii')
- eq(cset1, 'US-ASCII')
- eq(cset1, 'Us-AsCiI')
- eq('us-ascii', cset1)
- eq('US-ASCII', cset1)
- eq('Us-AsCiI', cset1)
- ne(cset1, 'usascii')
- ne(cset1, 'USASCII')
- ne(cset1, 'UsAsCiI')
- ne('usascii', cset1)
- ne('USASCII', cset1)
- ne('UsAsCiI', cset1)
- eq(cset1, cset2)
- eq(cset2, cset1)
-
- def test_getaddresses(self):
- eq = self.assertEqual
- eq(Utils.getaddresses(['aperson@dom.ain (Al Person)',
- 'Bud Person <bperson@dom.ain>']),
- [('Al Person', 'aperson@dom.ain'),
- ('Bud Person', 'bperson@dom.ain')])
-
- def test_getaddresses_nasty(self):
- eq = self.assertEqual
- eq(Utils.getaddresses(['foo: ;']), [('', '')])
- eq(Utils.getaddresses(
- ['[]*-- =~$']),
- [('', ''), ('', ''), ('', '*--')])
- eq(Utils.getaddresses(
- ['foo: ;', '"Jason R. Mastaler" <jason@dom.ain>']),
- [('', ''), ('Jason R. Mastaler', 'jason@dom.ain')])
-
- def test_getaddresses_embedded_comment(self):
- """Test proper handling of a nested comment"""
- eq = self.assertEqual
- addrs = Utils.getaddresses(['User ((nested comment)) <foo@bar.com>'])
- eq(addrs[0][1], 'foo@bar.com')
-
- def test_utils_quote_unquote(self):
- eq = self.assertEqual
- msg = Message()
- msg.add_header('content-disposition', 'attachment',
- filename='foo\\wacky"name')
- eq(msg.get_filename(), 'foo\\wacky"name')
-
- def test_get_body_encoding_with_bogus_charset(self):
- charset = Charset('not a charset')
- self.assertEqual(charset.get_body_encoding(), 'base64')
-
- def test_get_body_encoding_with_uppercase_charset(self):
- eq = self.assertEqual
- msg = Message()
- msg['Content-Type'] = 'text/plain; charset=UTF-8'
- eq(msg['content-type'], 'text/plain; charset=UTF-8')
- charsets = msg.get_charsets()
- eq(len(charsets), 1)
- eq(charsets[0], 'utf-8')
- charset = Charset(charsets[0])
- eq(charset.get_body_encoding(), 'base64')
- msg.set_payload('hello world', charset=charset)
- eq(msg.get_payload(), 'aGVsbG8gd29ybGQ=\n')
- eq(msg.get_payload(decode=True), 'hello world')
- eq(msg['content-transfer-encoding'], 'base64')
- # Try another one
- msg = Message()
- msg['Content-Type'] = 'text/plain; charset="US-ASCII"'
- charsets = msg.get_charsets()
- eq(len(charsets), 1)
- eq(charsets[0], 'us-ascii')
- charset = Charset(charsets[0])
- eq(charset.get_body_encoding(), Encoders.encode_7or8bit)
- msg.set_payload('hello world', charset=charset)
- eq(msg.get_payload(), 'hello world')
- eq(msg['content-transfer-encoding'], '7bit')
-
- def test_charsets_case_insensitive(self):
- lc = Charset('us-ascii')
- uc = Charset('US-ASCII')
- self.assertEqual(lc.get_body_encoding(), uc.get_body_encoding())
-
- def test_partial_falls_inside_message_delivery_status(self):
- eq = self.ndiffAssertEqual
- # The Parser interface provides chunks of data to FeedParser in 8192
- # byte gulps. SF bug #1076485 found one of those chunks inside
- # message/delivery-status header block, which triggered an
- # unreadline() of NeedMoreData.
- msg = self._msgobj('msg_43.txt')
- sfp = StringIO()
- Iterators._structure(msg, sfp)
- eq(sfp.getvalue(), """\
-multipart/report
- text/plain
- message/delivery-status
- text/plain
- text/plain
- text/plain
- text/plain
- text/plain
- text/plain
- text/plain
- text/plain
- text/plain
- text/plain
- text/plain
- text/plain
- text/plain
- text/plain
- text/plain
- text/plain
- text/plain
- text/plain
- text/plain
- text/plain
- text/plain
- text/plain
- text/plain
- text/plain
- text/plain
- text/plain
- text/rfc822-headers
-""")
-
-
-
-# Test the iterator/generators
-class TestIterators(TestEmailBase):
- def test_body_line_iterator(self):
- eq = self.assertEqual
- neq = self.ndiffAssertEqual
- # First a simple non-multipart message
- msg = self._msgobj('msg_01.txt')
- it = Iterators.body_line_iterator(msg)
- lines = list(it)
- eq(len(lines), 6)
- neq(EMPTYSTRING.join(lines), msg.get_payload())
- # Now a more complicated multipart
- msg = self._msgobj('msg_02.txt')
- it = Iterators.body_line_iterator(msg)
- lines = list(it)
- eq(len(lines), 43)
- fp = openfile('msg_19.txt')
- try:
- neq(EMPTYSTRING.join(lines), fp.read())
- finally:
- fp.close()
-
- def test_typed_subpart_iterator(self):
- eq = self.assertEqual
- msg = self._msgobj('msg_04.txt')
- it = Iterators.typed_subpart_iterator(msg, 'text')
- lines = []
- subparts = 0
- for subpart in it:
- subparts += 1
- lines.append(subpart.get_payload())
- eq(subparts, 2)
- eq(EMPTYSTRING.join(lines), """\
-a simple kind of mirror
-to reflect upon our own
-a simple kind of mirror
-to reflect upon our own
-""")
-
- def test_typed_subpart_iterator_default_type(self):
- eq = self.assertEqual
- msg = self._msgobj('msg_03.txt')
- it = Iterators.typed_subpart_iterator(msg, 'text', 'plain')
- lines = []
- subparts = 0
- for subpart in it:
- subparts += 1
- lines.append(subpart.get_payload())
- eq(subparts, 1)
- eq(EMPTYSTRING.join(lines), """\
-
-Hi,
-
-Do you like this message?
-
--Me
-""")
-
-
-
-class TestParsers(TestEmailBase):
- def test_header_parser(self):
- eq = self.assertEqual
- # Parse only the headers of a complex multipart MIME document
- fp = openfile('msg_02.txt')
- try:
- msg = HeaderParser().parse(fp)
- finally:
- fp.close()
- eq(msg['from'], 'ppp-request@zzz.org')
- eq(msg['to'], 'ppp@zzz.org')
- eq(msg.get_content_type(), 'multipart/mixed')
- self.failIf(msg.is_multipart())
- self.failUnless(isinstance(msg.get_payload(), str))
-
- def test_whitespace_continuation(self):
- eq = self.assertEqual
- # This message contains a line after the Subject: header that has only
- # whitespace, but it is not empty!
- msg = email.message_from_string("""\
-From: aperson@dom.ain
-To: bperson@dom.ain
-Subject: the next line has a space on it
-\x20
-Date: Mon, 8 Apr 2002 15:09:19 -0400
-Message-ID: spam
-
-Here's the message body
-""")
- eq(msg['subject'], 'the next line has a space on it\n ')
- eq(msg['message-id'], 'spam')
- eq(msg.get_payload(), "Here's the message body\n")
-
- def test_whitespace_continuation_last_header(self):
- eq = self.assertEqual
- # Like the previous test, but the subject line is the last
- # header.
- msg = email.message_from_string("""\
-From: aperson@dom.ain
-To: bperson@dom.ain
-Date: Mon, 8 Apr 2002 15:09:19 -0400
-Message-ID: spam
-Subject: the next line has a space on it
-\x20
-
-Here's the message body
-""")
- eq(msg['subject'], 'the next line has a space on it\n ')
- eq(msg['message-id'], 'spam')
- eq(msg.get_payload(), "Here's the message body\n")
-
- def test_crlf_separation(self):
- eq = self.assertEqual
- fp = openfile('msg_26.txt', mode='rb')
- try:
- msg = Parser().parse(fp)
- finally:
- fp.close()
- eq(len(msg.get_payload()), 2)
- part1 = msg.get_payload(0)
- eq(part1.get_content_type(), 'text/plain')
- eq(part1.get_payload(), 'Simple email with attachment.\r\n\r\n')
- part2 = msg.get_payload(1)
- eq(part2.get_content_type(), 'application/riscos')
-
- def test_multipart_digest_with_extra_mime_headers(self):
- eq = self.assertEqual
- neq = self.ndiffAssertEqual
- fp = openfile('msg_28.txt')
- try:
- msg = email.message_from_file(fp)
- finally:
- fp.close()
- # Structure is:
- # multipart/digest
- # message/rfc822
- # text/plain
- # message/rfc822
- # text/plain
- eq(msg.is_multipart(), 1)
- eq(len(msg.get_payload()), 2)
- part1 = msg.get_payload(0)
- eq(part1.get_content_type(), 'message/rfc822')
- eq(part1.is_multipart(), 1)
- eq(len(part1.get_payload()), 1)
- part1a = part1.get_payload(0)
- eq(part1a.is_multipart(), 0)
- eq(part1a.get_content_type(), 'text/plain')
- neq(part1a.get_payload(), 'message 1\n')
- # next message/rfc822
- part2 = msg.get_payload(1)
- eq(part2.get_content_type(), 'message/rfc822')
- eq(part2.is_multipart(), 1)
- eq(len(part2.get_payload()), 1)
- part2a = part2.get_payload(0)
- eq(part2a.is_multipart(), 0)
- eq(part2a.get_content_type(), 'text/plain')
- neq(part2a.get_payload(), 'message 2\n')
-
- def test_three_lines(self):
- # A bug report by Andrew McNamara
- lines = ['From: Andrew Person <aperson@dom.ain',
- 'Subject: Test',
- 'Date: Tue, 20 Aug 2002 16:43:45 +1000']
- msg = email.message_from_string(NL.join(lines))
- self.assertEqual(msg['date'], 'Tue, 20 Aug 2002 16:43:45 +1000')
-
- def test_strip_line_feed_and_carriage_return_in_headers(self):
- eq = self.assertEqual
- # For [ 1002475 ] email message parser doesn't handle \r\n correctly
- value1 = 'text'
- value2 = 'more text'
- m = 'Header: %s\r\nNext-Header: %s\r\n\r\nBody\r\n\r\n' % (
- value1, value2)
- msg = email.message_from_string(m)
- eq(msg.get('Header'), value1)
- eq(msg.get('Next-Header'), value2)
-
- def test_rfc2822_header_syntax(self):
- eq = self.assertEqual
- m = '>From: foo\nFrom: bar\n!"#QUX;~: zoo\n\nbody'
- msg = email.message_from_string(m)
- eq(len(msg.keys()), 3)
- keys = msg.keys()
- keys.sort()
- eq(keys, ['!"#QUX;~', '>From', 'From'])
- eq(msg.get_payload(), 'body')
-
- def test_rfc2822_space_not_allowed_in_header(self):
- eq = self.assertEqual
- m = '>From foo@example.com 11:25:53\nFrom: bar\n!"#QUX;~: zoo\n\nbody'
- msg = email.message_from_string(m)
- eq(len(msg.keys()), 0)
-
- def test_rfc2822_one_character_header(self):
- eq = self.assertEqual
- m = 'A: first header\nB: second header\nCC: third header\n\nbody'
- msg = email.message_from_string(m)
- headers = msg.keys()
- headers.sort()
- eq(headers, ['A', 'B', 'CC'])
- eq(msg.get_payload(), 'body')
-
-
-
-class TestBase64(unittest.TestCase):
- def test_len(self):
- eq = self.assertEqual
- eq(base64MIME.base64_len('hello'),
- len(base64MIME.encode('hello', eol='')))
- for size in range(15):
- if size == 0 : bsize = 0
- elif size <= 3 : bsize = 4
- elif size <= 6 : bsize = 8
- elif size <= 9 : bsize = 12
- elif size <= 12: bsize = 16
- else : bsize = 20
- eq(base64MIME.base64_len('x'*size), bsize)
-
- def test_decode(self):
- eq = self.assertEqual
- eq(base64MIME.decode(''), '')
- eq(base64MIME.decode('aGVsbG8='), 'hello')
- eq(base64MIME.decode('aGVsbG8=', 'X'), 'hello')
- eq(base64MIME.decode('aGVsbG8NCndvcmxk\n', 'X'), 'helloXworld')
-
- def test_encode(self):
- eq = self.assertEqual
- eq(base64MIME.encode(''), '')
- eq(base64MIME.encode('hello'), 'aGVsbG8=\n')
- # Test the binary flag
- eq(base64MIME.encode('hello\n'), 'aGVsbG8K\n')
- eq(base64MIME.encode('hello\n', 0), 'aGVsbG8NCg==\n')
- # Test the maxlinelen arg
- eq(base64MIME.encode('xxxx ' * 20, maxlinelen=40), """\
-eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
-eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
-eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
-eHh4eCB4eHh4IA==
-""")
- # Test the eol argument
- eq(base64MIME.encode('xxxx ' * 20, maxlinelen=40, eol='\r\n'), """\
-eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg\r
-eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg\r
-eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg\r
-eHh4eCB4eHh4IA==\r
-""")
-
- def test_header_encode(self):
- eq = self.assertEqual
- he = base64MIME.header_encode
- eq(he('hello'), '=?iso-8859-1?b?aGVsbG8=?=')
- eq(he('hello\nworld'), '=?iso-8859-1?b?aGVsbG8NCndvcmxk?=')
- # Test the charset option
- eq(he('hello', charset='iso-8859-2'), '=?iso-8859-2?b?aGVsbG8=?=')
- # Test the keep_eols flag
- eq(he('hello\nworld', keep_eols=True),
- '=?iso-8859-1?b?aGVsbG8Kd29ybGQ=?=')
- # Test the maxlinelen argument
- eq(he('xxxx ' * 20, maxlinelen=40), """\
-=?iso-8859-1?b?eHh4eCB4eHh4IHh4eHggeHg=?=
- =?iso-8859-1?b?eHggeHh4eCB4eHh4IHh4eHg=?=
- =?iso-8859-1?b?IHh4eHggeHh4eCB4eHh4IHg=?=
- =?iso-8859-1?b?eHh4IHh4eHggeHh4eCB4eHg=?=
- =?iso-8859-1?b?eCB4eHh4IHh4eHggeHh4eCA=?=
- =?iso-8859-1?b?eHh4eCB4eHh4IHh4eHgg?=""")
- # Test the eol argument
- eq(he('xxxx ' * 20, maxlinelen=40, eol='\r\n'), """\
-=?iso-8859-1?b?eHh4eCB4eHh4IHh4eHggeHg=?=\r
- =?iso-8859-1?b?eHggeHh4eCB4eHh4IHh4eHg=?=\r
- =?iso-8859-1?b?IHh4eHggeHh4eCB4eHh4IHg=?=\r
- =?iso-8859-1?b?eHh4IHh4eHggeHh4eCB4eHg=?=\r
- =?iso-8859-1?b?eCB4eHh4IHh4eHggeHh4eCA=?=\r
- =?iso-8859-1?b?eHh4eCB4eHh4IHh4eHgg?=""")
-
-
-
-class TestQuopri(unittest.TestCase):
- def setUp(self):
- self.hlit = [chr(x) for x in range(ord('a'), ord('z')+1)] + \
- [chr(x) for x in range(ord('A'), ord('Z')+1)] + \
- [chr(x) for x in range(ord('0'), ord('9')+1)] + \
- ['!', '*', '+', '-', '/', ' ']
- self.hnon = [chr(x) for x in range(256) if chr(x) not in self.hlit]
- assert len(self.hlit) + len(self.hnon) == 256
- self.blit = [chr(x) for x in range(ord(' '), ord('~')+1)] + ['\t']
- self.blit.remove('=')
- self.bnon = [chr(x) for x in range(256) if chr(x) not in self.blit]
- assert len(self.blit) + len(self.bnon) == 256
-
- def test_header_quopri_check(self):
- for c in self.hlit:
- self.failIf(quopriMIME.header_quopri_check(c))
- for c in self.hnon:
- self.failUnless(quopriMIME.header_quopri_check(c))
-
- def test_body_quopri_check(self):
- for c in self.blit:
- self.failIf(quopriMIME.body_quopri_check(c))
- for c in self.bnon:
- self.failUnless(quopriMIME.body_quopri_check(c))
-
- def test_header_quopri_len(self):
- eq = self.assertEqual
- hql = quopriMIME.header_quopri_len
- enc = quopriMIME.header_encode
- for s in ('hello', 'h@e@l@l@o@'):
- # Empty charset and no line-endings. 7 == RFC chrome
- eq(hql(s), len(enc(s, charset='', eol=''))-7)
- for c in self.hlit:
- eq(hql(c), 1)
- for c in self.hnon:
- eq(hql(c), 3)
-
- def test_body_quopri_len(self):
- eq = self.assertEqual
- bql = quopriMIME.body_quopri_len
- for c in self.blit:
- eq(bql(c), 1)
- for c in self.bnon:
- eq(bql(c), 3)
-
- def test_quote_unquote_idempotent(self):
- for x in range(256):
- c = chr(x)
- self.assertEqual(quopriMIME.unquote(quopriMIME.quote(c)), c)
-
- def test_header_encode(self):
- eq = self.assertEqual
- he = quopriMIME.header_encode
- eq(he('hello'), '=?iso-8859-1?q?hello?=')
- eq(he('hello\nworld'), '=?iso-8859-1?q?hello=0D=0Aworld?=')
- # Test the charset option
- eq(he('hello', charset='iso-8859-2'), '=?iso-8859-2?q?hello?=')
- # Test the keep_eols flag
- eq(he('hello\nworld', keep_eols=True), '=?iso-8859-1?q?hello=0Aworld?=')
- # Test a non-ASCII character
- eq(he('hello\xc7there'), '=?iso-8859-1?q?hello=C7there?=')
- # Test the maxlinelen argument
- eq(he('xxxx ' * 20, maxlinelen=40), """\
-=?iso-8859-1?q?xxxx_xxxx_xxxx_xxxx_xx?=
- =?iso-8859-1?q?xx_xxxx_xxxx_xxxx_xxxx?=
- =?iso-8859-1?q?_xxxx_xxxx_xxxx_xxxx_x?=
- =?iso-8859-1?q?xxx_xxxx_xxxx_xxxx_xxx?=
- =?iso-8859-1?q?x_xxxx_xxxx_?=""")
- # Test the eol argument
- eq(he('xxxx ' * 20, maxlinelen=40, eol='\r\n'), """\
-=?iso-8859-1?q?xxxx_xxxx_xxxx_xxxx_xx?=\r
- =?iso-8859-1?q?xx_xxxx_xxxx_xxxx_xxxx?=\r
- =?iso-8859-1?q?_xxxx_xxxx_xxxx_xxxx_x?=\r
- =?iso-8859-1?q?xxx_xxxx_xxxx_xxxx_xxx?=\r
- =?iso-8859-1?q?x_xxxx_xxxx_?=""")
-
- def test_decode(self):
- eq = self.assertEqual
- eq(quopriMIME.decode(''), '')
- eq(quopriMIME.decode('hello'), 'hello')
- eq(quopriMIME.decode('hello', 'X'), 'hello')
- eq(quopriMIME.decode('hello\nworld', 'X'), 'helloXworld')
-
- def test_encode(self):
- eq = self.assertEqual
- eq(quopriMIME.encode(''), '')
- eq(quopriMIME.encode('hello'), 'hello')
- # Test the binary flag
- eq(quopriMIME.encode('hello\r\nworld'), 'hello\nworld')
- eq(quopriMIME.encode('hello\r\nworld', 0), 'hello\nworld')
- # Test the maxlinelen arg
- eq(quopriMIME.encode('xxxx ' * 20, maxlinelen=40), """\
-xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx=
- xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxx=
-x xxxx xxxx xxxx xxxx=20""")
- # Test the eol argument
- eq(quopriMIME.encode('xxxx ' * 20, maxlinelen=40, eol='\r\n'), """\
-xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx=\r
- xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxx=\r
-x xxxx xxxx xxxx xxxx=20""")
- eq(quopriMIME.encode("""\
-one line
-
-two line"""), """\
-one line
-
-two line""")
-
-
-
-# Test the Charset class
-class TestCharset(unittest.TestCase):
- def tearDown(self):
- from email import Charset as CharsetModule
- try:
- del CharsetModule.CHARSETS['fake']
- except KeyError:
- pass
-
- def test_idempotent(self):
- eq = self.assertEqual
- # Make sure us-ascii = no Unicode conversion
- c = Charset('us-ascii')
- s = 'Hello World!'
- sp = c.to_splittable(s)
- eq(s, c.from_splittable(sp))
- # test 8-bit idempotency with us-ascii
- s = '\xa4\xa2\xa4\xa4\xa4\xa6\xa4\xa8\xa4\xaa'
- sp = c.to_splittable(s)
- eq(s, c.from_splittable(sp))
-
- def test_body_encode(self):
- eq = self.assertEqual
- # Try a charset with QP body encoding
- c = Charset('iso-8859-1')
- eq('hello w=F6rld', c.body_encode('hello w\xf6rld'))
- # Try a charset with Base64 body encoding
- c = Charset('utf-8')
- eq('aGVsbG8gd29ybGQ=\n', c.body_encode('hello world'))
- # Try a charset with None body encoding
- c = Charset('us-ascii')
- eq('hello world', c.body_encode('hello world'))
- # Try the convert argument, where input codec != output codec
- c = Charset('euc-jp')
- # With apologies to Tokio Kikuchi ;)
- try:
- eq('\x1b$B5FCO;~IW\x1b(B',
- c.body_encode('\xb5\xc6\xc3\xcf\xbb\xfe\xc9\xd7'))
- eq('\xb5\xc6\xc3\xcf\xbb\xfe\xc9\xd7',
- c.body_encode('\xb5\xc6\xc3\xcf\xbb\xfe\xc9\xd7', False))
- except LookupError:
- # We probably don't have the Japanese codecs installed
- pass
- # Testing SF bug #625509, which we have to fake, since there are no
- # built-in encodings where the header encoding is QP but the body
- # encoding is not.
- from email import Charset as CharsetModule
- CharsetModule.add_charset('fake', CharsetModule.QP, None)
- c = Charset('fake')
- eq('hello w\xf6rld', c.body_encode('hello w\xf6rld'))
-
- def test_unicode_charset_name(self):
- charset = Charset('us-ascii')
- self.assertEqual(str(charset), 'us-ascii')
- self.assertRaises(Errors.CharsetError, Charset, 'asc\xffii')
-
-
-
-# Test multilingual MIME headers.
-class TestHeader(TestEmailBase):
- def test_simple(self):
- eq = self.ndiffAssertEqual
- h = Header('Hello World!')
- eq(h.encode(), 'Hello World!')
- h.append(' Goodbye World!')
- eq(h.encode(), 'Hello World! Goodbye World!')
-
- def test_simple_surprise(self):
- eq = self.ndiffAssertEqual
- h = Header('Hello World!')
- eq(h.encode(), 'Hello World!')
- h.append('Goodbye World!')
- eq(h.encode(), 'Hello World! Goodbye World!')
-
- def test_header_needs_no_decoding(self):
- h = 'no decoding needed'
- self.assertEqual(decode_header(h), [(h, None)])
-
- def test_long(self):
- h = Header("I am the very model of a modern Major-General; I've information vegetable, animal, and mineral; I know the kings of England, and I quote the fights historical from Marathon to Waterloo, in order categorical; I'm very well acquainted, too, with matters mathematical; I understand equations, both the simple and quadratical; about binomial theorem I'm teeming with a lot o' news, with many cheerful facts about the square of the hypotenuse.",
- maxlinelen=76)
- for l in h.encode(splitchars=' ').split('\n '):
- self.failUnless(len(l) <= 76)
-
- def test_multilingual(self):
- eq = self.ndiffAssertEqual
- g = Charset("iso-8859-1")
- cz = Charset("iso-8859-2")
- utf8 = Charset("utf-8")
- g_head = "Die Mieter treten hier ein werden mit einem Foerderband komfortabel den Korridor entlang, an s\xfcdl\xfcndischen Wandgem\xe4lden vorbei, gegen die rotierenden Klingen bef\xf6rdert. "
- cz_head = "Finan\xe8ni metropole se hroutily pod tlakem jejich d\xf9vtipu.. "
- utf8_head = "\u6b63\u78ba\u306b\u8a00\u3046\u3068\u7ffb\u8a33\u306f\u3055\u308c\u3066\u3044\u307e\u305b\u3093\u3002\u4e00\u90e8\u306f\u30c9\u30a4\u30c4\u8a9e\u3067\u3059\u304c\u3001\u3042\u3068\u306f\u3067\u305f\u3089\u3081\u3067\u3059\u3002\u5b9f\u969b\u306b\u306f\u300cWenn ist das Nunstuck git und Slotermeyer? Ja! Beiherhund das Oder die Flipperwaldt gersput.\u300d\u3068\u8a00\u3063\u3066\u3044\u307e\u3059\u3002".encode("utf-8")
- h = Header(g_head, g)
- h.append(cz_head, cz)
- h.append(utf8_head, utf8)
- enc = h.encode()
- eq(enc, """\
-=?iso-8859-1?q?Die_Mieter_treten_hier_ein_werden_mit_einem_Foerderband_ko?=
- =?iso-8859-1?q?mfortabel_den_Korridor_entlang=2C_an_s=FCdl=FCndischen_Wan?=
- =?iso-8859-1?q?dgem=E4lden_vorbei=2C_gegen_die_rotierenden_Klingen_bef=F6?=
- =?iso-8859-1?q?rdert=2E_?= =?iso-8859-2?q?Finan=E8ni_metropole_se_hroutily?=
- =?iso-8859-2?q?_pod_tlakem_jejich_d=F9vtipu=2E=2E_?= =?utf-8?b?5q2j56K6?=
- =?utf-8?b?44Gr6KiA44GG44Go57+76Kiz44Gv44GV44KM44Gm44GE44G+44Gb44KT44CC?=
- =?utf-8?b?5LiA6YOo44Gv44OJ44Kk44OE6Kqe44Gn44GZ44GM44CB44GC44Go44Gv44Gn?=
- =?utf-8?b?44Gf44KJ44KB44Gn44GZ44CC5a6f6Zqb44Gr44Gv44CMV2VubiBpc3QgZGFz?=
- =?utf-8?q?_Nunstuck_git_und_Slotermeyer=3F_Ja!_Beiherhund_das_Oder_die_Fl?=
- =?utf-8?b?aXBwZXJ3YWxkdCBnZXJzcHV0LuOAjeOBqOiogOOBo+OBpuOBhOOBvuOBmQ==?=
- =?utf-8?b?44CC?=""")
- eq(decode_header(enc),
- [(g_head, "iso-8859-1"), (cz_head, "iso-8859-2"),
- (utf8_head, "utf-8")])
- ustr = str(h)
- eq(ustr.encode('utf-8'),
- 'Die Mieter treten hier ein werden mit einem Foerderband '
- 'komfortabel den Korridor entlang, an s\xc3\xbcdl\xc3\xbcndischen '
- 'Wandgem\xc3\xa4lden vorbei, gegen die rotierenden Klingen '
- 'bef\xc3\xb6rdert. Finan\xc4\x8dni metropole se hroutily pod '
- 'tlakem jejich d\xc5\xafvtipu.. \xe6\xad\xa3\xe7\xa2\xba\xe3\x81'
- '\xab\xe8\xa8\x80\xe3\x81\x86\xe3\x81\xa8\xe7\xbf\xbb\xe8\xa8\xb3'
- '\xe3\x81\xaf\xe3\x81\x95\xe3\x82\x8c\xe3\x81\xa6\xe3\x81\x84\xe3'
- '\x81\xbe\xe3\x81\x9b\xe3\x82\x93\xe3\x80\x82\xe4\xb8\x80\xe9\x83'
- '\xa8\xe3\x81\xaf\xe3\x83\x89\xe3\x82\xa4\xe3\x83\x84\xe8\xaa\x9e'
- '\xe3\x81\xa7\xe3\x81\x99\xe3\x81\x8c\xe3\x80\x81\xe3\x81\x82\xe3'
- '\x81\xa8\xe3\x81\xaf\xe3\x81\xa7\xe3\x81\x9f\xe3\x82\x89\xe3\x82'
- '\x81\xe3\x81\xa7\xe3\x81\x99\xe3\x80\x82\xe5\xae\x9f\xe9\x9a\x9b'
- '\xe3\x81\xab\xe3\x81\xaf\xe3\x80\x8cWenn ist das Nunstuck git '
- 'und Slotermeyer? Ja! Beiherhund das Oder die Flipperwaldt '
- 'gersput.\xe3\x80\x8d\xe3\x81\xa8\xe8\xa8\x80\xe3\x81\xa3\xe3\x81'
- '\xa6\xe3\x81\x84\xe3\x81\xbe\xe3\x81\x99\xe3\x80\x82')
- # Test make_header()
- newh = make_header(decode_header(enc))
- eq(newh, enc)
-
- def test_header_ctor_default_args(self):
- eq = self.ndiffAssertEqual
- h = Header()
- eq(h, '')
- h.append('foo', Charset('iso-8859-1'))
- eq(h, '=?iso-8859-1?q?foo?=')
-
- def test_explicit_maxlinelen(self):
- eq = self.ndiffAssertEqual
- hstr = 'A very long line that must get split to something other than at the 76th character boundary to test the non-default behavior'
- h = Header(hstr)
- eq(h.encode(), '''\
-A very long line that must get split to something other than at the 76th
- character boundary to test the non-default behavior''')
- h = Header(hstr, header_name='Subject')
- eq(h.encode(), '''\
-A very long line that must get split to something other than at the
- 76th character boundary to test the non-default behavior''')
- h = Header(hstr, maxlinelen=1024, header_name='Subject')
- eq(h.encode(), hstr)
-
- def test_us_ascii_header(self):
- eq = self.assertEqual
- s = 'hello'
- x = decode_header(s)
- eq(x, [('hello', None)])
- h = make_header(x)
- eq(s, h.encode())
-
- def test_string_charset(self):
- eq = self.assertEqual
- h = Header()
- h.append('hello', 'iso-8859-1')
- eq(h, '=?iso-8859-1?q?hello?=')
-
-## def test_unicode_error(self):
-## raises = self.assertRaises
-## raises(UnicodeError, Header, u'[P\xf6stal]', 'us-ascii')
-## raises(UnicodeError, Header, '[P\xf6stal]', 'us-ascii')
-## h = Header()
-## raises(UnicodeError, h.append, u'[P\xf6stal]', 'us-ascii')
-## raises(UnicodeError, h.append, '[P\xf6stal]', 'us-ascii')
-## raises(UnicodeError, Header, u'\u83ca\u5730\u6642\u592b', 'iso-8859-1')
-
- def test_utf8_shortest(self):
- eq = self.assertEqual
- h = Header('p\xf6stal', 'utf-8')
- eq(h.encode(), '=?utf-8?q?p=C3=B6stal?=')
- h = Header('\u83ca\u5730\u6642\u592b', 'utf-8')
- eq(h.encode(), '=?utf-8?b?6I+K5Zyw5pmC5aSr?=')
-
- def test_bad_8bit_header(self):
- raises = self.assertRaises
- eq = self.assertEqual
- x = 'Ynwp4dUEbay Auction Semiar- No Charge \x96 Earn Big'
- raises(UnicodeError, Header, x)
- h = Header()
- raises(UnicodeError, h.append, x)
- eq(str(Header(x, errors='replace')), x)
- h.append(x, errors='replace')
- eq(str(h), x)
-
- def test_encoded_adjacent_nonencoded(self):
- eq = self.assertEqual
- h = Header()
- h.append('hello', 'iso-8859-1')
- h.append('world')
- s = h.encode()
- eq(s, '=?iso-8859-1?q?hello?= world')
- h = make_header(decode_header(s))
- eq(h.encode(), s)
-
- def test_whitespace_eater(self):
- eq = self.assertEqual
- s = 'Subject: =?koi8-r?b?8NLP18XSy8EgzsEgxsnOwczYztk=?= =?koi8-r?q?=CA?= zz.'
- parts = decode_header(s)
- eq(parts, [('Subject:', None), ('\xf0\xd2\xcf\xd7\xc5\xd2\xcb\xc1 \xce\xc1 \xc6\xc9\xce\xc1\xcc\xd8\xce\xd9\xca', 'koi8-r'), ('zz.', None)])
- hdr = make_header(parts)
- eq(hdr.encode(),
- 'Subject: =?koi8-r?b?8NLP18XSy8EgzsEgxsnOwczYztnK?= zz.')
-
- def test_broken_base64_header(self):
- raises = self.assertRaises
- s = 'Subject: =?EUC-KR?B?CSixpLDtKSC/7Liuvsax4iC6uLmwMcijIKHaILzSwd/H0SC8+LCjwLsgv7W/+Mj3IQ?='
- raises(Errors.HeaderParseError, decode_header, s)
-
-
-
-# Test RFC 2231 header parameters (en/de)coding
-class TestRFC2231(TestEmailBase):
- def test_get_param(self):
- eq = self.assertEqual
- msg = self._msgobj('msg_29.txt')
- eq(msg.get_param('title'),
- ('us-ascii', 'en', 'This is even more ***fun*** isn\'t it!'))
- eq(msg.get_param('title', unquote=False),
- ('us-ascii', 'en', '"This is even more ***fun*** isn\'t it!"'))
-
- def test_set_param(self):
- eq = self.assertEqual
- msg = Message()
- msg.set_param('title', 'This is even more ***fun*** isn\'t it!',
- charset='us-ascii')
- eq(msg.get_param('title'),
- ('us-ascii', '', 'This is even more ***fun*** isn\'t it!'))
- msg.set_param('title', 'This is even more ***fun*** isn\'t it!',
- charset='us-ascii', language='en')
- eq(msg.get_param('title'),
- ('us-ascii', 'en', 'This is even more ***fun*** isn\'t it!'))
- msg = self._msgobj('msg_01.txt')
- msg.set_param('title', 'This is even more ***fun*** isn\'t it!',
- charset='us-ascii', language='en')
- eq(msg.as_string(), """\
-Return-Path: <bbb@zzz.org>
-Delivered-To: bbb@zzz.org
-Received: by mail.zzz.org (Postfix, from userid 889)
-\tid 27CEAD38CC; Fri, 4 May 2001 14:05:44 -0400 (EDT)
-MIME-Version: 1.0
-Content-Transfer-Encoding: 7bit
-Message-ID: <15090.61304.110929.45684@aaa.zzz.org>
-From: bbb@ddd.com (John X. Doe)
-To: bbb@zzz.org
-Subject: This is a test message
-Date: Fri, 4 May 2001 14:05:44 -0400
-Content-Type: text/plain; charset=us-ascii;
-\ttitle*="us-ascii'en'This%20is%20even%20more%20%2A%2A%2Afun%2A%2A%2A%20isn%27t%20it%21"
-
-
-Hi,
-
-Do you like this message?
-
--Me
-""")
-
- def test_del_param(self):
- eq = self.ndiffAssertEqual
- msg = self._msgobj('msg_01.txt')
- msg.set_param('foo', 'bar', charset='us-ascii', language='en')
- msg.set_param('title', 'This is even more ***fun*** isn\'t it!',
- charset='us-ascii', language='en')
- msg.del_param('foo', header='Content-Type')
- eq(msg.as_string(), """\
-Return-Path: <bbb@zzz.org>
-Delivered-To: bbb@zzz.org
-Received: by mail.zzz.org (Postfix, from userid 889)
-\tid 27CEAD38CC; Fri, 4 May 2001 14:05:44 -0400 (EDT)
-MIME-Version: 1.0
-Content-Transfer-Encoding: 7bit
-Message-ID: <15090.61304.110929.45684@aaa.zzz.org>
-From: bbb@ddd.com (John X. Doe)
-To: bbb@zzz.org
-Subject: This is a test message
-Date: Fri, 4 May 2001 14:05:44 -0400
-Content-Type: text/plain; charset="us-ascii";
-\ttitle*="us-ascii'en'This%20is%20even%20more%20%2A%2A%2Afun%2A%2A%2A%20isn%27t%20it%21"
-
-
-Hi,
-
-Do you like this message?
-
--Me
-""")
-
- def test_rfc2231_get_content_charset(self):
- eq = self.assertEqual
- msg = self._msgobj('msg_32.txt')
- eq(msg.get_content_charset(), 'us-ascii')
-
- def test_rfc2231_no_language_or_charset(self):
- m = '''\
-Content-Transfer-Encoding: 8bit
-Content-Disposition: inline; filename="file____C__DOCUMENTS_20AND_20SETTINGS_FABIEN_LOCAL_20SETTINGS_TEMP_nsmail.htm"
-Content-Type: text/html; NAME*0=file____C__DOCUMENTS_20AND_20SETTINGS_FABIEN_LOCAL_20SETTINGS_TEM; NAME*1=P_nsmail.htm
-
-'''
- msg = email.message_from_string(m)
- param = msg.get_param('NAME')
- self.failIf(isinstance(param, tuple))
- self.assertEqual(
- param,
- 'file____C__DOCUMENTS_20AND_20SETTINGS_FABIEN_LOCAL_20SETTINGS_TEMP_nsmail.htm')
-
- def test_rfc2231_no_language_or_charset_in_filename(self):
- m = '''\
-Content-Disposition: inline;
-\tfilename*0*="''This%20is%20even%20more%20";
-\tfilename*1*="%2A%2A%2Afun%2A%2A%2A%20";
-\tfilename*2="is it not.pdf"
-
-'''
- msg = email.message_from_string(m)
- self.assertEqual(msg.get_filename(),
- 'This is even more ***fun*** is it not.pdf')
-
- def test_rfc2231_no_language_or_charset_in_filename_encoded(self):
- m = '''\
-Content-Disposition: inline;
-\tfilename*0*="''This%20is%20even%20more%20";
-\tfilename*1*="%2A%2A%2Afun%2A%2A%2A%20";
-\tfilename*2="is it not.pdf"
-
-'''
- msg = email.message_from_string(m)
- self.assertEqual(msg.get_filename(),
- 'This is even more ***fun*** is it not.pdf')
-
- def test_rfc2231_partly_encoded(self):
- m = '''\
-Content-Disposition: inline;
-\tfilename*0="''This%20is%20even%20more%20";
-\tfilename*1*="%2A%2A%2Afun%2A%2A%2A%20";
-\tfilename*2="is it not.pdf"
-
-'''
- msg = email.message_from_string(m)
- self.assertEqual(
- msg.get_filename(),
- 'This%20is%20even%20more%20***fun*** is it not.pdf')
-
- def test_rfc2231_partly_nonencoded(self):
- m = '''\
-Content-Disposition: inline;
-\tfilename*0="This%20is%20even%20more%20";
-\tfilename*1="%2A%2A%2Afun%2A%2A%2A%20";
-\tfilename*2="is it not.pdf"
-
-'''
- msg = email.message_from_string(m)
- self.assertEqual(
- msg.get_filename(),
- 'This%20is%20even%20more%20%2A%2A%2Afun%2A%2A%2A%20is it not.pdf')
-
- def test_rfc2231_no_language_or_charset_in_boundary(self):
- m = '''\
-Content-Type: multipart/alternative;
-\tboundary*0*="''This%20is%20even%20more%20";
-\tboundary*1*="%2A%2A%2Afun%2A%2A%2A%20";
-\tboundary*2="is it not.pdf"
-
-'''
- msg = email.message_from_string(m)
- self.assertEqual(msg.get_boundary(),
- 'This is even more ***fun*** is it not.pdf')
-
- def test_rfc2231_no_language_or_charset_in_charset(self):
- # This is a nonsensical charset value, but tests the code anyway
- m = '''\
-Content-Type: text/plain;
-\tcharset*0*="This%20is%20even%20more%20";
-\tcharset*1*="%2A%2A%2Afun%2A%2A%2A%20";
-\tcharset*2="is it not.pdf"
-
-'''
- msg = email.message_from_string(m)
- self.assertEqual(msg.get_content_charset(),
- 'this is even more ***fun*** is it not.pdf')
-
- def test_rfc2231_bad_encoding_in_filename(self):
- m = '''\
-Content-Disposition: inline;
-\tfilename*0*="bogus'xx'This%20is%20even%20more%20";
-\tfilename*1*="%2A%2A%2Afun%2A%2A%2A%20";
-\tfilename*2="is it not.pdf"
-
-'''
- msg = email.message_from_string(m)
- self.assertEqual(msg.get_filename(),
- 'This is even more ***fun*** is it not.pdf')
-
- def test_rfc2231_bad_encoding_in_charset(self):
- m = """\
-Content-Type: text/plain; charset*=bogus''utf-8%E2%80%9D
-
-"""
- msg = email.message_from_string(m)
- # This should return None because non-ascii characters in the charset
- # are not allowed.
- self.assertEqual(msg.get_content_charset(), None)
-
- def test_rfc2231_bad_character_in_charset(self):
- m = """\
-Content-Type: text/plain; charset*=ascii''utf-8%E2%80%9D
-
-"""
- msg = email.message_from_string(m)
- # This should return None because non-ascii characters in the charset
- # are not allowed.
- self.assertEqual(msg.get_content_charset(), None)
-
- def test_rfc2231_bad_character_in_filename(self):
- m = '''\
-Content-Disposition: inline;
-\tfilename*0*="ascii'xx'This%20is%20even%20more%20";
-\tfilename*1*="%2A%2A%2Afun%2A%2A%2A%20";
-\tfilename*2*="is it not.pdf%E2"
-
-'''
- msg = email.message_from_string(m)
- self.assertEqual(msg.get_filename(),
- 'This is even more ***fun*** is it not.pdf\ufffd')
-
- def test_rfc2231_unknown_encoding(self):
- m = """\
-Content-Transfer-Encoding: 8bit
-Content-Disposition: inline; filename*=X-UNKNOWN''myfile.txt
-
-"""
- msg = email.message_from_string(m)
- self.assertEqual(msg.get_filename(), 'myfile.txt')
-
- def test_rfc2231_single_tick_in_filename_extended(self):
- eq = self.assertEqual
- m = """\
-Content-Type: application/x-foo;
-\tname*0*=\"Frank's\"; name*1*=\" Document\"
-
-"""
- msg = email.message_from_string(m)
- charset, language, s = msg.get_param('name')
- eq(charset, None)
- eq(language, None)
- eq(s, "Frank's Document")
-
- def test_rfc2231_single_tick_in_filename(self):
- m = """\
-Content-Type: application/x-foo; name*0=\"Frank's\"; name*1=\" Document\"
-
-"""
- msg = email.message_from_string(m)
- param = msg.get_param('name')
- self.failIf(isinstance(param, tuple))
- self.assertEqual(param, "Frank's Document")
-
- def test_rfc2231_tick_attack_extended(self):
- eq = self.assertEqual
- m = """\
-Content-Type: application/x-foo;
-\tname*0*=\"us-ascii'en-us'Frank's\"; name*1*=\" Document\"
-
-"""
- msg = email.message_from_string(m)
- charset, language, s = msg.get_param('name')
- eq(charset, 'us-ascii')
- eq(language, 'en-us')
- eq(s, "Frank's Document")
-
- def test_rfc2231_tick_attack(self):
- m = """\
-Content-Type: application/x-foo;
-\tname*0=\"us-ascii'en-us'Frank's\"; name*1=\" Document\"
-
-"""
- msg = email.message_from_string(m)
- param = msg.get_param('name')
- self.failIf(isinstance(param, tuple))
- self.assertEqual(param, "us-ascii'en-us'Frank's Document")
-
- def test_rfc2231_no_extended_values(self):
- eq = self.assertEqual
- m = """\
-Content-Type: application/x-foo; name=\"Frank's Document\"
-
-"""
- msg = email.message_from_string(m)
- eq(msg.get_param('name'), "Frank's Document")
-
- def test_rfc2231_encoded_then_unencoded_segments(self):
- eq = self.assertEqual
- m = """\
-Content-Type: application/x-foo;
-\tname*0*=\"us-ascii'en-us'My\";
-\tname*1=\" Document\";
-\tname*2*=\" For You\"
-
-"""
- msg = email.message_from_string(m)
- charset, language, s = msg.get_param('name')
- eq(charset, 'us-ascii')
- eq(language, 'en-us')
- eq(s, 'My Document For You')
-
- def test_rfc2231_unencoded_then_encoded_segments(self):
- eq = self.assertEqual
- m = """\
-Content-Type: application/x-foo;
-\tname*0=\"us-ascii'en-us'My\";
-\tname*1*=\" Document\";
-\tname*2*=\" For You\"
-
-"""
- msg = email.message_from_string(m)
- charset, language, s = msg.get_param('name')
- eq(charset, 'us-ascii')
- eq(language, 'en-us')
- eq(s, 'My Document For You')
-
-
-
-def _testclasses():
- mod = sys.modules[__name__]
- return [getattr(mod, name) for name in dir(mod) if name.startswith('Test')]
-
-
-def suite():
- suite = unittest.TestSuite()
- for testclass in _testclasses():
- suite.addTest(unittest.makeSuite(testclass))
- return suite
-
-
-def test_main():
- for testclass in _testclasses():
- run_unittest(testclass)
-
-
-
-if __name__ == '__main__':
- unittest.main(defaultTest='suite')
diff --git a/Lib/email/test/test_email_codecs.py b/Lib/email/test/test_email_codecs.py
deleted file mode 100644
index 1c77347..0000000
--- a/Lib/email/test/test_email_codecs.py
+++ /dev/null
@@ -1,77 +0,0 @@
-# Copyright (C) 2002-2006 Python Software Foundation
-# Contact: email-sig@python.org
-# email package unit tests for (optional) Asian codecs
-
-import unittest
-from test.test_support import TestSkipped, run_unittest
-
-from email.test.test_email import TestEmailBase
-from email.Charset import Charset
-from email.Header import Header, decode_header
-from email.Message import Message
-
-# We're compatible with Python 2.3, but it doesn't have the built-in Asian
-# codecs, so we have to skip all these tests.
-try:
- str('foo', 'euc-jp')
-except LookupError:
- raise TestSkipped
-
-
-
-class TestEmailAsianCodecs(TestEmailBase):
- def test_japanese_codecs(self):
- eq = self.ndiffAssertEqual
- j = Charset("euc-jp")
- g = Charset("iso-8859-1")
- h = Header("Hello World!")
- jhello = '\xa5\xcf\xa5\xed\xa1\xbc\xa5\xef\xa1\xbc\xa5\xeb\xa5\xc9\xa1\xaa'
- ghello = 'Gr\xfc\xdf Gott!'
- h.append(jhello, j)
- h.append(ghello, g)
- # BAW: This used to -- and maybe should -- fold the two iso-8859-1
- # chunks into a single encoded word. However it doesn't violate the
- # standard to have them as two encoded chunks and maybe it's
- # reasonable <wink> for each .append() call to result in a separate
- # encoded word.
- eq(h.encode(), """\
-Hello World! =?iso-2022-jp?b?GyRCJU8lbSE8JW8hPCVrJUkhKhsoQg==?=
- =?iso-8859-1?q?Gr=FC=DF?= =?iso-8859-1?q?_Gott!?=""")
- eq(decode_header(h.encode()),
- [('Hello World!', None),
- ('\x1b$B%O%m!<%o!<%k%I!*\x1b(B', 'iso-2022-jp'),
- ('Gr\xfc\xdf Gott!', 'iso-8859-1')])
- int = 'test-ja \xa4\xd8\xc5\xea\xb9\xc6\xa4\xb5\xa4\xec\xa4\xbf\xa5\xe1\xa1\xbc\xa5\xeb\xa4\xcf\xbb\xca\xb2\xf1\xbc\xd4\xa4\xce\xbe\xb5\xc7\xa7\xa4\xf2\xc2\xd4\xa4\xc3\xa4\xc6\xa4\xa4\xa4\xde\xa4\xb9'
- h = Header(int, j, header_name="Subject")
- # test a very long header
- enc = h.encode()
- # TK: splitting point may differ by codec design and/or Header encoding
- eq(enc , """\
-=?iso-2022-jp?b?dGVzdC1qYSAbJEIkWEVqOUYkNSRsJD8lYSE8JWskTztKGyhC?=
- =?iso-2022-jp?b?GyRCMnE8VCROPjVHJyRyQlQkQyRGJCQkXiQ5GyhC?=""")
- # TK: full decode comparison
- eq(h.__unicode__().encode('euc-jp'), int)
-
- def test_payload_encoding(self):
- jhello = '\xa5\xcf\xa5\xed\xa1\xbc\xa5\xef\xa1\xbc\xa5\xeb\xa5\xc9\xa1\xaa'
- jcode = 'euc-jp'
- msg = Message()
- msg.set_payload(jhello, jcode)
- ustr = str(msg.get_payload(), msg.get_content_charset())
- self.assertEqual(jhello, ustr.encode(jcode))
-
-
-
-def suite():
- suite = unittest.TestSuite()
- suite.addTest(unittest.makeSuite(TestEmailAsianCodecs))
- return suite
-
-
-def test_main():
- run_unittest(TestEmailAsianCodecs)
-
-
-
-if __name__ == '__main__':
- unittest.main(defaultTest='suite')
diff --git a/Lib/email/test/test_email_codecs_renamed.py b/Lib/email/test/test_email_codecs_renamed.py
deleted file mode 100644
index d190de3..0000000
--- a/Lib/email/test/test_email_codecs_renamed.py
+++ /dev/null
@@ -1,77 +0,0 @@
-# Copyright (C) 2002-2006 Python Software Foundation
-# Contact: email-sig@python.org
-# email package unit tests for (optional) Asian codecs
-
-import unittest
-from test.test_support import TestSkipped, run_unittest
-
-from email.test.test_email import TestEmailBase
-from email.charset import Charset
-from email.header import Header, decode_header
-from email.message import Message
-
-# We're compatible with Python 2.3, but it doesn't have the built-in Asian
-# codecs, so we have to skip all these tests.
-try:
- str('foo', 'euc-jp')
-except LookupError:
- raise TestSkipped
-
-
-
-class TestEmailAsianCodecs(TestEmailBase):
- def test_japanese_codecs(self):
- eq = self.ndiffAssertEqual
- j = Charset("euc-jp")
- g = Charset("iso-8859-1")
- h = Header("Hello World!")
- jhello = '\xa5\xcf\xa5\xed\xa1\xbc\xa5\xef\xa1\xbc\xa5\xeb\xa5\xc9\xa1\xaa'
- ghello = 'Gr\xfc\xdf Gott!'
- h.append(jhello, j)
- h.append(ghello, g)
- # BAW: This used to -- and maybe should -- fold the two iso-8859-1
- # chunks into a single encoded word. However it doesn't violate the
- # standard to have them as two encoded chunks and maybe it's
- # reasonable <wink> for each .append() call to result in a separate
- # encoded word.
- eq(h.encode(), """\
-Hello World! =?iso-2022-jp?b?GyRCJU8lbSE8JW8hPCVrJUkhKhsoQg==?=
- =?iso-8859-1?q?Gr=FC=DF?= =?iso-8859-1?q?_Gott!?=""")
- eq(decode_header(h.encode()),
- [('Hello World!', None),
- ('\x1b$B%O%m!<%o!<%k%I!*\x1b(B', 'iso-2022-jp'),
- ('Gr\xfc\xdf Gott!', 'iso-8859-1')])
- int = 'test-ja \xa4\xd8\xc5\xea\xb9\xc6\xa4\xb5\xa4\xec\xa4\xbf\xa5\xe1\xa1\xbc\xa5\xeb\xa4\xcf\xbb\xca\xb2\xf1\xbc\xd4\xa4\xce\xbe\xb5\xc7\xa7\xa4\xf2\xc2\xd4\xa4\xc3\xa4\xc6\xa4\xa4\xa4\xde\xa4\xb9'
- h = Header(int, j, header_name="Subject")
- # test a very long header
- enc = h.encode()
- # TK: splitting point may differ by codec design and/or Header encoding
- eq(enc , """\
-=?iso-2022-jp?b?dGVzdC1qYSAbJEIkWEVqOUYkNSRsJD8lYSE8JWskTztKGyhC?=
- =?iso-2022-jp?b?GyRCMnE8VCROPjVHJyRyQlQkQyRGJCQkXiQ5GyhC?=""")
- # TK: full decode comparison
- eq(h.__unicode__().encode('euc-jp'), int)
-
- def test_payload_encoding(self):
- jhello = '\xa5\xcf\xa5\xed\xa1\xbc\xa5\xef\xa1\xbc\xa5\xeb\xa5\xc9\xa1\xaa'
- jcode = 'euc-jp'
- msg = Message()
- msg.set_payload(jhello, jcode)
- ustr = str(msg.get_payload(), msg.get_content_charset())
- self.assertEqual(jhello, ustr.encode(jcode))
-
-
-
-def suite():
- suite = unittest.TestSuite()
- suite.addTest(unittest.makeSuite(TestEmailAsianCodecs))
- return suite
-
-
-def test_main():
- run_unittest(TestEmailAsianCodecs)
-
-
-
-if __name__ == '__main__':
- unittest.main(defaultTest='suite')
diff --git a/Lib/email/test/test_email_renamed.py b/Lib/email/test/test_email_renamed.py
deleted file mode 100644
index ea5b1a1..0000000
--- a/Lib/email/test/test_email_renamed.py
+++ /dev/null
@@ -1,3283 +0,0 @@
-# Copyright (C) 2001-2007 Python Software Foundation
-# Contact: email-sig@python.org
-# email package unit tests
-
-import os
-import sys
-import time
-import base64
-import difflib
-import unittest
-import warnings
-from io import StringIO
-
-import email
-
-from email.charset import Charset
-from email.header import Header, decode_header, make_header
-from email.parser import Parser, HeaderParser
-from email.generator import Generator, DecodedGenerator
-from email.message import Message
-from email.mime.application import MIMEApplication
-from email.mime.audio import MIMEAudio
-from email.mime.text import MIMEText
-from email.mime.image import MIMEImage
-from email.mime.base import MIMEBase
-from email.mime.message import MIMEMessage
-from email.mime.multipart import MIMEMultipart
-from email import utils
-from email import errors
-from email import encoders
-from email import iterators
-from email import base64mime
-from email import quoprimime
-
-from test.test_support import findfile, run_unittest
-from email.test import __file__ as landmark
-
-
-NL = '\n'
-EMPTYSTRING = ''
-SPACE = ' '
-
-
-
-def openfile(filename, mode='r'):
- path = os.path.join(os.path.dirname(landmark), 'data', filename)
- return open(path, mode)
-
-
-
-# Base test class
-class TestEmailBase(unittest.TestCase):
- def ndiffAssertEqual(self, first, second):
- """Like failUnlessEqual except use ndiff for readable output."""
- if first != second:
- sfirst = str(first)
- ssecond = str(second)
- diff = difflib.ndiff(sfirst.splitlines(True),
- ssecond.splitlines(True))
- raise self.failureException(NL + "".join(diff))
-
- def _msgobj(self, filename):
- fp = openfile(findfile(filename))
- try:
- msg = email.message_from_file(fp)
- finally:
- fp.close()
- return msg
-
-
-
-# Test various aspects of the Message class's API
-class TestMessageAPI(TestEmailBase):
- def test_get_all(self):
- eq = self.assertEqual
- msg = self._msgobj('msg_20.txt')
- eq(msg.get_all('cc'), ['ccc@zzz.org', 'ddd@zzz.org', 'eee@zzz.org'])
- eq(msg.get_all('xx', 'n/a'), 'n/a')
-
- def test_getset_charset(self):
- eq = self.assertEqual
- msg = Message()
- eq(msg.get_charset(), None)
- charset = Charset('iso-8859-1')
- msg.set_charset(charset)
- eq(msg['mime-version'], '1.0')
- eq(msg.get_content_type(), 'text/plain')
- eq(msg['content-type'], 'text/plain; charset="iso-8859-1"')
- eq(msg.get_param('charset'), 'iso-8859-1')
- eq(msg['content-transfer-encoding'], 'quoted-printable')
- eq(msg.get_charset().input_charset, 'iso-8859-1')
- # Remove the charset
- msg.set_charset(None)
- eq(msg.get_charset(), None)
- eq(msg['content-type'], 'text/plain')
- # Try adding a charset when there's already MIME headers present
- msg = Message()
- msg['MIME-Version'] = '2.0'
- msg['Content-Type'] = 'text/x-weird'
- msg['Content-Transfer-Encoding'] = 'quinted-puntable'
- msg.set_charset(charset)
- eq(msg['mime-version'], '2.0')
- eq(msg['content-type'], 'text/x-weird; charset="iso-8859-1"')
- eq(msg['content-transfer-encoding'], 'quinted-puntable')
-
- def test_set_charset_from_string(self):
- eq = self.assertEqual
- msg = Message()
- msg.set_charset('us-ascii')
- eq(msg.get_charset().input_charset, 'us-ascii')
- eq(msg['content-type'], 'text/plain; charset="us-ascii"')
-
- def test_set_payload_with_charset(self):
- msg = Message()
- charset = Charset('iso-8859-1')
- msg.set_payload('This is a string payload', charset)
- self.assertEqual(msg.get_charset().input_charset, 'iso-8859-1')
-
- def test_get_charsets(self):
- eq = self.assertEqual
-
- msg = self._msgobj('msg_08.txt')
- charsets = msg.get_charsets()
- eq(charsets, [None, 'us-ascii', 'iso-8859-1', 'iso-8859-2', 'koi8-r'])
-
- msg = self._msgobj('msg_09.txt')
- charsets = msg.get_charsets('dingbat')
- eq(charsets, ['dingbat', 'us-ascii', 'iso-8859-1', 'dingbat',
- 'koi8-r'])
-
- msg = self._msgobj('msg_12.txt')
- charsets = msg.get_charsets()
- eq(charsets, [None, 'us-ascii', 'iso-8859-1', None, 'iso-8859-2',
- 'iso-8859-3', 'us-ascii', 'koi8-r'])
-
- def test_get_filename(self):
- eq = self.assertEqual
-
- msg = self._msgobj('msg_04.txt')
- filenames = [p.get_filename() for p in msg.get_payload()]
- eq(filenames, ['msg.txt', 'msg.txt'])
-
- msg = self._msgobj('msg_07.txt')
- subpart = msg.get_payload(1)
- eq(subpart.get_filename(), 'dingusfish.gif')
-
- def test_get_filename_with_name_parameter(self):
- eq = self.assertEqual
-
- msg = self._msgobj('msg_44.txt')
- filenames = [p.get_filename() for p in msg.get_payload()]
- eq(filenames, ['msg.txt', 'msg.txt'])
-
- def test_get_boundary(self):
- eq = self.assertEqual
- msg = self._msgobj('msg_07.txt')
- # No quotes!
- eq(msg.get_boundary(), 'BOUNDARY')
-
- def test_set_boundary(self):
- eq = self.assertEqual
- # This one has no existing boundary parameter, but the Content-Type:
- # header appears fifth.
- msg = self._msgobj('msg_01.txt')
- msg.set_boundary('BOUNDARY')
- header, value = msg.items()[4]
- eq(header.lower(), 'content-type')
- eq(value, 'text/plain; charset="us-ascii"; boundary="BOUNDARY"')
- # This one has a Content-Type: header, with a boundary, stuck in the
- # middle of its headers. Make sure the order is preserved; it should
- # be fifth.
- msg = self._msgobj('msg_04.txt')
- msg.set_boundary('BOUNDARY')
- header, value = msg.items()[4]
- eq(header.lower(), 'content-type')
- eq(value, 'multipart/mixed; boundary="BOUNDARY"')
- # And this one has no Content-Type: header at all.
- msg = self._msgobj('msg_03.txt')
- self.assertRaises(errors.HeaderParseError,
- msg.set_boundary, 'BOUNDARY')
-
- def test_get_decoded_payload(self):
- eq = self.assertEqual
- msg = self._msgobj('msg_10.txt')
- # The outer message is a multipart
- eq(msg.get_payload(decode=True), None)
- # Subpart 1 is 7bit encoded
- eq(msg.get_payload(0).get_payload(decode=True),
- 'This is a 7bit encoded message.\n')
- # Subpart 2 is quopri
- eq(msg.get_payload(1).get_payload(decode=True),
- '\xa1This is a Quoted Printable encoded message!\n')
- # Subpart 3 is base64
- eq(msg.get_payload(2).get_payload(decode=True),
- 'This is a Base64 encoded message.')
- # Subpart 4 has no Content-Transfer-Encoding: header.
- eq(msg.get_payload(3).get_payload(decode=True),
- 'This has no Content-Transfer-Encoding: header.\n')
-
- def test_get_decoded_uu_payload(self):
- eq = self.assertEqual
- msg = Message()
- msg.set_payload('begin 666 -\n+:&5L;&\\@=V]R;&0 \n \nend\n')
- for cte in ('x-uuencode', 'uuencode', 'uue', 'x-uue'):
- msg['content-transfer-encoding'] = cte
- eq(msg.get_payload(decode=True), 'hello world')
- # Now try some bogus data
- msg.set_payload('foo')
- eq(msg.get_payload(decode=True), 'foo')
-
- def test_decoded_generator(self):
- eq = self.assertEqual
- msg = self._msgobj('msg_07.txt')
- fp = openfile('msg_17.txt')
- try:
- text = fp.read()
- finally:
- fp.close()
- s = StringIO()
- g = DecodedGenerator(s)
- g.flatten(msg)
- eq(s.getvalue(), text)
-
- def test__contains__(self):
- msg = Message()
- msg['From'] = 'Me'
- msg['to'] = 'You'
- # Check for case insensitivity
- self.failUnless('from' in msg)
- self.failUnless('From' in msg)
- self.failUnless('FROM' in msg)
- self.failUnless('to' in msg)
- self.failUnless('To' in msg)
- self.failUnless('TO' in msg)
-
- def test_as_string(self):
- eq = self.assertEqual
- msg = self._msgobj('msg_01.txt')
- fp = openfile('msg_01.txt')
- try:
- text = fp.read()
- finally:
- fp.close()
- eq(text, msg.as_string())
- fullrepr = str(msg)
- lines = fullrepr.split('\n')
- self.failUnless(lines[0].startswith('From '))
- eq(text, NL.join(lines[1:]))
-
- def test_bad_param(self):
- msg = email.message_from_string("Content-Type: blarg; baz; boo\n")
- self.assertEqual(msg.get_param('baz'), '')
-
- def test_missing_filename(self):
- msg = email.message_from_string("From: foo\n")
- self.assertEqual(msg.get_filename(), None)
-
- def test_bogus_filename(self):
- msg = email.message_from_string(
- "Content-Disposition: blarg; filename\n")
- self.assertEqual(msg.get_filename(), '')
-
- def test_missing_boundary(self):
- msg = email.message_from_string("From: foo\n")
- self.assertEqual(msg.get_boundary(), None)
-
- def test_get_params(self):
- eq = self.assertEqual
- msg = email.message_from_string(
- 'X-Header: foo=one; bar=two; baz=three\n')
- eq(msg.get_params(header='x-header'),
- [('foo', 'one'), ('bar', 'two'), ('baz', 'three')])
- msg = email.message_from_string(
- 'X-Header: foo; bar=one; baz=two\n')
- eq(msg.get_params(header='x-header'),
- [('foo', ''), ('bar', 'one'), ('baz', 'two')])
- eq(msg.get_params(), None)
- msg = email.message_from_string(
- 'X-Header: foo; bar="one"; baz=two\n')
- eq(msg.get_params(header='x-header'),
- [('foo', ''), ('bar', 'one'), ('baz', 'two')])
-
- def test_get_param_liberal(self):
- msg = Message()
- msg['Content-Type'] = 'Content-Type: Multipart/mixed; boundary = "CPIMSSMTPC06p5f3tG"'
- self.assertEqual(msg.get_param('boundary'), 'CPIMSSMTPC06p5f3tG')
-
- def test_get_param(self):
- eq = self.assertEqual
- msg = email.message_from_string(
- "X-Header: foo=one; bar=two; baz=three\n")
- eq(msg.get_param('bar', header='x-header'), 'two')
- eq(msg.get_param('quuz', header='x-header'), None)
- eq(msg.get_param('quuz'), None)
- msg = email.message_from_string(
- 'X-Header: foo; bar="one"; baz=two\n')
- eq(msg.get_param('foo', header='x-header'), '')
- eq(msg.get_param('bar', header='x-header'), 'one')
- eq(msg.get_param('baz', header='x-header'), 'two')
- # XXX: We are not RFC-2045 compliant! We cannot parse:
- # msg["Content-Type"] = 'text/plain; weird="hey; dolly? [you] @ <\\"home\\">?"'
- # msg.get_param("weird")
- # yet.
-
- def test_get_param_funky_continuation_lines(self):
- msg = self._msgobj('msg_22.txt')
- self.assertEqual(msg.get_payload(1).get_param('name'), 'wibble.JPG')
-
- def test_get_param_with_semis_in_quotes(self):
- msg = email.message_from_string(
- 'Content-Type: image/pjpeg; name="Jim&amp;&amp;Jill"\n')
- self.assertEqual(msg.get_param('name'), 'Jim&amp;&amp;Jill')
- self.assertEqual(msg.get_param('name', unquote=False),
- '"Jim&amp;&amp;Jill"')
-
- def test_has_key(self):
- msg = email.message_from_string('Header: exists')
- self.failUnless(msg.has_key('header'))
- self.failUnless(msg.has_key('Header'))
- self.failUnless(msg.has_key('HEADER'))
- self.failIf(msg.has_key('headeri'))
-
- def test_set_param(self):
- eq = self.assertEqual
- msg = Message()
- msg.set_param('charset', 'iso-2022-jp')
- eq(msg.get_param('charset'), 'iso-2022-jp')
- msg.set_param('importance', 'high value')
- eq(msg.get_param('importance'), 'high value')
- eq(msg.get_param('importance', unquote=False), '"high value"')
- eq(msg.get_params(), [('text/plain', ''),
- ('charset', 'iso-2022-jp'),
- ('importance', 'high value')])
- eq(msg.get_params(unquote=False), [('text/plain', ''),
- ('charset', '"iso-2022-jp"'),
- ('importance', '"high value"')])
- msg.set_param('charset', 'iso-9999-xx', header='X-Jimmy')
- eq(msg.get_param('charset', header='X-Jimmy'), 'iso-9999-xx')
-
- def test_del_param(self):
- eq = self.assertEqual
- msg = self._msgobj('msg_05.txt')
- eq(msg.get_params(),
- [('multipart/report', ''), ('report-type', 'delivery-status'),
- ('boundary', 'D1690A7AC1.996856090/mail.example.com')])
- old_val = msg.get_param("report-type")
- msg.del_param("report-type")
- eq(msg.get_params(),
- [('multipart/report', ''),
- ('boundary', 'D1690A7AC1.996856090/mail.example.com')])
- msg.set_param("report-type", old_val)
- eq(msg.get_params(),
- [('multipart/report', ''),
- ('boundary', 'D1690A7AC1.996856090/mail.example.com'),
- ('report-type', old_val)])
-
- def test_del_param_on_other_header(self):
- msg = Message()
- msg.add_header('Content-Disposition', 'attachment', filename='bud.gif')
- msg.del_param('filename', 'content-disposition')
- self.assertEqual(msg['content-disposition'], 'attachment')
-
- def test_set_type(self):
- eq = self.assertEqual
- msg = Message()
- self.assertRaises(ValueError, msg.set_type, 'text')
- msg.set_type('text/plain')
- eq(msg['content-type'], 'text/plain')
- msg.set_param('charset', 'us-ascii')
- eq(msg['content-type'], 'text/plain; charset="us-ascii"')
- msg.set_type('text/html')
- eq(msg['content-type'], 'text/html; charset="us-ascii"')
-
- def test_set_type_on_other_header(self):
- msg = Message()
- msg['X-Content-Type'] = 'text/plain'
- msg.set_type('application/octet-stream', 'X-Content-Type')
- self.assertEqual(msg['x-content-type'], 'application/octet-stream')
-
- def test_get_content_type_missing(self):
- msg = Message()
- self.assertEqual(msg.get_content_type(), 'text/plain')
-
- def test_get_content_type_missing_with_default_type(self):
- msg = Message()
- msg.set_default_type('message/rfc822')
- self.assertEqual(msg.get_content_type(), 'message/rfc822')
-
- def test_get_content_type_from_message_implicit(self):
- msg = self._msgobj('msg_30.txt')
- self.assertEqual(msg.get_payload(0).get_content_type(),
- 'message/rfc822')
-
- def test_get_content_type_from_message_explicit(self):
- msg = self._msgobj('msg_28.txt')
- self.assertEqual(msg.get_payload(0).get_content_type(),
- 'message/rfc822')
-
- def test_get_content_type_from_message_text_plain_implicit(self):
- msg = self._msgobj('msg_03.txt')
- self.assertEqual(msg.get_content_type(), 'text/plain')
-
- def test_get_content_type_from_message_text_plain_explicit(self):
- msg = self._msgobj('msg_01.txt')
- self.assertEqual(msg.get_content_type(), 'text/plain')
-
- def test_get_content_maintype_missing(self):
- msg = Message()
- self.assertEqual(msg.get_content_maintype(), 'text')
-
- def test_get_content_maintype_missing_with_default_type(self):
- msg = Message()
- msg.set_default_type('message/rfc822')
- self.assertEqual(msg.get_content_maintype(), 'message')
-
- def test_get_content_maintype_from_message_implicit(self):
- msg = self._msgobj('msg_30.txt')
- self.assertEqual(msg.get_payload(0).get_content_maintype(), 'message')
-
- def test_get_content_maintype_from_message_explicit(self):
- msg = self._msgobj('msg_28.txt')
- self.assertEqual(msg.get_payload(0).get_content_maintype(), 'message')
-
- def test_get_content_maintype_from_message_text_plain_implicit(self):
- msg = self._msgobj('msg_03.txt')
- self.assertEqual(msg.get_content_maintype(), 'text')
-
- def test_get_content_maintype_from_message_text_plain_explicit(self):
- msg = self._msgobj('msg_01.txt')
- self.assertEqual(msg.get_content_maintype(), 'text')
-
- def test_get_content_subtype_missing(self):
- msg = Message()
- self.assertEqual(msg.get_content_subtype(), 'plain')
-
- def test_get_content_subtype_missing_with_default_type(self):
- msg = Message()
- msg.set_default_type('message/rfc822')
- self.assertEqual(msg.get_content_subtype(), 'rfc822')
-
- def test_get_content_subtype_from_message_implicit(self):
- msg = self._msgobj('msg_30.txt')
- self.assertEqual(msg.get_payload(0).get_content_subtype(), 'rfc822')
-
- def test_get_content_subtype_from_message_explicit(self):
- msg = self._msgobj('msg_28.txt')
- self.assertEqual(msg.get_payload(0).get_content_subtype(), 'rfc822')
-
- def test_get_content_subtype_from_message_text_plain_implicit(self):
- msg = self._msgobj('msg_03.txt')
- self.assertEqual(msg.get_content_subtype(), 'plain')
-
- def test_get_content_subtype_from_message_text_plain_explicit(self):
- msg = self._msgobj('msg_01.txt')
- self.assertEqual(msg.get_content_subtype(), 'plain')
-
- def test_get_content_maintype_error(self):
- msg = Message()
- msg['Content-Type'] = 'no-slash-in-this-string'
- self.assertEqual(msg.get_content_maintype(), 'text')
-
- def test_get_content_subtype_error(self):
- msg = Message()
- msg['Content-Type'] = 'no-slash-in-this-string'
- self.assertEqual(msg.get_content_subtype(), 'plain')
-
- def test_replace_header(self):
- eq = self.assertEqual
- msg = Message()
- msg.add_header('First', 'One')
- msg.add_header('Second', 'Two')
- msg.add_header('Third', 'Three')
- eq(msg.keys(), ['First', 'Second', 'Third'])
- eq(msg.values(), ['One', 'Two', 'Three'])
- msg.replace_header('Second', 'Twenty')
- eq(msg.keys(), ['First', 'Second', 'Third'])
- eq(msg.values(), ['One', 'Twenty', 'Three'])
- msg.add_header('First', 'Eleven')
- msg.replace_header('First', 'One Hundred')
- eq(msg.keys(), ['First', 'Second', 'Third', 'First'])
- eq(msg.values(), ['One Hundred', 'Twenty', 'Three', 'Eleven'])
- self.assertRaises(KeyError, msg.replace_header, 'Fourth', 'Missing')
-
- def test_broken_base64_payload(self):
- x = 'AwDp0P7//y6LwKEAcPa/6Q=9'
- msg = Message()
- msg['content-type'] = 'audio/x-midi'
- msg['content-transfer-encoding'] = 'base64'
- msg.set_payload(x)
- self.assertEqual(msg.get_payload(decode=True), x)
-
-
-
-# Test the email.encoders module
-class TestEncoders(unittest.TestCase):
- def test_encode_empty_payload(self):
- eq = self.assertEqual
- msg = Message()
- msg.set_charset('us-ascii')
- eq(msg['content-transfer-encoding'], '7bit')
-
- def test_default_cte(self):
- eq = self.assertEqual
- msg = MIMEText('hello world')
- eq(msg['content-transfer-encoding'], '7bit')
-
- def test_default_cte(self):
- eq = self.assertEqual
- # With no explicit _charset its us-ascii, and all are 7-bit
- msg = MIMEText('hello world')
- eq(msg['content-transfer-encoding'], '7bit')
- # Similar, but with 8-bit data
- msg = MIMEText('hello \xf8 world')
- eq(msg['content-transfer-encoding'], '8bit')
- # And now with a different charset
- msg = MIMEText('hello \xf8 world', _charset='iso-8859-1')
- eq(msg['content-transfer-encoding'], 'quoted-printable')
-
-
-
-# Test long header wrapping
-class TestLongHeaders(TestEmailBase):
- def test_split_long_continuation(self):
- eq = self.ndiffAssertEqual
- msg = email.message_from_string("""\
-Subject: bug demonstration
-\t12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789
-\tmore text
-
-test
-""")
- sfp = StringIO()
- g = Generator(sfp)
- g.flatten(msg)
- eq(sfp.getvalue(), """\
-Subject: bug demonstration
-\t12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789
-\tmore text
-
-test
-""")
-
- def test_another_long_almost_unsplittable_header(self):
- eq = self.ndiffAssertEqual
- hstr = """\
-bug demonstration
-\t12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789
-\tmore text"""
- h = Header(hstr, continuation_ws='\t')
- eq(h.encode(), """\
-bug demonstration
-\t12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789
-\tmore text""")
- h = Header(hstr)
- eq(h.encode(), """\
-bug demonstration
- 12345678911234567892123456789312345678941234567895123456789612345678971234567898112345678911234567892123456789112345678911234567892123456789
- more text""")
-
- def test_long_nonstring(self):
- eq = self.ndiffAssertEqual
- g = Charset("iso-8859-1")
- cz = Charset("iso-8859-2")
- utf8 = Charset("utf-8")
- g_head = "Die Mieter treten hier ein werden mit einem Foerderband komfortabel den Korridor entlang, an s\xfcdl\xfcndischen Wandgem\xe4lden vorbei, gegen die rotierenden Klingen bef\xf6rdert. "
- cz_head = "Finan\xe8ni metropole se hroutily pod tlakem jejich d\xf9vtipu.. "
- utf8_head = "\u6b63\u78ba\u306b\u8a00\u3046\u3068\u7ffb\u8a33\u306f\u3055\u308c\u3066\u3044\u307e\u305b\u3093\u3002\u4e00\u90e8\u306f\u30c9\u30a4\u30c4\u8a9e\u3067\u3059\u304c\u3001\u3042\u3068\u306f\u3067\u305f\u3089\u3081\u3067\u3059\u3002\u5b9f\u969b\u306b\u306f\u300cWenn ist das Nunstuck git und Slotermeyer? Ja! Beiherhund das Oder die Flipperwaldt gersput.\u300d\u3068\u8a00\u3063\u3066\u3044\u307e\u3059\u3002".encode("utf-8")
- h = Header(g_head, g, header_name='Subject')
- h.append(cz_head, cz)
- h.append(utf8_head, utf8)
- msg = Message()
- msg['Subject'] = h
- sfp = StringIO()
- g = Generator(sfp)
- g.flatten(msg)
- eq(sfp.getvalue(), """\
-Subject: =?iso-8859-1?q?Die_Mieter_treten_hier_ein_werden_mit_einem_Foerd?=
- =?iso-8859-1?q?erband_komfortabel_den_Korridor_entlang=2C_an_s=FCdl=FCndi?=
- =?iso-8859-1?q?schen_Wandgem=E4lden_vorbei=2C_gegen_die_rotierenden_Kling?=
- =?iso-8859-1?q?en_bef=F6rdert=2E_?= =?iso-8859-2?q?Finan=E8ni_met?=
- =?iso-8859-2?q?ropole_se_hroutily_pod_tlakem_jejich_d=F9vtipu=2E=2E_?=
- =?utf-8?b?5q2j56K644Gr6KiA44GG44Go57+76Kiz44Gv44GV44KM44Gm44GE?=
- =?utf-8?b?44G+44Gb44KT44CC5LiA6YOo44Gv44OJ44Kk44OE6Kqe44Gn44GZ44GM44CB?=
- =?utf-8?b?44GC44Go44Gv44Gn44Gf44KJ44KB44Gn44GZ44CC5a6f6Zqb44Gr44Gv44CM?=
- =?utf-8?q?Wenn_ist_das_Nunstuck_git_und_Slotermeyer=3F_Ja!_Beiherhund_das?=
- =?utf-8?b?IE9kZXIgZGllIEZsaXBwZXJ3YWxkdCBnZXJzcHV0LuOAjeOBqOiogOOBow==?=
- =?utf-8?b?44Gm44GE44G+44GZ44CC?=
-
-""")
- eq(h.encode(), """\
-=?iso-8859-1?q?Die_Mieter_treten_hier_ein_werden_mit_einem_Foerd?=
- =?iso-8859-1?q?erband_komfortabel_den_Korridor_entlang=2C_an_s=FCdl=FCndi?=
- =?iso-8859-1?q?schen_Wandgem=E4lden_vorbei=2C_gegen_die_rotierenden_Kling?=
- =?iso-8859-1?q?en_bef=F6rdert=2E_?= =?iso-8859-2?q?Finan=E8ni_met?=
- =?iso-8859-2?q?ropole_se_hroutily_pod_tlakem_jejich_d=F9vtipu=2E=2E_?=
- =?utf-8?b?5q2j56K644Gr6KiA44GG44Go57+76Kiz44Gv44GV44KM44Gm44GE?=
- =?utf-8?b?44G+44Gb44KT44CC5LiA6YOo44Gv44OJ44Kk44OE6Kqe44Gn44GZ44GM44CB?=
- =?utf-8?b?44GC44Go44Gv44Gn44Gf44KJ44KB44Gn44GZ44CC5a6f6Zqb44Gr44Gv44CM?=
- =?utf-8?q?Wenn_ist_das_Nunstuck_git_und_Slotermeyer=3F_Ja!_Beiherhund_das?=
- =?utf-8?b?IE9kZXIgZGllIEZsaXBwZXJ3YWxkdCBnZXJzcHV0LuOAjeOBqOiogOOBow==?=
- =?utf-8?b?44Gm44GE44G+44GZ44CC?=""")
-
- def test_long_header_encode(self):
- eq = self.ndiffAssertEqual
- h = Header('wasnipoop; giraffes="very-long-necked-animals"; '
- 'spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"',
- header_name='X-Foobar-Spoink-Defrobnit')
- eq(h.encode(), '''\
-wasnipoop; giraffes="very-long-necked-animals";
- spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"''')
-
- def test_long_header_encode_with_tab_continuation(self):
- eq = self.ndiffAssertEqual
- h = Header('wasnipoop; giraffes="very-long-necked-animals"; '
- 'spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"',
- header_name='X-Foobar-Spoink-Defrobnit',
- continuation_ws='\t')
- eq(h.encode(), '''\
-wasnipoop; giraffes="very-long-necked-animals";
-\tspooge="yummy"; hippos="gargantuan"; marshmallows="gooey"''')
-
- def test_header_splitter(self):
- eq = self.ndiffAssertEqual
- msg = MIMEText('')
- # It'd be great if we could use add_header() here, but that doesn't
- # guarantee an order of the parameters.
- msg['X-Foobar-Spoink-Defrobnit'] = (
- 'wasnipoop; giraffes="very-long-necked-animals"; '
- 'spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"')
- sfp = StringIO()
- g = Generator(sfp)
- g.flatten(msg)
- eq(sfp.getvalue(), '''\
-Content-Type: text/plain; charset="us-ascii"
-MIME-Version: 1.0
-Content-Transfer-Encoding: 7bit
-X-Foobar-Spoink-Defrobnit: wasnipoop; giraffes="very-long-necked-animals";
-\tspooge="yummy"; hippos="gargantuan"; marshmallows="gooey"
-
-''')
-
- def test_no_semis_header_splitter(self):
- eq = self.ndiffAssertEqual
- msg = Message()
- msg['From'] = 'test@dom.ain'
- msg['References'] = SPACE.join(['<%d@dom.ain>' % i for i in range(10)])
- msg.set_payload('Test')
- sfp = StringIO()
- g = Generator(sfp)
- g.flatten(msg)
- eq(sfp.getvalue(), """\
-From: test@dom.ain
-References: <0@dom.ain> <1@dom.ain> <2@dom.ain> <3@dom.ain> <4@dom.ain>
-\t<5@dom.ain> <6@dom.ain> <7@dom.ain> <8@dom.ain> <9@dom.ain>
-
-Test""")
-
- def test_no_split_long_header(self):
- eq = self.ndiffAssertEqual
- hstr = 'References: ' + 'x' * 80
- h = Header(hstr, continuation_ws='\t')
- eq(h.encode(), """\
-References: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx""")
-
- def test_splitting_multiple_long_lines(self):
- eq = self.ndiffAssertEqual
- hstr = """\
-from babylon.socal-raves.org (localhost [127.0.0.1]); by babylon.socal-raves.org (Postfix) with ESMTP id B570E51B81; for <mailman-admin@babylon.socal-raves.org>; Sat, 2 Feb 2002 17:00:06 -0800 (PST)
-\tfrom babylon.socal-raves.org (localhost [127.0.0.1]); by babylon.socal-raves.org (Postfix) with ESMTP id B570E51B81; for <mailman-admin@babylon.socal-raves.org>; Sat, 2 Feb 2002 17:00:06 -0800 (PST)
-\tfrom babylon.socal-raves.org (localhost [127.0.0.1]); by babylon.socal-raves.org (Postfix) with ESMTP id B570E51B81; for <mailman-admin@babylon.socal-raves.org>; Sat, 2 Feb 2002 17:00:06 -0800 (PST)
-"""
- h = Header(hstr, continuation_ws='\t')
- eq(h.encode(), """\
-from babylon.socal-raves.org (localhost [127.0.0.1]);
-\tby babylon.socal-raves.org (Postfix) with ESMTP id B570E51B81;
-\tfor <mailman-admin@babylon.socal-raves.org>;
-\tSat, 2 Feb 2002 17:00:06 -0800 (PST)
-\tfrom babylon.socal-raves.org (localhost [127.0.0.1]);
-\tby babylon.socal-raves.org (Postfix) with ESMTP id B570E51B81;
-\tfor <mailman-admin@babylon.socal-raves.org>;
-\tSat, 2 Feb 2002 17:00:06 -0800 (PST)
-\tfrom babylon.socal-raves.org (localhost [127.0.0.1]);
-\tby babylon.socal-raves.org (Postfix) with ESMTP id B570E51B81;
-\tfor <mailman-admin@babylon.socal-raves.org>;
-\tSat, 2 Feb 2002 17:00:06 -0800 (PST)""")
-
- def test_splitting_first_line_only_is_long(self):
- eq = self.ndiffAssertEqual
- hstr = """\
-from modemcable093.139-201-24.que.mc.videotron.ca ([24.201.139.93] helo=cthulhu.gerg.ca)
-\tby kronos.mems-exchange.org with esmtp (Exim 4.05)
-\tid 17k4h5-00034i-00
-\tfor test@mems-exchange.org; Wed, 28 Aug 2002 11:25:20 -0400"""
- h = Header(hstr, maxlinelen=78, header_name='Received',
- continuation_ws='\t')
- eq(h.encode(), """\
-from modemcable093.139-201-24.que.mc.videotron.ca ([24.201.139.93]
-\thelo=cthulhu.gerg.ca)
-\tby kronos.mems-exchange.org with esmtp (Exim 4.05)
-\tid 17k4h5-00034i-00
-\tfor test@mems-exchange.org; Wed, 28 Aug 2002 11:25:20 -0400""")
-
- def test_long_8bit_header(self):
- eq = self.ndiffAssertEqual
- msg = Message()
- h = Header('Britische Regierung gibt', 'iso-8859-1',
- header_name='Subject')
- h.append('gr\xfcnes Licht f\xfcr Offshore-Windkraftprojekte')
- msg['Subject'] = h
- eq(msg.as_string(), """\
-Subject: =?iso-8859-1?q?Britische_Regierung_gibt?= =?iso-8859-1?q?gr=FCnes?=
- =?iso-8859-1?q?_Licht_f=FCr_Offshore-Windkraftprojekte?=
-
-""")
-
- def test_long_8bit_header_no_charset(self):
- eq = self.ndiffAssertEqual
- msg = Message()
- msg['Reply-To'] = 'Britische Regierung gibt gr\xfcnes Licht f\xfcr Offshore-Windkraftprojekte <a-very-long-address@example.com>'
- eq(msg.as_string(), """\
-Reply-To: Britische Regierung gibt gr\xfcnes Licht f\xfcr Offshore-Windkraftprojekte <a-very-long-address@example.com>
-
-""")
-
- def test_long_to_header(self):
- eq = self.ndiffAssertEqual
- to = '"Someone Test #A" <someone@eecs.umich.edu>,<someone@eecs.umich.edu>,"Someone Test #B" <someone@umich.edu>, "Someone Test #C" <someone@eecs.umich.edu>, "Someone Test #D" <someone@eecs.umich.edu>'
- msg = Message()
- msg['To'] = to
- eq(msg.as_string(0), '''\
-To: "Someone Test #A" <someone@eecs.umich.edu>, <someone@eecs.umich.edu>,
-\t"Someone Test #B" <someone@umich.edu>,
-\t"Someone Test #C" <someone@eecs.umich.edu>,
-\t"Someone Test #D" <someone@eecs.umich.edu>
-
-''')
-
- def test_long_line_after_append(self):
- eq = self.ndiffAssertEqual
- s = 'This is an example of string which has almost the limit of header length.'
- h = Header(s)
- h.append('Add another line.')
- eq(h.encode(), """\
-This is an example of string which has almost the limit of header length.
- Add another line.""")
-
- def test_shorter_line_with_append(self):
- eq = self.ndiffAssertEqual
- s = 'This is a shorter line.'
- h = Header(s)
- h.append('Add another sentence. (Surprise?)')
- eq(h.encode(),
- 'This is a shorter line. Add another sentence. (Surprise?)')
-
- def test_long_field_name(self):
- eq = self.ndiffAssertEqual
- fn = 'X-Very-Very-Very-Long-Header-Name'
- gs = "Die Mieter treten hier ein werden mit einem Foerderband komfortabel den Korridor entlang, an s\xfcdl\xfcndischen Wandgem\xe4lden vorbei, gegen die rotierenden Klingen bef\xf6rdert. "
- h = Header(gs, 'iso-8859-1', header_name=fn)
- # BAW: this seems broken because the first line is too long
- eq(h.encode(), """\
-=?iso-8859-1?q?Die_Mieter_treten_hier_?=
- =?iso-8859-1?q?ein_werden_mit_einem_Foerderband_komfortabel_den_Korridor_?=
- =?iso-8859-1?q?entlang=2C_an_s=FCdl=FCndischen_Wandgem=E4lden_vorbei=2C_g?=
- =?iso-8859-1?q?egen_die_rotierenden_Klingen_bef=F6rdert=2E_?=""")
-
- def test_long_received_header(self):
- h = 'from FOO.TLD (vizworld.acl.foo.tld [123.452.678.9]) by hrothgar.la.mastaler.com (tmda-ofmipd) with ESMTP; Wed, 05 Mar 2003 18:10:18 -0700'
- msg = Message()
- msg['Received-1'] = Header(h, continuation_ws='\t')
- msg['Received-2'] = h
- self.assertEqual(msg.as_string(), """\
-Received-1: from FOO.TLD (vizworld.acl.foo.tld [123.452.678.9]) by
-\throthgar.la.mastaler.com (tmda-ofmipd) with ESMTP;
-\tWed, 05 Mar 2003 18:10:18 -0700
-Received-2: from FOO.TLD (vizworld.acl.foo.tld [123.452.678.9]) by
-\throthgar.la.mastaler.com (tmda-ofmipd) with ESMTP;
-\tWed, 05 Mar 2003 18:10:18 -0700
-
-""")
-
- def test_string_headerinst_eq(self):
- h = '<15975.17901.207240.414604@sgigritzmann1.mathematik.tu-muenchen.de> (David Bremner\'s message of "Thu, 6 Mar 2003 13:58:21 +0100")'
- msg = Message()
- msg['Received-1'] = Header(h, header_name='Received-1',
- continuation_ws='\t')
- msg['Received-2'] = h
- self.assertEqual(msg.as_string(), """\
-Received-1: <15975.17901.207240.414604@sgigritzmann1.mathematik.tu-muenchen.de>
-\t(David Bremner's message of "Thu, 6 Mar 2003 13:58:21 +0100")
-Received-2: <15975.17901.207240.414604@sgigritzmann1.mathematik.tu-muenchen.de>
-\t(David Bremner's message of "Thu, 6 Mar 2003 13:58:21 +0100")
-
-""")
-
- def test_long_unbreakable_lines_with_continuation(self):
- eq = self.ndiffAssertEqual
- msg = Message()
- t = """\
- iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
- locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp"""
- msg['Face-1'] = t
- msg['Face-2'] = Header(t, header_name='Face-2')
- eq(msg.as_string(), """\
-Face-1: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
-\tlocQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp
-Face-2: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
- locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp
-
-""")
-
- def test_another_long_multiline_header(self):
- eq = self.ndiffAssertEqual
- m = '''\
-Received: from siimage.com ([172.25.1.3]) by zima.siliconimage.com with Microsoft SMTPSVC(5.0.2195.4905);
-\tWed, 16 Oct 2002 07:41:11 -0700'''
- msg = email.message_from_string(m)
- eq(msg.as_string(), '''\
-Received: from siimage.com ([172.25.1.3]) by zima.siliconimage.com with
-\tMicrosoft SMTPSVC(5.0.2195.4905); Wed, 16 Oct 2002 07:41:11 -0700
-
-''')
-
- def test_long_lines_with_different_header(self):
- eq = self.ndiffAssertEqual
- h = """\
-List-Unsubscribe: <https://lists.sourceforge.net/lists/listinfo/spamassassin-talk>,
- <mailto:spamassassin-talk-request@lists.sourceforge.net?subject=unsubscribe>"""
- msg = Message()
- msg['List'] = h
- msg['List'] = Header(h, header_name='List')
- eq(msg.as_string(), """\
-List: List-Unsubscribe: <https://lists.sourceforge.net/lists/listinfo/spamassassin-talk>,
-\t<mailto:spamassassin-talk-request@lists.sourceforge.net?subject=unsubscribe>
-List: List-Unsubscribe: <https://lists.sourceforge.net/lists/listinfo/spamassassin-talk>,
- <mailto:spamassassin-talk-request@lists.sourceforge.net?subject=unsubscribe>
-
-""")
-
-
-
-# Test mangling of "From " lines in the body of a message
-class TestFromMangling(unittest.TestCase):
- def setUp(self):
- self.msg = Message()
- self.msg['From'] = 'aaa@bbb.org'
- self.msg.set_payload("""\
-From the desk of A.A.A.:
-Blah blah blah
-""")
-
- def test_mangled_from(self):
- s = StringIO()
- g = Generator(s, mangle_from_=True)
- g.flatten(self.msg)
- self.assertEqual(s.getvalue(), """\
-From: aaa@bbb.org
-
->From the desk of A.A.A.:
-Blah blah blah
-""")
-
- def test_dont_mangle_from(self):
- s = StringIO()
- g = Generator(s, mangle_from_=False)
- g.flatten(self.msg)
- self.assertEqual(s.getvalue(), """\
-From: aaa@bbb.org
-
-From the desk of A.A.A.:
-Blah blah blah
-""")
-
-
-
-# Test the basic MIMEAudio class
-class TestMIMEAudio(unittest.TestCase):
- def setUp(self):
- # Make sure we pick up the audiotest.au that lives in email/test/data.
- # In Python, there's an audiotest.au living in Lib/test but that isn't
- # included in some binary distros that don't include the test
- # package. The trailing empty string on the .join() is significant
- # since findfile() will do a dirname().
- datadir = os.path.join(os.path.dirname(landmark), 'data', '')
- fp = open(findfile('audiotest.au', datadir), 'rb')
- try:
- self._audiodata = fp.read()
- finally:
- fp.close()
- self._au = MIMEAudio(self._audiodata)
-
- def test_guess_minor_type(self):
- self.assertEqual(self._au.get_content_type(), 'audio/basic')
-
- def test_encoding(self):
- payload = self._au.get_payload()
- self.assertEqual(base64.decodestring(payload), self._audiodata)
-
- def test_checkSetMinor(self):
- au = MIMEAudio(self._audiodata, 'fish')
- self.assertEqual(au.get_content_type(), 'audio/fish')
-
- def test_add_header(self):
- eq = self.assertEqual
- unless = self.failUnless
- self._au.add_header('Content-Disposition', 'attachment',
- filename='audiotest.au')
- eq(self._au['content-disposition'],
- 'attachment; filename="audiotest.au"')
- eq(self._au.get_params(header='content-disposition'),
- [('attachment', ''), ('filename', 'audiotest.au')])
- eq(self._au.get_param('filename', header='content-disposition'),
- 'audiotest.au')
- missing = []
- eq(self._au.get_param('attachment', header='content-disposition'), '')
- unless(self._au.get_param('foo', failobj=missing,
- header='content-disposition') is missing)
- # Try some missing stuff
- unless(self._au.get_param('foobar', missing) is missing)
- unless(self._au.get_param('attachment', missing,
- header='foobar') is missing)
-
-
-
-# Test the basic MIMEImage class
-class TestMIMEImage(unittest.TestCase):
- def setUp(self):
- fp = openfile('PyBanner048.gif')
- try:
- self._imgdata = fp.read()
- finally:
- fp.close()
- self._im = MIMEImage(self._imgdata)
-
- def test_guess_minor_type(self):
- self.assertEqual(self._im.get_content_type(), 'image/gif')
-
- def test_encoding(self):
- payload = self._im.get_payload()
- self.assertEqual(base64.decodestring(payload), self._imgdata)
-
- def test_checkSetMinor(self):
- im = MIMEImage(self._imgdata, 'fish')
- self.assertEqual(im.get_content_type(), 'image/fish')
-
- def test_add_header(self):
- eq = self.assertEqual
- unless = self.failUnless
- self._im.add_header('Content-Disposition', 'attachment',
- filename='dingusfish.gif')
- eq(self._im['content-disposition'],
- 'attachment; filename="dingusfish.gif"')
- eq(self._im.get_params(header='content-disposition'),
- [('attachment', ''), ('filename', 'dingusfish.gif')])
- eq(self._im.get_param('filename', header='content-disposition'),
- 'dingusfish.gif')
- missing = []
- eq(self._im.get_param('attachment', header='content-disposition'), '')
- unless(self._im.get_param('foo', failobj=missing,
- header='content-disposition') is missing)
- # Try some missing stuff
- unless(self._im.get_param('foobar', missing) is missing)
- unless(self._im.get_param('attachment', missing,
- header='foobar') is missing)
-
-
-
-# Test the basic MIMEApplication class
-class TestMIMEApplication(unittest.TestCase):
- def test_headers(self):
- eq = self.assertEqual
- msg = MIMEApplication('\xfa\xfb\xfc\xfd\xfe\xff')
- eq(msg.get_content_type(), 'application/octet-stream')
- eq(msg['content-transfer-encoding'], 'base64')
-
- def test_body(self):
- eq = self.assertEqual
- bytes = '\xfa\xfb\xfc\xfd\xfe\xff'
- msg = MIMEApplication(bytes)
- eq(msg.get_payload(), '+vv8/f7/')
- eq(msg.get_payload(decode=True), bytes)
-
-
-
-# Test the basic MIMEText class
-class TestMIMEText(unittest.TestCase):
- def setUp(self):
- self._msg = MIMEText('hello there')
-
- def test_types(self):
- eq = self.assertEqual
- unless = self.failUnless
- eq(self._msg.get_content_type(), 'text/plain')
- eq(self._msg.get_param('charset'), 'us-ascii')
- missing = []
- unless(self._msg.get_param('foobar', missing) is missing)
- unless(self._msg.get_param('charset', missing, header='foobar')
- is missing)
-
- def test_payload(self):
- self.assertEqual(self._msg.get_payload(), 'hello there')
- self.failUnless(not self._msg.is_multipart())
-
- def test_charset(self):
- eq = self.assertEqual
- msg = MIMEText('hello there', _charset='us-ascii')
- eq(msg.get_charset().input_charset, 'us-ascii')
- eq(msg['content-type'], 'text/plain; charset="us-ascii"')
-
-
-
-# Test complicated multipart/* messages
-class TestMultipart(TestEmailBase):
- def setUp(self):
- fp = openfile('PyBanner048.gif')
- try:
- data = fp.read()
- finally:
- fp.close()
-
- container = MIMEBase('multipart', 'mixed', boundary='BOUNDARY')
- image = MIMEImage(data, name='dingusfish.gif')
- image.add_header('content-disposition', 'attachment',
- filename='dingusfish.gif')
- intro = MIMEText('''\
-Hi there,
-
-This is the dingus fish.
-''')
- container.attach(intro)
- container.attach(image)
- container['From'] = 'Barry <barry@digicool.com>'
- container['To'] = 'Dingus Lovers <cravindogs@cravindogs.com>'
- container['Subject'] = 'Here is your dingus fish'
-
- now = 987809702.54848599
- timetuple = time.localtime(now)
- if timetuple[-1] == 0:
- tzsecs = time.timezone
- else:
- tzsecs = time.altzone
- if tzsecs > 0:
- sign = '-'
- else:
- sign = '+'
- tzoffset = ' %s%04d' % (sign, tzsecs / 36)
- container['Date'] = time.strftime(
- '%a, %d %b %Y %H:%M:%S',
- time.localtime(now)) + tzoffset
- self._msg = container
- self._im = image
- self._txt = intro
-
- def test_hierarchy(self):
- # convenience
- eq = self.assertEqual
- unless = self.failUnless
- raises = self.assertRaises
- # tests
- m = self._msg
- unless(m.is_multipart())
- eq(m.get_content_type(), 'multipart/mixed')
- eq(len(m.get_payload()), 2)
- raises(IndexError, m.get_payload, 2)
- m0 = m.get_payload(0)
- m1 = m.get_payload(1)
- unless(m0 is self._txt)
- unless(m1 is self._im)
- eq(m.get_payload(), [m0, m1])
- unless(not m0.is_multipart())
- unless(not m1.is_multipart())
-
- def test_empty_multipart_idempotent(self):
- text = """\
-Content-Type: multipart/mixed; boundary="BOUNDARY"
-MIME-Version: 1.0
-Subject: A subject
-To: aperson@dom.ain
-From: bperson@dom.ain
-
-
---BOUNDARY
-
-
---BOUNDARY--
-"""
- msg = Parser().parsestr(text)
- self.ndiffAssertEqual(text, msg.as_string())
-
- def test_no_parts_in_a_multipart_with_none_epilogue(self):
- outer = MIMEBase('multipart', 'mixed')
- outer['Subject'] = 'A subject'
- outer['To'] = 'aperson@dom.ain'
- outer['From'] = 'bperson@dom.ain'
- outer.set_boundary('BOUNDARY')
- self.ndiffAssertEqual(outer.as_string(), '''\
-Content-Type: multipart/mixed; boundary="BOUNDARY"
-MIME-Version: 1.0
-Subject: A subject
-To: aperson@dom.ain
-From: bperson@dom.ain
-
---BOUNDARY
-
---BOUNDARY--''')
-
- def test_no_parts_in_a_multipart_with_empty_epilogue(self):
- outer = MIMEBase('multipart', 'mixed')
- outer['Subject'] = 'A subject'
- outer['To'] = 'aperson@dom.ain'
- outer['From'] = 'bperson@dom.ain'
- outer.preamble = ''
- outer.epilogue = ''
- outer.set_boundary('BOUNDARY')
- self.ndiffAssertEqual(outer.as_string(), '''\
-Content-Type: multipart/mixed; boundary="BOUNDARY"
-MIME-Version: 1.0
-Subject: A subject
-To: aperson@dom.ain
-From: bperson@dom.ain
-
-
---BOUNDARY
-
---BOUNDARY--
-''')
-
- def test_one_part_in_a_multipart(self):
- eq = self.ndiffAssertEqual
- outer = MIMEBase('multipart', 'mixed')
- outer['Subject'] = 'A subject'
- outer['To'] = 'aperson@dom.ain'
- outer['From'] = 'bperson@dom.ain'
- outer.set_boundary('BOUNDARY')
- msg = MIMEText('hello world')
- outer.attach(msg)
- eq(outer.as_string(), '''\
-Content-Type: multipart/mixed; boundary="BOUNDARY"
-MIME-Version: 1.0
-Subject: A subject
-To: aperson@dom.ain
-From: bperson@dom.ain
-
---BOUNDARY
-Content-Type: text/plain; charset="us-ascii"
-MIME-Version: 1.0
-Content-Transfer-Encoding: 7bit
-
-hello world
---BOUNDARY--''')
-
- def test_seq_parts_in_a_multipart_with_empty_preamble(self):
- eq = self.ndiffAssertEqual
- outer = MIMEBase('multipart', 'mixed')
- outer['Subject'] = 'A subject'
- outer['To'] = 'aperson@dom.ain'
- outer['From'] = 'bperson@dom.ain'
- outer.preamble = ''
- msg = MIMEText('hello world')
- outer.attach(msg)
- outer.set_boundary('BOUNDARY')
- eq(outer.as_string(), '''\
-Content-Type: multipart/mixed; boundary="BOUNDARY"
-MIME-Version: 1.0
-Subject: A subject
-To: aperson@dom.ain
-From: bperson@dom.ain
-
-
---BOUNDARY
-Content-Type: text/plain; charset="us-ascii"
-MIME-Version: 1.0
-Content-Transfer-Encoding: 7bit
-
-hello world
---BOUNDARY--''')
-
-
- def test_seq_parts_in_a_multipart_with_none_preamble(self):
- eq = self.ndiffAssertEqual
- outer = MIMEBase('multipart', 'mixed')
- outer['Subject'] = 'A subject'
- outer['To'] = 'aperson@dom.ain'
- outer['From'] = 'bperson@dom.ain'
- outer.preamble = None
- msg = MIMEText('hello world')
- outer.attach(msg)
- outer.set_boundary('BOUNDARY')
- eq(outer.as_string(), '''\
-Content-Type: multipart/mixed; boundary="BOUNDARY"
-MIME-Version: 1.0
-Subject: A subject
-To: aperson@dom.ain
-From: bperson@dom.ain
-
---BOUNDARY
-Content-Type: text/plain; charset="us-ascii"
-MIME-Version: 1.0
-Content-Transfer-Encoding: 7bit
-
-hello world
---BOUNDARY--''')
-
-
- def test_seq_parts_in_a_multipart_with_none_epilogue(self):
- eq = self.ndiffAssertEqual
- outer = MIMEBase('multipart', 'mixed')
- outer['Subject'] = 'A subject'
- outer['To'] = 'aperson@dom.ain'
- outer['From'] = 'bperson@dom.ain'
- outer.epilogue = None
- msg = MIMEText('hello world')
- outer.attach(msg)
- outer.set_boundary('BOUNDARY')
- eq(outer.as_string(), '''\
-Content-Type: multipart/mixed; boundary="BOUNDARY"
-MIME-Version: 1.0
-Subject: A subject
-To: aperson@dom.ain
-From: bperson@dom.ain
-
---BOUNDARY
-Content-Type: text/plain; charset="us-ascii"
-MIME-Version: 1.0
-Content-Transfer-Encoding: 7bit
-
-hello world
---BOUNDARY--''')
-
-
- def test_seq_parts_in_a_multipart_with_empty_epilogue(self):
- eq = self.ndiffAssertEqual
- outer = MIMEBase('multipart', 'mixed')
- outer['Subject'] = 'A subject'
- outer['To'] = 'aperson@dom.ain'
- outer['From'] = 'bperson@dom.ain'
- outer.epilogue = ''
- msg = MIMEText('hello world')
- outer.attach(msg)
- outer.set_boundary('BOUNDARY')
- eq(outer.as_string(), '''\
-Content-Type: multipart/mixed; boundary="BOUNDARY"
-MIME-Version: 1.0
-Subject: A subject
-To: aperson@dom.ain
-From: bperson@dom.ain
-
---BOUNDARY
-Content-Type: text/plain; charset="us-ascii"
-MIME-Version: 1.0
-Content-Transfer-Encoding: 7bit
-
-hello world
---BOUNDARY--
-''')
-
-
- def test_seq_parts_in_a_multipart_with_nl_epilogue(self):
- eq = self.ndiffAssertEqual
- outer = MIMEBase('multipart', 'mixed')
- outer['Subject'] = 'A subject'
- outer['To'] = 'aperson@dom.ain'
- outer['From'] = 'bperson@dom.ain'
- outer.epilogue = '\n'
- msg = MIMEText('hello world')
- outer.attach(msg)
- outer.set_boundary('BOUNDARY')
- eq(outer.as_string(), '''\
-Content-Type: multipart/mixed; boundary="BOUNDARY"
-MIME-Version: 1.0
-Subject: A subject
-To: aperson@dom.ain
-From: bperson@dom.ain
-
---BOUNDARY
-Content-Type: text/plain; charset="us-ascii"
-MIME-Version: 1.0
-Content-Transfer-Encoding: 7bit
-
-hello world
---BOUNDARY--
-
-''')
-
- def test_message_external_body(self):
- eq = self.assertEqual
- msg = self._msgobj('msg_36.txt')
- eq(len(msg.get_payload()), 2)
- msg1 = msg.get_payload(1)
- eq(msg1.get_content_type(), 'multipart/alternative')
- eq(len(msg1.get_payload()), 2)
- for subpart in msg1.get_payload():
- eq(subpart.get_content_type(), 'message/external-body')
- eq(len(subpart.get_payload()), 1)
- subsubpart = subpart.get_payload(0)
- eq(subsubpart.get_content_type(), 'text/plain')
-
- def test_double_boundary(self):
- # msg_37.txt is a multipart that contains two dash-boundary's in a
- # row. Our interpretation of RFC 2046 calls for ignoring the second
- # and subsequent boundaries.
- msg = self._msgobj('msg_37.txt')
- self.assertEqual(len(msg.get_payload()), 3)
-
- def test_nested_inner_contains_outer_boundary(self):
- eq = self.ndiffAssertEqual
- # msg_38.txt has an inner part that contains outer boundaries. My
- # interpretation of RFC 2046 (based on sections 5.1 and 5.1.2) say
- # these are illegal and should be interpreted as unterminated inner
- # parts.
- msg = self._msgobj('msg_38.txt')
- sfp = StringIO()
- iterators._structure(msg, sfp)
- eq(sfp.getvalue(), """\
-multipart/mixed
- multipart/mixed
- multipart/alternative
- text/plain
- text/plain
- text/plain
- text/plain
-""")
-
- def test_nested_with_same_boundary(self):
- eq = self.ndiffAssertEqual
- # msg 39.txt is similarly evil in that it's got inner parts that use
- # the same boundary as outer parts. Again, I believe the way this is
- # parsed is closest to the spirit of RFC 2046
- msg = self._msgobj('msg_39.txt')
- sfp = StringIO()
- iterators._structure(msg, sfp)
- eq(sfp.getvalue(), """\
-multipart/mixed
- multipart/mixed
- multipart/alternative
- application/octet-stream
- application/octet-stream
- text/plain
-""")
-
- def test_boundary_in_non_multipart(self):
- msg = self._msgobj('msg_40.txt')
- self.assertEqual(msg.as_string(), '''\
-MIME-Version: 1.0
-Content-Type: text/html; boundary="--961284236552522269"
-
-----961284236552522269
-Content-Type: text/html;
-Content-Transfer-Encoding: 7Bit
-
-<html></html>
-
-----961284236552522269--
-''')
-
- def test_boundary_with_leading_space(self):
- eq = self.assertEqual
- msg = email.message_from_string('''\
-MIME-Version: 1.0
-Content-Type: multipart/mixed; boundary=" XXXX"
-
--- XXXX
-Content-Type: text/plain
-
-
--- XXXX
-Content-Type: text/plain
-
--- XXXX--
-''')
- self.failUnless(msg.is_multipart())
- eq(msg.get_boundary(), ' XXXX')
- eq(len(msg.get_payload()), 2)
-
- def test_boundary_without_trailing_newline(self):
- m = Parser().parsestr("""\
-Content-Type: multipart/mixed; boundary="===============0012394164=="
-MIME-Version: 1.0
-
---===============0012394164==
-Content-Type: image/file1.jpg
-MIME-Version: 1.0
-Content-Transfer-Encoding: base64
-
-YXNkZg==
---===============0012394164==--""")
- self.assertEquals(m.get_payload(0).get_payload(), 'YXNkZg==')
-
-
-
-# Test some badly formatted messages
-class TestNonConformant(TestEmailBase):
- def test_parse_missing_minor_type(self):
- eq = self.assertEqual
- msg = self._msgobj('msg_14.txt')
- eq(msg.get_content_type(), 'text/plain')
- eq(msg.get_content_maintype(), 'text')
- eq(msg.get_content_subtype(), 'plain')
-
- def test_same_boundary_inner_outer(self):
- unless = self.failUnless
- msg = self._msgobj('msg_15.txt')
- # XXX We can probably eventually do better
- inner = msg.get_payload(0)
- unless(hasattr(inner, 'defects'))
- self.assertEqual(len(inner.defects), 1)
- unless(isinstance(inner.defects[0],
- errors.StartBoundaryNotFoundDefect))
-
- def test_multipart_no_boundary(self):
- unless = self.failUnless
- msg = self._msgobj('msg_25.txt')
- unless(isinstance(msg.get_payload(), str))
- self.assertEqual(len(msg.defects), 2)
- unless(isinstance(msg.defects[0], errors.NoBoundaryInMultipartDefect))
- unless(isinstance(msg.defects[1],
- errors.MultipartInvariantViolationDefect))
-
- def test_invalid_content_type(self):
- eq = self.assertEqual
- neq = self.ndiffAssertEqual
- msg = Message()
- # RFC 2045, $5.2 says invalid yields text/plain
- msg['Content-Type'] = 'text'
- eq(msg.get_content_maintype(), 'text')
- eq(msg.get_content_subtype(), 'plain')
- eq(msg.get_content_type(), 'text/plain')
- # Clear the old value and try something /really/ invalid
- del msg['content-type']
- msg['Content-Type'] = 'foo'
- eq(msg.get_content_maintype(), 'text')
- eq(msg.get_content_subtype(), 'plain')
- eq(msg.get_content_type(), 'text/plain')
- # Still, make sure that the message is idempotently generated
- s = StringIO()
- g = Generator(s)
- g.flatten(msg)
- neq(s.getvalue(), 'Content-Type: foo\n\n')
-
- def test_no_start_boundary(self):
- eq = self.ndiffAssertEqual
- msg = self._msgobj('msg_31.txt')
- eq(msg.get_payload(), """\
---BOUNDARY
-Content-Type: text/plain
-
-message 1
-
---BOUNDARY
-Content-Type: text/plain
-
-message 2
-
---BOUNDARY--
-""")
-
- def test_no_separating_blank_line(self):
- eq = self.ndiffAssertEqual
- msg = self._msgobj('msg_35.txt')
- eq(msg.as_string(), """\
-From: aperson@dom.ain
-To: bperson@dom.ain
-Subject: here's something interesting
-
-counter to RFC 2822, there's no separating newline here
-""")
-
- def test_lying_multipart(self):
- unless = self.failUnless
- msg = self._msgobj('msg_41.txt')
- unless(hasattr(msg, 'defects'))
- self.assertEqual(len(msg.defects), 2)
- unless(isinstance(msg.defects[0], errors.NoBoundaryInMultipartDefect))
- unless(isinstance(msg.defects[1],
- errors.MultipartInvariantViolationDefect))
-
- def test_missing_start_boundary(self):
- outer = self._msgobj('msg_42.txt')
- # The message structure is:
- #
- # multipart/mixed
- # text/plain
- # message/rfc822
- # multipart/mixed [*]
- #
- # [*] This message is missing its start boundary
- bad = outer.get_payload(1).get_payload(0)
- self.assertEqual(len(bad.defects), 1)
- self.failUnless(isinstance(bad.defects[0],
- errors.StartBoundaryNotFoundDefect))
-
- def test_first_line_is_continuation_header(self):
- eq = self.assertEqual
- m = ' Line 1\nLine 2\nLine 3'
- msg = email.message_from_string(m)
- eq(msg.keys(), [])
- eq(msg.get_payload(), 'Line 2\nLine 3')
- eq(len(msg.defects), 1)
- self.failUnless(isinstance(msg.defects[0],
- errors.FirstHeaderLineIsContinuationDefect))
- eq(msg.defects[0].line, ' Line 1\n')
-
-
-
-# Test RFC 2047 header encoding and decoding
-class TestRFC2047(unittest.TestCase):
- def test_rfc2047_multiline(self):
- eq = self.assertEqual
- s = """Re: =?mac-iceland?q?r=8Aksm=9Arg=8Cs?= baz
- foo bar =?mac-iceland?q?r=8Aksm=9Arg=8Cs?="""
- dh = decode_header(s)
- eq(dh, [
- ('Re:', None),
- ('r\x8aksm\x9arg\x8cs', 'mac-iceland'),
- ('baz foo bar', None),
- ('r\x8aksm\x9arg\x8cs', 'mac-iceland')])
- eq(str(make_header(dh)),
- """Re: =?mac-iceland?q?r=8Aksm=9Arg=8Cs?= baz foo bar
- =?mac-iceland?q?r=8Aksm=9Arg=8Cs?=""")
-
- def test_whitespace_eater_unicode(self):
- eq = self.assertEqual
- s = '=?ISO-8859-1?Q?Andr=E9?= Pirard <pirard@dom.ain>'
- dh = decode_header(s)
- eq(dh, [('Andr\xe9', 'iso-8859-1'), ('Pirard <pirard@dom.ain>', None)])
- hu = str(make_header(dh)).encode('latin-1')
- eq(hu, 'Andr\xe9 Pirard <pirard@dom.ain>')
-
- def test_whitespace_eater_unicode_2(self):
- eq = self.assertEqual
- s = 'The =?iso-8859-1?b?cXVpY2sgYnJvd24gZm94?= jumped over the =?iso-8859-1?b?bGF6eSBkb2c=?='
- dh = decode_header(s)
- eq(dh, [('The', None), ('quick brown fox', 'iso-8859-1'),
- ('jumped over the', None), ('lazy dog', 'iso-8859-1')])
- hu = make_header(dh).__unicode__()
- eq(hu, 'The quick brown fox jumped over the lazy dog')
-
- def test_rfc2047_missing_whitespace(self):
- s = 'Sm=?ISO-8859-1?B?9g==?=rg=?ISO-8859-1?B?5Q==?=sbord'
- dh = decode_header(s)
- self.assertEqual(dh, [(s, None)])
-
- def test_rfc2047_with_whitespace(self):
- s = 'Sm =?ISO-8859-1?B?9g==?= rg =?ISO-8859-1?B?5Q==?= sbord'
- dh = decode_header(s)
- self.assertEqual(dh, [('Sm', None), ('\xf6', 'iso-8859-1'),
- ('rg', None), ('\xe5', 'iso-8859-1'),
- ('sbord', None)])
-
-
-
-# Test the MIMEMessage class
-class TestMIMEMessage(TestEmailBase):
- def setUp(self):
- fp = openfile('msg_11.txt')
- try:
- self._text = fp.read()
- finally:
- fp.close()
-
- def test_type_error(self):
- self.assertRaises(TypeError, MIMEMessage, 'a plain string')
-
- def test_valid_argument(self):
- eq = self.assertEqual
- unless = self.failUnless
- subject = 'A sub-message'
- m = Message()
- m['Subject'] = subject
- r = MIMEMessage(m)
- eq(r.get_content_type(), 'message/rfc822')
- payload = r.get_payload()
- unless(isinstance(payload, list))
- eq(len(payload), 1)
- subpart = payload[0]
- unless(subpart is m)
- eq(subpart['subject'], subject)
-
- def test_bad_multipart(self):
- eq = self.assertEqual
- msg1 = Message()
- msg1['Subject'] = 'subpart 1'
- msg2 = Message()
- msg2['Subject'] = 'subpart 2'
- r = MIMEMessage(msg1)
- self.assertRaises(errors.MultipartConversionError, r.attach, msg2)
-
- def test_generate(self):
- # First craft the message to be encapsulated
- m = Message()
- m['Subject'] = 'An enclosed message'
- m.set_payload('Here is the body of the message.\n')
- r = MIMEMessage(m)
- r['Subject'] = 'The enclosing message'
- s = StringIO()
- g = Generator(s)
- g.flatten(r)
- self.assertEqual(s.getvalue(), """\
-Content-Type: message/rfc822
-MIME-Version: 1.0
-Subject: The enclosing message
-
-Subject: An enclosed message
-
-Here is the body of the message.
-""")
-
- def test_parse_message_rfc822(self):
- eq = self.assertEqual
- unless = self.failUnless
- msg = self._msgobj('msg_11.txt')
- eq(msg.get_content_type(), 'message/rfc822')
- payload = msg.get_payload()
- unless(isinstance(payload, list))
- eq(len(payload), 1)
- submsg = payload[0]
- self.failUnless(isinstance(submsg, Message))
- eq(submsg['subject'], 'An enclosed message')
- eq(submsg.get_payload(), 'Here is the body of the message.\n')
-
- def test_dsn(self):
- eq = self.assertEqual
- unless = self.failUnless
- # msg 16 is a Delivery Status Notification, see RFC 1894
- msg = self._msgobj('msg_16.txt')
- eq(msg.get_content_type(), 'multipart/report')
- unless(msg.is_multipart())
- eq(len(msg.get_payload()), 3)
- # Subpart 1 is a text/plain, human readable section
- subpart = msg.get_payload(0)
- eq(subpart.get_content_type(), 'text/plain')
- eq(subpart.get_payload(), """\
-This report relates to a message you sent with the following header fields:
-
- Message-id: <002001c144a6$8752e060$56104586@oxy.edu>
- Date: Sun, 23 Sep 2001 20:10:55 -0700
- From: "Ian T. Henry" <henryi@oxy.edu>
- To: SoCal Raves <scr@socal-raves.org>
- Subject: [scr] yeah for Ians!!
-
-Your message cannot be delivered to the following recipients:
-
- Recipient address: jangel1@cougar.noc.ucla.edu
- Reason: recipient reached disk quota
-
-""")
- # Subpart 2 contains the machine parsable DSN information. It
- # consists of two blocks of headers, represented by two nested Message
- # objects.
- subpart = msg.get_payload(1)
- eq(subpart.get_content_type(), 'message/delivery-status')
- eq(len(subpart.get_payload()), 2)
- # message/delivery-status should treat each block as a bunch of
- # headers, i.e. a bunch of Message objects.
- dsn1 = subpart.get_payload(0)
- unless(isinstance(dsn1, Message))
- eq(dsn1['original-envelope-id'], '0GK500B4HD0888@cougar.noc.ucla.edu')
- eq(dsn1.get_param('dns', header='reporting-mta'), '')
- # Try a missing one <wink>
- eq(dsn1.get_param('nsd', header='reporting-mta'), None)
- dsn2 = subpart.get_payload(1)
- unless(isinstance(dsn2, Message))
- eq(dsn2['action'], 'failed')
- eq(dsn2.get_params(header='original-recipient'),
- [('rfc822', ''), ('jangel1@cougar.noc.ucla.edu', '')])
- eq(dsn2.get_param('rfc822', header='final-recipient'), '')
- # Subpart 3 is the original message
- subpart = msg.get_payload(2)
- eq(subpart.get_content_type(), 'message/rfc822')
- payload = subpart.get_payload()
- unless(isinstance(payload, list))
- eq(len(payload), 1)
- subsubpart = payload[0]
- unless(isinstance(subsubpart, Message))
- eq(subsubpart.get_content_type(), 'text/plain')
- eq(subsubpart['message-id'],
- '<002001c144a6$8752e060$56104586@oxy.edu>')
-
- def test_epilogue(self):
- eq = self.ndiffAssertEqual
- fp = openfile('msg_21.txt')
- try:
- text = fp.read()
- finally:
- fp.close()
- msg = Message()
- msg['From'] = 'aperson@dom.ain'
- msg['To'] = 'bperson@dom.ain'
- msg['Subject'] = 'Test'
- msg.preamble = 'MIME message'
- msg.epilogue = 'End of MIME message\n'
- msg1 = MIMEText('One')
- msg2 = MIMEText('Two')
- msg.add_header('Content-Type', 'multipart/mixed', boundary='BOUNDARY')
- msg.attach(msg1)
- msg.attach(msg2)
- sfp = StringIO()
- g = Generator(sfp)
- g.flatten(msg)
- eq(sfp.getvalue(), text)
-
- def test_no_nl_preamble(self):
- eq = self.ndiffAssertEqual
- msg = Message()
- msg['From'] = 'aperson@dom.ain'
- msg['To'] = 'bperson@dom.ain'
- msg['Subject'] = 'Test'
- msg.preamble = 'MIME message'
- msg.epilogue = ''
- msg1 = MIMEText('One')
- msg2 = MIMEText('Two')
- msg.add_header('Content-Type', 'multipart/mixed', boundary='BOUNDARY')
- msg.attach(msg1)
- msg.attach(msg2)
- eq(msg.as_string(), """\
-From: aperson@dom.ain
-To: bperson@dom.ain
-Subject: Test
-Content-Type: multipart/mixed; boundary="BOUNDARY"
-
-MIME message
---BOUNDARY
-Content-Type: text/plain; charset="us-ascii"
-MIME-Version: 1.0
-Content-Transfer-Encoding: 7bit
-
-One
---BOUNDARY
-Content-Type: text/plain; charset="us-ascii"
-MIME-Version: 1.0
-Content-Transfer-Encoding: 7bit
-
-Two
---BOUNDARY--
-""")
-
- def test_default_type(self):
- eq = self.assertEqual
- fp = openfile('msg_30.txt')
- try:
- msg = email.message_from_file(fp)
- finally:
- fp.close()
- container1 = msg.get_payload(0)
- eq(container1.get_default_type(), 'message/rfc822')
- eq(container1.get_content_type(), 'message/rfc822')
- container2 = msg.get_payload(1)
- eq(container2.get_default_type(), 'message/rfc822')
- eq(container2.get_content_type(), 'message/rfc822')
- container1a = container1.get_payload(0)
- eq(container1a.get_default_type(), 'text/plain')
- eq(container1a.get_content_type(), 'text/plain')
- container2a = container2.get_payload(0)
- eq(container2a.get_default_type(), 'text/plain')
- eq(container2a.get_content_type(), 'text/plain')
-
- def test_default_type_with_explicit_container_type(self):
- eq = self.assertEqual
- fp = openfile('msg_28.txt')
- try:
- msg = email.message_from_file(fp)
- finally:
- fp.close()
- container1 = msg.get_payload(0)
- eq(container1.get_default_type(), 'message/rfc822')
- eq(container1.get_content_type(), 'message/rfc822')
- container2 = msg.get_payload(1)
- eq(container2.get_default_type(), 'message/rfc822')
- eq(container2.get_content_type(), 'message/rfc822')
- container1a = container1.get_payload(0)
- eq(container1a.get_default_type(), 'text/plain')
- eq(container1a.get_content_type(), 'text/plain')
- container2a = container2.get_payload(0)
- eq(container2a.get_default_type(), 'text/plain')
- eq(container2a.get_content_type(), 'text/plain')
-
- def test_default_type_non_parsed(self):
- eq = self.assertEqual
- neq = self.ndiffAssertEqual
- # Set up container
- container = MIMEMultipart('digest', 'BOUNDARY')
- container.epilogue = ''
- # Set up subparts
- subpart1a = MIMEText('message 1\n')
- subpart2a = MIMEText('message 2\n')
- subpart1 = MIMEMessage(subpart1a)
- subpart2 = MIMEMessage(subpart2a)
- container.attach(subpart1)
- container.attach(subpart2)
- eq(subpart1.get_content_type(), 'message/rfc822')
- eq(subpart1.get_default_type(), 'message/rfc822')
- eq(subpart2.get_content_type(), 'message/rfc822')
- eq(subpart2.get_default_type(), 'message/rfc822')
- neq(container.as_string(0), '''\
-Content-Type: multipart/digest; boundary="BOUNDARY"
-MIME-Version: 1.0
-
---BOUNDARY
-Content-Type: message/rfc822
-MIME-Version: 1.0
-
-Content-Type: text/plain; charset="us-ascii"
-MIME-Version: 1.0
-Content-Transfer-Encoding: 7bit
-
-message 1
-
---BOUNDARY
-Content-Type: message/rfc822
-MIME-Version: 1.0
-
-Content-Type: text/plain; charset="us-ascii"
-MIME-Version: 1.0
-Content-Transfer-Encoding: 7bit
-
-message 2
-
---BOUNDARY--
-''')
- del subpart1['content-type']
- del subpart1['mime-version']
- del subpart2['content-type']
- del subpart2['mime-version']
- eq(subpart1.get_content_type(), 'message/rfc822')
- eq(subpart1.get_default_type(), 'message/rfc822')
- eq(subpart2.get_content_type(), 'message/rfc822')
- eq(subpart2.get_default_type(), 'message/rfc822')
- neq(container.as_string(0), '''\
-Content-Type: multipart/digest; boundary="BOUNDARY"
-MIME-Version: 1.0
-
---BOUNDARY
-
-Content-Type: text/plain; charset="us-ascii"
-MIME-Version: 1.0
-Content-Transfer-Encoding: 7bit
-
-message 1
-
---BOUNDARY
-
-Content-Type: text/plain; charset="us-ascii"
-MIME-Version: 1.0
-Content-Transfer-Encoding: 7bit
-
-message 2
-
---BOUNDARY--
-''')
-
- def test_mime_attachments_in_constructor(self):
- eq = self.assertEqual
- text1 = MIMEText('')
- text2 = MIMEText('')
- msg = MIMEMultipart(_subparts=(text1, text2))
- eq(len(msg.get_payload()), 2)
- eq(msg.get_payload(0), text1)
- eq(msg.get_payload(1), text2)
-
-
-
-# A general test of parser->model->generator idempotency. IOW, read a message
-# in, parse it into a message object tree, then without touching the tree,
-# regenerate the plain text. The original text and the transformed text
-# should be identical. Note: that we ignore the Unix-From since that may
-# contain a changed date.
-class TestIdempotent(TestEmailBase):
- def _msgobj(self, filename):
- fp = openfile(filename)
- try:
- data = fp.read()
- finally:
- fp.close()
- msg = email.message_from_string(data)
- return msg, data
-
- def _idempotent(self, msg, text):
- eq = self.ndiffAssertEqual
- s = StringIO()
- g = Generator(s, maxheaderlen=0)
- g.flatten(msg)
- eq(text, s.getvalue())
-
- def test_parse_text_message(self):
- eq = self.assertEquals
- msg, text = self._msgobj('msg_01.txt')
- eq(msg.get_content_type(), 'text/plain')
- eq(msg.get_content_maintype(), 'text')
- eq(msg.get_content_subtype(), 'plain')
- eq(msg.get_params()[1], ('charset', 'us-ascii'))
- eq(msg.get_param('charset'), 'us-ascii')
- eq(msg.preamble, None)
- eq(msg.epilogue, None)
- self._idempotent(msg, text)
-
- def test_parse_untyped_message(self):
- eq = self.assertEquals
- msg, text = self._msgobj('msg_03.txt')
- eq(msg.get_content_type(), 'text/plain')
- eq(msg.get_params(), None)
- eq(msg.get_param('charset'), None)
- self._idempotent(msg, text)
-
- def test_simple_multipart(self):
- msg, text = self._msgobj('msg_04.txt')
- self._idempotent(msg, text)
-
- def test_MIME_digest(self):
- msg, text = self._msgobj('msg_02.txt')
- self._idempotent(msg, text)
-
- def test_long_header(self):
- msg, text = self._msgobj('msg_27.txt')
- self._idempotent(msg, text)
-
- def test_MIME_digest_with_part_headers(self):
- msg, text = self._msgobj('msg_28.txt')
- self._idempotent(msg, text)
-
- def test_mixed_with_image(self):
- msg, text = self._msgobj('msg_06.txt')
- self._idempotent(msg, text)
-
- def test_multipart_report(self):
- msg, text = self._msgobj('msg_05.txt')
- self._idempotent(msg, text)
-
- def test_dsn(self):
- msg, text = self._msgobj('msg_16.txt')
- self._idempotent(msg, text)
-
- def test_preamble_epilogue(self):
- msg, text = self._msgobj('msg_21.txt')
- self._idempotent(msg, text)
-
- def test_multipart_one_part(self):
- msg, text = self._msgobj('msg_23.txt')
- self._idempotent(msg, text)
-
- def test_multipart_no_parts(self):
- msg, text = self._msgobj('msg_24.txt')
- self._idempotent(msg, text)
-
- def test_no_start_boundary(self):
- msg, text = self._msgobj('msg_31.txt')
- self._idempotent(msg, text)
-
- def test_rfc2231_charset(self):
- msg, text = self._msgobj('msg_32.txt')
- self._idempotent(msg, text)
-
- def test_more_rfc2231_parameters(self):
- msg, text = self._msgobj('msg_33.txt')
- self._idempotent(msg, text)
-
- def test_text_plain_in_a_multipart_digest(self):
- msg, text = self._msgobj('msg_34.txt')
- self._idempotent(msg, text)
-
- def test_nested_multipart_mixeds(self):
- msg, text = self._msgobj('msg_12a.txt')
- self._idempotent(msg, text)
-
- def test_message_external_body_idempotent(self):
- msg, text = self._msgobj('msg_36.txt')
- self._idempotent(msg, text)
-
- def test_content_type(self):
- eq = self.assertEquals
- unless = self.failUnless
- # Get a message object and reset the seek pointer for other tests
- msg, text = self._msgobj('msg_05.txt')
- eq(msg.get_content_type(), 'multipart/report')
- # Test the Content-Type: parameters
- params = {}
- for pk, pv in msg.get_params():
- params[pk] = pv
- eq(params['report-type'], 'delivery-status')
- eq(params['boundary'], 'D1690A7AC1.996856090/mail.example.com')
- eq(msg.preamble, 'This is a MIME-encapsulated message.\n')
- eq(msg.epilogue, '\n')
- eq(len(msg.get_payload()), 3)
- # Make sure the subparts are what we expect
- msg1 = msg.get_payload(0)
- eq(msg1.get_content_type(), 'text/plain')
- eq(msg1.get_payload(), 'Yadda yadda yadda\n')
- msg2 = msg.get_payload(1)
- eq(msg2.get_content_type(), 'text/plain')
- eq(msg2.get_payload(), 'Yadda yadda yadda\n')
- msg3 = msg.get_payload(2)
- eq(msg3.get_content_type(), 'message/rfc822')
- self.failUnless(isinstance(msg3, Message))
- payload = msg3.get_payload()
- unless(isinstance(payload, list))
- eq(len(payload), 1)
- msg4 = payload[0]
- unless(isinstance(msg4, Message))
- eq(msg4.get_payload(), 'Yadda yadda yadda\n')
-
- def test_parser(self):
- eq = self.assertEquals
- unless = self.failUnless
- msg, text = self._msgobj('msg_06.txt')
- # Check some of the outer headers
- eq(msg.get_content_type(), 'message/rfc822')
- # Make sure the payload is a list of exactly one sub-Message, and that
- # that submessage has a type of text/plain
- payload = msg.get_payload()
- unless(isinstance(payload, list))
- eq(len(payload), 1)
- msg1 = payload[0]
- self.failUnless(isinstance(msg1, Message))
- eq(msg1.get_content_type(), 'text/plain')
- self.failUnless(isinstance(msg1.get_payload(), str))
- eq(msg1.get_payload(), '\n')
-
-
-
-# Test various other bits of the package's functionality
-class TestMiscellaneous(TestEmailBase):
- def test_message_from_string(self):
- fp = openfile('msg_01.txt')
- try:
- text = fp.read()
- finally:
- fp.close()
- msg = email.message_from_string(text)
- s = StringIO()
- # Don't wrap/continue long headers since we're trying to test
- # idempotency.
- g = Generator(s, maxheaderlen=0)
- g.flatten(msg)
- self.assertEqual(text, s.getvalue())
-
- def test_message_from_file(self):
- fp = openfile('msg_01.txt')
- try:
- text = fp.read()
- fp.seek(0)
- msg = email.message_from_file(fp)
- s = StringIO()
- # Don't wrap/continue long headers since we're trying to test
- # idempotency.
- g = Generator(s, maxheaderlen=0)
- g.flatten(msg)
- self.assertEqual(text, s.getvalue())
- finally:
- fp.close()
-
- def test_message_from_string_with_class(self):
- unless = self.failUnless
- fp = openfile('msg_01.txt')
- try:
- text = fp.read()
- finally:
- fp.close()
- # Create a subclass
- class MyMessage(Message):
- pass
-
- msg = email.message_from_string(text, MyMessage)
- unless(isinstance(msg, MyMessage))
- # Try something more complicated
- fp = openfile('msg_02.txt')
- try:
- text = fp.read()
- finally:
- fp.close()
- msg = email.message_from_string(text, MyMessage)
- for subpart in msg.walk():
- unless(isinstance(subpart, MyMessage))
-
- def test_message_from_file_with_class(self):
- unless = self.failUnless
- # Create a subclass
- class MyMessage(Message):
- pass
-
- fp = openfile('msg_01.txt')
- try:
- msg = email.message_from_file(fp, MyMessage)
- finally:
- fp.close()
- unless(isinstance(msg, MyMessage))
- # Try something more complicated
- fp = openfile('msg_02.txt')
- try:
- msg = email.message_from_file(fp, MyMessage)
- finally:
- fp.close()
- for subpart in msg.walk():
- unless(isinstance(subpart, MyMessage))
-
- def test__all__(self):
- module = __import__('email')
- # Can't use sorted() here due to Python 2.3 compatibility
- all = module.__all__[:]
- all.sort()
- self.assertEqual(all, [
- # Old names
- 'Charset', 'Encoders', 'Errors', 'Generator',
- 'Header', 'Iterators', 'MIMEAudio', 'MIMEBase',
- 'MIMEImage', 'MIMEMessage', 'MIMEMultipart',
- 'MIMENonMultipart', 'MIMEText', 'Message',
- 'Parser', 'Utils', 'base64MIME',
- # new names
- 'base64mime', 'charset', 'encoders', 'errors', 'generator',
- 'header', 'iterators', 'message', 'message_from_file',
- 'message_from_string', 'mime', 'parser',
- 'quopriMIME', 'quoprimime', 'utils',
- ])
-
- def test_formatdate(self):
- now = time.time()
- self.assertEqual(utils.parsedate(utils.formatdate(now))[:6],
- time.gmtime(now)[:6])
-
- def test_formatdate_localtime(self):
- now = time.time()
- self.assertEqual(
- utils.parsedate(utils.formatdate(now, localtime=True))[:6],
- time.localtime(now)[:6])
-
- def test_formatdate_usegmt(self):
- now = time.time()
- self.assertEqual(
- utils.formatdate(now, localtime=False),
- time.strftime('%a, %d %b %Y %H:%M:%S -0000', time.gmtime(now)))
- self.assertEqual(
- utils.formatdate(now, localtime=False, usegmt=True),
- time.strftime('%a, %d %b %Y %H:%M:%S GMT', time.gmtime(now)))
-
- def test_parsedate_none(self):
- self.assertEqual(utils.parsedate(''), None)
-
- def test_parsedate_compact(self):
- # The FWS after the comma is optional
- self.assertEqual(utils.parsedate('Wed,3 Apr 2002 14:58:26 +0800'),
- utils.parsedate('Wed, 3 Apr 2002 14:58:26 +0800'))
-
- def test_parsedate_no_dayofweek(self):
- eq = self.assertEqual
- eq(utils.parsedate_tz('25 Feb 2003 13:47:26 -0800'),
- (2003, 2, 25, 13, 47, 26, 0, 1, -1, -28800))
-
- def test_parsedate_compact_no_dayofweek(self):
- eq = self.assertEqual
- eq(utils.parsedate_tz('5 Feb 2003 13:47:26 -0800'),
- (2003, 2, 5, 13, 47, 26, 0, 1, -1, -28800))
-
- def test_parsedate_acceptable_to_time_functions(self):
- eq = self.assertEqual
- timetup = utils.parsedate('5 Feb 2003 13:47:26 -0800')
- t = int(time.mktime(timetup))
- eq(time.localtime(t)[:6], timetup[:6])
- eq(int(time.strftime('%Y', timetup)), 2003)
- timetup = utils.parsedate_tz('5 Feb 2003 13:47:26 -0800')
- t = int(time.mktime(timetup[:9]))
- eq(time.localtime(t)[:6], timetup[:6])
- eq(int(time.strftime('%Y', timetup[:9])), 2003)
-
- def test_parseaddr_empty(self):
- self.assertEqual(utils.parseaddr('<>'), ('', ''))
- self.assertEqual(utils.formataddr(utils.parseaddr('<>')), '')
-
- def test_noquote_dump(self):
- self.assertEqual(
- utils.formataddr(('A Silly Person', 'person@dom.ain')),
- 'A Silly Person <person@dom.ain>')
-
- def test_escape_dump(self):
- self.assertEqual(
- utils.formataddr(('A (Very) Silly Person', 'person@dom.ain')),
- r'"A \(Very\) Silly Person" <person@dom.ain>')
- a = r'A \(Special\) Person'
- b = 'person@dom.ain'
- self.assertEqual(utils.parseaddr(utils.formataddr((a, b))), (a, b))
-
- def test_escape_backslashes(self):
- self.assertEqual(
- utils.formataddr(('Arthur \Backslash\ Foobar', 'person@dom.ain')),
- r'"Arthur \\Backslash\\ Foobar" <person@dom.ain>')
- a = r'Arthur \Backslash\ Foobar'
- b = 'person@dom.ain'
- self.assertEqual(utils.parseaddr(utils.formataddr((a, b))), (a, b))
-
- def test_name_with_dot(self):
- x = 'John X. Doe <jxd@example.com>'
- y = '"John X. Doe" <jxd@example.com>'
- a, b = ('John X. Doe', 'jxd@example.com')
- self.assertEqual(utils.parseaddr(x), (a, b))
- self.assertEqual(utils.parseaddr(y), (a, b))
- # formataddr() quotes the name if there's a dot in it
- self.assertEqual(utils.formataddr((a, b)), y)
-
- def test_multiline_from_comment(self):
- x = """\
-Foo
-\tBar <foo@example.com>"""
- self.assertEqual(utils.parseaddr(x), ('Foo Bar', 'foo@example.com'))
-
- def test_quote_dump(self):
- self.assertEqual(
- utils.formataddr(('A Silly; Person', 'person@dom.ain')),
- r'"A Silly; Person" <person@dom.ain>')
-
- def test_fix_eols(self):
- eq = self.assertEqual
- eq(utils.fix_eols('hello'), 'hello')
- eq(utils.fix_eols('hello\n'), 'hello\r\n')
- eq(utils.fix_eols('hello\r'), 'hello\r\n')
- eq(utils.fix_eols('hello\r\n'), 'hello\r\n')
- eq(utils.fix_eols('hello\n\r'), 'hello\r\n\r\n')
-
- def test_charset_richcomparisons(self):
- eq = self.assertEqual
- ne = self.failIfEqual
- cset1 = Charset()
- cset2 = Charset()
- eq(cset1, 'us-ascii')
- eq(cset1, 'US-ASCII')
- eq(cset1, 'Us-AsCiI')
- eq('us-ascii', cset1)
- eq('US-ASCII', cset1)
- eq('Us-AsCiI', cset1)
- ne(cset1, 'usascii')
- ne(cset1, 'USASCII')
- ne(cset1, 'UsAsCiI')
- ne('usascii', cset1)
- ne('USASCII', cset1)
- ne('UsAsCiI', cset1)
- eq(cset1, cset2)
- eq(cset2, cset1)
-
- def test_getaddresses(self):
- eq = self.assertEqual
- eq(utils.getaddresses(['aperson@dom.ain (Al Person)',
- 'Bud Person <bperson@dom.ain>']),
- [('Al Person', 'aperson@dom.ain'),
- ('Bud Person', 'bperson@dom.ain')])
-
- def test_getaddresses_nasty(self):
- eq = self.assertEqual
- eq(utils.getaddresses(['foo: ;']), [('', '')])
- eq(utils.getaddresses(
- ['[]*-- =~$']),
- [('', ''), ('', ''), ('', '*--')])
- eq(utils.getaddresses(
- ['foo: ;', '"Jason R. Mastaler" <jason@dom.ain>']),
- [('', ''), ('Jason R. Mastaler', 'jason@dom.ain')])
-
- def test_getaddresses_embedded_comment(self):
- """Test proper handling of a nested comment"""
- eq = self.assertEqual
- addrs = utils.getaddresses(['User ((nested comment)) <foo@bar.com>'])
- eq(addrs[0][1], 'foo@bar.com')
-
- def test_utils_quote_unquote(self):
- eq = self.assertEqual
- msg = Message()
- msg.add_header('content-disposition', 'attachment',
- filename='foo\\wacky"name')
- eq(msg.get_filename(), 'foo\\wacky"name')
-
- def test_get_body_encoding_with_bogus_charset(self):
- charset = Charset('not a charset')
- self.assertEqual(charset.get_body_encoding(), 'base64')
-
- def test_get_body_encoding_with_uppercase_charset(self):
- eq = self.assertEqual
- msg = Message()
- msg['Content-Type'] = 'text/plain; charset=UTF-8'
- eq(msg['content-type'], 'text/plain; charset=UTF-8')
- charsets = msg.get_charsets()
- eq(len(charsets), 1)
- eq(charsets[0], 'utf-8')
- charset = Charset(charsets[0])
- eq(charset.get_body_encoding(), 'base64')
- msg.set_payload('hello world', charset=charset)
- eq(msg.get_payload(), 'aGVsbG8gd29ybGQ=\n')
- eq(msg.get_payload(decode=True), 'hello world')
- eq(msg['content-transfer-encoding'], 'base64')
- # Try another one
- msg = Message()
- msg['Content-Type'] = 'text/plain; charset="US-ASCII"'
- charsets = msg.get_charsets()
- eq(len(charsets), 1)
- eq(charsets[0], 'us-ascii')
- charset = Charset(charsets[0])
- eq(charset.get_body_encoding(), encoders.encode_7or8bit)
- msg.set_payload('hello world', charset=charset)
- eq(msg.get_payload(), 'hello world')
- eq(msg['content-transfer-encoding'], '7bit')
-
- def test_charsets_case_insensitive(self):
- lc = Charset('us-ascii')
- uc = Charset('US-ASCII')
- self.assertEqual(lc.get_body_encoding(), uc.get_body_encoding())
-
- def test_partial_falls_inside_message_delivery_status(self):
- eq = self.ndiffAssertEqual
- # The Parser interface provides chunks of data to FeedParser in 8192
- # byte gulps. SF bug #1076485 found one of those chunks inside
- # message/delivery-status header block, which triggered an
- # unreadline() of NeedMoreData.
- msg = self._msgobj('msg_43.txt')
- sfp = StringIO()
- iterators._structure(msg, sfp)
- eq(sfp.getvalue(), """\
-multipart/report
- text/plain
- message/delivery-status
- text/plain
- text/plain
- text/plain
- text/plain
- text/plain
- text/plain
- text/plain
- text/plain
- text/plain
- text/plain
- text/plain
- text/plain
- text/plain
- text/plain
- text/plain
- text/plain
- text/plain
- text/plain
- text/plain
- text/plain
- text/plain
- text/plain
- text/plain
- text/plain
- text/plain
- text/plain
- text/rfc822-headers
-""")
-
-
-
-# Test the iterator/generators
-class TestIterators(TestEmailBase):
- def test_body_line_iterator(self):
- eq = self.assertEqual
- neq = self.ndiffAssertEqual
- # First a simple non-multipart message
- msg = self._msgobj('msg_01.txt')
- it = iterators.body_line_iterator(msg)
- lines = list(it)
- eq(len(lines), 6)
- neq(EMPTYSTRING.join(lines), msg.get_payload())
- # Now a more complicated multipart
- msg = self._msgobj('msg_02.txt')
- it = iterators.body_line_iterator(msg)
- lines = list(it)
- eq(len(lines), 43)
- fp = openfile('msg_19.txt')
- try:
- neq(EMPTYSTRING.join(lines), fp.read())
- finally:
- fp.close()
-
- def test_typed_subpart_iterator(self):
- eq = self.assertEqual
- msg = self._msgobj('msg_04.txt')
- it = iterators.typed_subpart_iterator(msg, 'text')
- lines = []
- subparts = 0
- for subpart in it:
- subparts += 1
- lines.append(subpart.get_payload())
- eq(subparts, 2)
- eq(EMPTYSTRING.join(lines), """\
-a simple kind of mirror
-to reflect upon our own
-a simple kind of mirror
-to reflect upon our own
-""")
-
- def test_typed_subpart_iterator_default_type(self):
- eq = self.assertEqual
- msg = self._msgobj('msg_03.txt')
- it = iterators.typed_subpart_iterator(msg, 'text', 'plain')
- lines = []
- subparts = 0
- for subpart in it:
- subparts += 1
- lines.append(subpart.get_payload())
- eq(subparts, 1)
- eq(EMPTYSTRING.join(lines), """\
-
-Hi,
-
-Do you like this message?
-
--Me
-""")
-
-
-
-class TestParsers(TestEmailBase):
- def test_header_parser(self):
- eq = self.assertEqual
- # Parse only the headers of a complex multipart MIME document
- fp = openfile('msg_02.txt')
- try:
- msg = HeaderParser().parse(fp)
- finally:
- fp.close()
- eq(msg['from'], 'ppp-request@zzz.org')
- eq(msg['to'], 'ppp@zzz.org')
- eq(msg.get_content_type(), 'multipart/mixed')
- self.failIf(msg.is_multipart())
- self.failUnless(isinstance(msg.get_payload(), str))
-
- def test_whitespace_continuation(self):
- eq = self.assertEqual
- # This message contains a line after the Subject: header that has only
- # whitespace, but it is not empty!
- msg = email.message_from_string("""\
-From: aperson@dom.ain
-To: bperson@dom.ain
-Subject: the next line has a space on it
-\x20
-Date: Mon, 8 Apr 2002 15:09:19 -0400
-Message-ID: spam
-
-Here's the message body
-""")
- eq(msg['subject'], 'the next line has a space on it\n ')
- eq(msg['message-id'], 'spam')
- eq(msg.get_payload(), "Here's the message body\n")
-
- def test_whitespace_continuation_last_header(self):
- eq = self.assertEqual
- # Like the previous test, but the subject line is the last
- # header.
- msg = email.message_from_string("""\
-From: aperson@dom.ain
-To: bperson@dom.ain
-Date: Mon, 8 Apr 2002 15:09:19 -0400
-Message-ID: spam
-Subject: the next line has a space on it
-\x20
-
-Here's the message body
-""")
- eq(msg['subject'], 'the next line has a space on it\n ')
- eq(msg['message-id'], 'spam')
- eq(msg.get_payload(), "Here's the message body\n")
-
- def test_crlf_separation(self):
- eq = self.assertEqual
- fp = openfile('msg_26.txt', mode='rb')
- try:
- msg = Parser().parse(fp)
- finally:
- fp.close()
- eq(len(msg.get_payload()), 2)
- part1 = msg.get_payload(0)
- eq(part1.get_content_type(), 'text/plain')
- eq(part1.get_payload(), 'Simple email with attachment.\r\n\r\n')
- part2 = msg.get_payload(1)
- eq(part2.get_content_type(), 'application/riscos')
-
- def test_multipart_digest_with_extra_mime_headers(self):
- eq = self.assertEqual
- neq = self.ndiffAssertEqual
- fp = openfile('msg_28.txt')
- try:
- msg = email.message_from_file(fp)
- finally:
- fp.close()
- # Structure is:
- # multipart/digest
- # message/rfc822
- # text/plain
- # message/rfc822
- # text/plain
- eq(msg.is_multipart(), 1)
- eq(len(msg.get_payload()), 2)
- part1 = msg.get_payload(0)
- eq(part1.get_content_type(), 'message/rfc822')
- eq(part1.is_multipart(), 1)
- eq(len(part1.get_payload()), 1)
- part1a = part1.get_payload(0)
- eq(part1a.is_multipart(), 0)
- eq(part1a.get_content_type(), 'text/plain')
- neq(part1a.get_payload(), 'message 1\n')
- # next message/rfc822
- part2 = msg.get_payload(1)
- eq(part2.get_content_type(), 'message/rfc822')
- eq(part2.is_multipart(), 1)
- eq(len(part2.get_payload()), 1)
- part2a = part2.get_payload(0)
- eq(part2a.is_multipart(), 0)
- eq(part2a.get_content_type(), 'text/plain')
- neq(part2a.get_payload(), 'message 2\n')
-
- def test_three_lines(self):
- # A bug report by Andrew McNamara
- lines = ['From: Andrew Person <aperson@dom.ain',
- 'Subject: Test',
- 'Date: Tue, 20 Aug 2002 16:43:45 +1000']
- msg = email.message_from_string(NL.join(lines))
- self.assertEqual(msg['date'], 'Tue, 20 Aug 2002 16:43:45 +1000')
-
- def test_strip_line_feed_and_carriage_return_in_headers(self):
- eq = self.assertEqual
- # For [ 1002475 ] email message parser doesn't handle \r\n correctly
- value1 = 'text'
- value2 = 'more text'
- m = 'Header: %s\r\nNext-Header: %s\r\n\r\nBody\r\n\r\n' % (
- value1, value2)
- msg = email.message_from_string(m)
- eq(msg.get('Header'), value1)
- eq(msg.get('Next-Header'), value2)
-
- def test_rfc2822_header_syntax(self):
- eq = self.assertEqual
- m = '>From: foo\nFrom: bar\n!"#QUX;~: zoo\n\nbody'
- msg = email.message_from_string(m)
- eq(len(msg.keys()), 3)
- keys = msg.keys()
- keys.sort()
- eq(keys, ['!"#QUX;~', '>From', 'From'])
- eq(msg.get_payload(), 'body')
-
- def test_rfc2822_space_not_allowed_in_header(self):
- eq = self.assertEqual
- m = '>From foo@example.com 11:25:53\nFrom: bar\n!"#QUX;~: zoo\n\nbody'
- msg = email.message_from_string(m)
- eq(len(msg.keys()), 0)
-
- def test_rfc2822_one_character_header(self):
- eq = self.assertEqual
- m = 'A: first header\nB: second header\nCC: third header\n\nbody'
- msg = email.message_from_string(m)
- headers = msg.keys()
- headers.sort()
- eq(headers, ['A', 'B', 'CC'])
- eq(msg.get_payload(), 'body')
-
-
-
-class TestBase64(unittest.TestCase):
- def test_len(self):
- eq = self.assertEqual
- eq(base64mime.base64_len('hello'),
- len(base64mime.encode('hello', eol='')))
- for size in range(15):
- if size == 0 : bsize = 0
- elif size <= 3 : bsize = 4
- elif size <= 6 : bsize = 8
- elif size <= 9 : bsize = 12
- elif size <= 12: bsize = 16
- else : bsize = 20
- eq(base64mime.base64_len('x'*size), bsize)
-
- def test_decode(self):
- eq = self.assertEqual
- eq(base64mime.decode(''), '')
- eq(base64mime.decode('aGVsbG8='), 'hello')
- eq(base64mime.decode('aGVsbG8=', 'X'), 'hello')
- eq(base64mime.decode('aGVsbG8NCndvcmxk\n', 'X'), 'helloXworld')
-
- def test_encode(self):
- eq = self.assertEqual
- eq(base64mime.encode(''), '')
- eq(base64mime.encode('hello'), 'aGVsbG8=\n')
- # Test the binary flag
- eq(base64mime.encode('hello\n'), 'aGVsbG8K\n')
- eq(base64mime.encode('hello\n', 0), 'aGVsbG8NCg==\n')
- # Test the maxlinelen arg
- eq(base64mime.encode('xxxx ' * 20, maxlinelen=40), """\
-eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
-eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
-eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg
-eHh4eCB4eHh4IA==
-""")
- # Test the eol argument
- eq(base64mime.encode('xxxx ' * 20, maxlinelen=40, eol='\r\n'), """\
-eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg\r
-eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg\r
-eHh4eCB4eHh4IHh4eHggeHh4eCB4eHh4IHh4eHgg\r
-eHh4eCB4eHh4IA==\r
-""")
-
- def test_header_encode(self):
- eq = self.assertEqual
- he = base64mime.header_encode
- eq(he('hello'), '=?iso-8859-1?b?aGVsbG8=?=')
- eq(he('hello\nworld'), '=?iso-8859-1?b?aGVsbG8NCndvcmxk?=')
- # Test the charset option
- eq(he('hello', charset='iso-8859-2'), '=?iso-8859-2?b?aGVsbG8=?=')
- # Test the keep_eols flag
- eq(he('hello\nworld', keep_eols=True),
- '=?iso-8859-1?b?aGVsbG8Kd29ybGQ=?=')
- # Test the maxlinelen argument
- eq(he('xxxx ' * 20, maxlinelen=40), """\
-=?iso-8859-1?b?eHh4eCB4eHh4IHh4eHggeHg=?=
- =?iso-8859-1?b?eHggeHh4eCB4eHh4IHh4eHg=?=
- =?iso-8859-1?b?IHh4eHggeHh4eCB4eHh4IHg=?=
- =?iso-8859-1?b?eHh4IHh4eHggeHh4eCB4eHg=?=
- =?iso-8859-1?b?eCB4eHh4IHh4eHggeHh4eCA=?=
- =?iso-8859-1?b?eHh4eCB4eHh4IHh4eHgg?=""")
- # Test the eol argument
- eq(he('xxxx ' * 20, maxlinelen=40, eol='\r\n'), """\
-=?iso-8859-1?b?eHh4eCB4eHh4IHh4eHggeHg=?=\r
- =?iso-8859-1?b?eHggeHh4eCB4eHh4IHh4eHg=?=\r
- =?iso-8859-1?b?IHh4eHggeHh4eCB4eHh4IHg=?=\r
- =?iso-8859-1?b?eHh4IHh4eHggeHh4eCB4eHg=?=\r
- =?iso-8859-1?b?eCB4eHh4IHh4eHggeHh4eCA=?=\r
- =?iso-8859-1?b?eHh4eCB4eHh4IHh4eHgg?=""")
-
-
-
-class TestQuopri(unittest.TestCase):
- def setUp(self):
- self.hlit = [chr(x) for x in range(ord('a'), ord('z')+1)] + \
- [chr(x) for x in range(ord('A'), ord('Z')+1)] + \
- [chr(x) for x in range(ord('0'), ord('9')+1)] + \
- ['!', '*', '+', '-', '/', ' ']
- self.hnon = [chr(x) for x in range(256) if chr(x) not in self.hlit]
- assert len(self.hlit) + len(self.hnon) == 256
- self.blit = [chr(x) for x in range(ord(' '), ord('~')+1)] + ['\t']
- self.blit.remove('=')
- self.bnon = [chr(x) for x in range(256) if chr(x) not in self.blit]
- assert len(self.blit) + len(self.bnon) == 256
-
- def test_header_quopri_check(self):
- for c in self.hlit:
- self.failIf(quoprimime.header_quopri_check(c))
- for c in self.hnon:
- self.failUnless(quoprimime.header_quopri_check(c))
-
- def test_body_quopri_check(self):
- for c in self.blit:
- self.failIf(quoprimime.body_quopri_check(c))
- for c in self.bnon:
- self.failUnless(quoprimime.body_quopri_check(c))
-
- def test_header_quopri_len(self):
- eq = self.assertEqual
- hql = quoprimime.header_quopri_len
- enc = quoprimime.header_encode
- for s in ('hello', 'h@e@l@l@o@'):
- # Empty charset and no line-endings. 7 == RFC chrome
- eq(hql(s), len(enc(s, charset='', eol=''))-7)
- for c in self.hlit:
- eq(hql(c), 1)
- for c in self.hnon:
- eq(hql(c), 3)
-
- def test_body_quopri_len(self):
- eq = self.assertEqual
- bql = quoprimime.body_quopri_len
- for c in self.blit:
- eq(bql(c), 1)
- for c in self.bnon:
- eq(bql(c), 3)
-
- def test_quote_unquote_idempotent(self):
- for x in range(256):
- c = chr(x)
- self.assertEqual(quoprimime.unquote(quoprimime.quote(c)), c)
-
- def test_header_encode(self):
- eq = self.assertEqual
- he = quoprimime.header_encode
- eq(he('hello'), '=?iso-8859-1?q?hello?=')
- eq(he('hello\nworld'), '=?iso-8859-1?q?hello=0D=0Aworld?=')
- # Test the charset option
- eq(he('hello', charset='iso-8859-2'), '=?iso-8859-2?q?hello?=')
- # Test the keep_eols flag
- eq(he('hello\nworld', keep_eols=True), '=?iso-8859-1?q?hello=0Aworld?=')
- # Test a non-ASCII character
- eq(he('hello\xc7there'), '=?iso-8859-1?q?hello=C7there?=')
- # Test the maxlinelen argument
- eq(he('xxxx ' * 20, maxlinelen=40), """\
-=?iso-8859-1?q?xxxx_xxxx_xxxx_xxxx_xx?=
- =?iso-8859-1?q?xx_xxxx_xxxx_xxxx_xxxx?=
- =?iso-8859-1?q?_xxxx_xxxx_xxxx_xxxx_x?=
- =?iso-8859-1?q?xxx_xxxx_xxxx_xxxx_xxx?=
- =?iso-8859-1?q?x_xxxx_xxxx_?=""")
- # Test the eol argument
- eq(he('xxxx ' * 20, maxlinelen=40, eol='\r\n'), """\
-=?iso-8859-1?q?xxxx_xxxx_xxxx_xxxx_xx?=\r
- =?iso-8859-1?q?xx_xxxx_xxxx_xxxx_xxxx?=\r
- =?iso-8859-1?q?_xxxx_xxxx_xxxx_xxxx_x?=\r
- =?iso-8859-1?q?xxx_xxxx_xxxx_xxxx_xxx?=\r
- =?iso-8859-1?q?x_xxxx_xxxx_?=""")
-
- def test_decode(self):
- eq = self.assertEqual
- eq(quoprimime.decode(''), '')
- eq(quoprimime.decode('hello'), 'hello')
- eq(quoprimime.decode('hello', 'X'), 'hello')
- eq(quoprimime.decode('hello\nworld', 'X'), 'helloXworld')
-
- def test_encode(self):
- eq = self.assertEqual
- eq(quoprimime.encode(''), '')
- eq(quoprimime.encode('hello'), 'hello')
- # Test the binary flag
- eq(quoprimime.encode('hello\r\nworld'), 'hello\nworld')
- eq(quoprimime.encode('hello\r\nworld', 0), 'hello\nworld')
- # Test the maxlinelen arg
- eq(quoprimime.encode('xxxx ' * 20, maxlinelen=40), """\
-xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx=
- xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxx=
-x xxxx xxxx xxxx xxxx=20""")
- # Test the eol argument
- eq(quoprimime.encode('xxxx ' * 20, maxlinelen=40, eol='\r\n'), """\
-xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx=\r
- xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxx=\r
-x xxxx xxxx xxxx xxxx=20""")
- eq(quoprimime.encode("""\
-one line
-
-two line"""), """\
-one line
-
-two line""")
-
-
-
-# Test the Charset class
-class TestCharset(unittest.TestCase):
- def tearDown(self):
- from email import charset as CharsetModule
- try:
- del CharsetModule.CHARSETS['fake']
- except KeyError:
- pass
-
- def test_idempotent(self):
- eq = self.assertEqual
- # Make sure us-ascii = no Unicode conversion
- c = Charset('us-ascii')
- s = 'Hello World!'
- sp = c.to_splittable(s)
- eq(s, c.from_splittable(sp))
- # test 8-bit idempotency with us-ascii
- s = '\xa4\xa2\xa4\xa4\xa4\xa6\xa4\xa8\xa4\xaa'
- sp = c.to_splittable(s)
- eq(s, c.from_splittable(sp))
-
- def test_body_encode(self):
- eq = self.assertEqual
- # Try a charset with QP body encoding
- c = Charset('iso-8859-1')
- eq('hello w=F6rld', c.body_encode('hello w\xf6rld'))
- # Try a charset with Base64 body encoding
- c = Charset('utf-8')
- eq('aGVsbG8gd29ybGQ=\n', c.body_encode('hello world'))
- # Try a charset with None body encoding
- c = Charset('us-ascii')
- eq('hello world', c.body_encode('hello world'))
- # Try the convert argument, where input codec != output codec
- c = Charset('euc-jp')
- # With apologies to Tokio Kikuchi ;)
- try:
- eq('\x1b$B5FCO;~IW\x1b(B',
- c.body_encode('\xb5\xc6\xc3\xcf\xbb\xfe\xc9\xd7'))
- eq('\xb5\xc6\xc3\xcf\xbb\xfe\xc9\xd7',
- c.body_encode('\xb5\xc6\xc3\xcf\xbb\xfe\xc9\xd7', False))
- except LookupError:
- # We probably don't have the Japanese codecs installed
- pass
- # Testing SF bug #625509, which we have to fake, since there are no
- # built-in encodings where the header encoding is QP but the body
- # encoding is not.
- from email import charset as CharsetModule
- CharsetModule.add_charset('fake', CharsetModule.QP, None)
- c = Charset('fake')
- eq('hello w\xf6rld', c.body_encode('hello w\xf6rld'))
-
- def test_unicode_charset_name(self):
- charset = Charset('us-ascii')
- self.assertEqual(str(charset), 'us-ascii')
- self.assertRaises(errors.CharsetError, Charset, 'asc\xffii')
-
-
-
-# Test multilingual MIME headers.
-class TestHeader(TestEmailBase):
- def test_simple(self):
- eq = self.ndiffAssertEqual
- h = Header('Hello World!')
- eq(h.encode(), 'Hello World!')
- h.append(' Goodbye World!')
- eq(h.encode(), 'Hello World! Goodbye World!')
-
- def test_simple_surprise(self):
- eq = self.ndiffAssertEqual
- h = Header('Hello World!')
- eq(h.encode(), 'Hello World!')
- h.append('Goodbye World!')
- eq(h.encode(), 'Hello World! Goodbye World!')
-
- def test_header_needs_no_decoding(self):
- h = 'no decoding needed'
- self.assertEqual(decode_header(h), [(h, None)])
-
- def test_long(self):
- h = Header("I am the very model of a modern Major-General; I've information vegetable, animal, and mineral; I know the kings of England, and I quote the fights historical from Marathon to Waterloo, in order categorical; I'm very well acquainted, too, with matters mathematical; I understand equations, both the simple and quadratical; about binomial theorem I'm teeming with a lot o' news, with many cheerful facts about the square of the hypotenuse.",
- maxlinelen=76)
- for l in h.encode(splitchars=' ').split('\n '):
- self.failUnless(len(l) <= 76)
-
- def test_multilingual(self):
- eq = self.ndiffAssertEqual
- g = Charset("iso-8859-1")
- cz = Charset("iso-8859-2")
- utf8 = Charset("utf-8")
- g_head = "Die Mieter treten hier ein werden mit einem Foerderband komfortabel den Korridor entlang, an s\xfcdl\xfcndischen Wandgem\xe4lden vorbei, gegen die rotierenden Klingen bef\xf6rdert. "
- cz_head = "Finan\xe8ni metropole se hroutily pod tlakem jejich d\xf9vtipu.. "
- utf8_head = "\u6b63\u78ba\u306b\u8a00\u3046\u3068\u7ffb\u8a33\u306f\u3055\u308c\u3066\u3044\u307e\u305b\u3093\u3002\u4e00\u90e8\u306f\u30c9\u30a4\u30c4\u8a9e\u3067\u3059\u304c\u3001\u3042\u3068\u306f\u3067\u305f\u3089\u3081\u3067\u3059\u3002\u5b9f\u969b\u306b\u306f\u300cWenn ist das Nunstuck git und Slotermeyer? Ja! Beiherhund das Oder die Flipperwaldt gersput.\u300d\u3068\u8a00\u3063\u3066\u3044\u307e\u3059\u3002".encode("utf-8")
- h = Header(g_head, g)
- h.append(cz_head, cz)
- h.append(utf8_head, utf8)
- enc = h.encode()
- eq(enc, """\
-=?iso-8859-1?q?Die_Mieter_treten_hier_ein_werden_mit_einem_Foerderband_ko?=
- =?iso-8859-1?q?mfortabel_den_Korridor_entlang=2C_an_s=FCdl=FCndischen_Wan?=
- =?iso-8859-1?q?dgem=E4lden_vorbei=2C_gegen_die_rotierenden_Klingen_bef=F6?=
- =?iso-8859-1?q?rdert=2E_?= =?iso-8859-2?q?Finan=E8ni_metropole_se_hroutily?=
- =?iso-8859-2?q?_pod_tlakem_jejich_d=F9vtipu=2E=2E_?= =?utf-8?b?5q2j56K6?=
- =?utf-8?b?44Gr6KiA44GG44Go57+76Kiz44Gv44GV44KM44Gm44GE44G+44Gb44KT44CC?=
- =?utf-8?b?5LiA6YOo44Gv44OJ44Kk44OE6Kqe44Gn44GZ44GM44CB44GC44Go44Gv44Gn?=
- =?utf-8?b?44Gf44KJ44KB44Gn44GZ44CC5a6f6Zqb44Gr44Gv44CMV2VubiBpc3QgZGFz?=
- =?utf-8?q?_Nunstuck_git_und_Slotermeyer=3F_Ja!_Beiherhund_das_Oder_die_Fl?=
- =?utf-8?b?aXBwZXJ3YWxkdCBnZXJzcHV0LuOAjeOBqOiogOOBo+OBpuOBhOOBvuOBmQ==?=
- =?utf-8?b?44CC?=""")
- eq(decode_header(enc),
- [(g_head, "iso-8859-1"), (cz_head, "iso-8859-2"),
- (utf8_head, "utf-8")])
- ustr = str(h)
- eq(ustr.encode('utf-8'),
- 'Die Mieter treten hier ein werden mit einem Foerderband '
- 'komfortabel den Korridor entlang, an s\xc3\xbcdl\xc3\xbcndischen '
- 'Wandgem\xc3\xa4lden vorbei, gegen die rotierenden Klingen '
- 'bef\xc3\xb6rdert. Finan\xc4\x8dni metropole se hroutily pod '
- 'tlakem jejich d\xc5\xafvtipu.. \xe6\xad\xa3\xe7\xa2\xba\xe3\x81'
- '\xab\xe8\xa8\x80\xe3\x81\x86\xe3\x81\xa8\xe7\xbf\xbb\xe8\xa8\xb3'
- '\xe3\x81\xaf\xe3\x81\x95\xe3\x82\x8c\xe3\x81\xa6\xe3\x81\x84\xe3'
- '\x81\xbe\xe3\x81\x9b\xe3\x82\x93\xe3\x80\x82\xe4\xb8\x80\xe9\x83'
- '\xa8\xe3\x81\xaf\xe3\x83\x89\xe3\x82\xa4\xe3\x83\x84\xe8\xaa\x9e'
- '\xe3\x81\xa7\xe3\x81\x99\xe3\x81\x8c\xe3\x80\x81\xe3\x81\x82\xe3'
- '\x81\xa8\xe3\x81\xaf\xe3\x81\xa7\xe3\x81\x9f\xe3\x82\x89\xe3\x82'
- '\x81\xe3\x81\xa7\xe3\x81\x99\xe3\x80\x82\xe5\xae\x9f\xe9\x9a\x9b'
- '\xe3\x81\xab\xe3\x81\xaf\xe3\x80\x8cWenn ist das Nunstuck git '
- 'und Slotermeyer? Ja! Beiherhund das Oder die Flipperwaldt '
- 'gersput.\xe3\x80\x8d\xe3\x81\xa8\xe8\xa8\x80\xe3\x81\xa3\xe3\x81'
- '\xa6\xe3\x81\x84\xe3\x81\xbe\xe3\x81\x99\xe3\x80\x82')
- # Test make_header()
- newh = make_header(decode_header(enc))
- eq(newh, enc)
-
- def test_header_ctor_default_args(self):
- eq = self.ndiffAssertEqual
- h = Header()
- eq(h, '')
- h.append('foo', Charset('iso-8859-1'))
- eq(h, '=?iso-8859-1?q?foo?=')
-
- def test_explicit_maxlinelen(self):
- eq = self.ndiffAssertEqual
- hstr = 'A very long line that must get split to something other than at the 76th character boundary to test the non-default behavior'
- h = Header(hstr)
- eq(h.encode(), '''\
-A very long line that must get split to something other than at the 76th
- character boundary to test the non-default behavior''')
- h = Header(hstr, header_name='Subject')
- eq(h.encode(), '''\
-A very long line that must get split to something other than at the
- 76th character boundary to test the non-default behavior''')
- h = Header(hstr, maxlinelen=1024, header_name='Subject')
- eq(h.encode(), hstr)
-
- def test_us_ascii_header(self):
- eq = self.assertEqual
- s = 'hello'
- x = decode_header(s)
- eq(x, [('hello', None)])
- h = make_header(x)
- eq(s, h.encode())
-
- def test_string_charset(self):
- eq = self.assertEqual
- h = Header()
- h.append('hello', 'iso-8859-1')
- eq(h, '=?iso-8859-1?q?hello?=')
-
-## def test_unicode_error(self):
-## raises = self.assertRaises
-## raises(UnicodeError, Header, u'[P\xf6stal]', 'us-ascii')
-## raises(UnicodeError, Header, '[P\xf6stal]', 'us-ascii')
-## h = Header()
-## raises(UnicodeError, h.append, u'[P\xf6stal]', 'us-ascii')
-## raises(UnicodeError, h.append, '[P\xf6stal]', 'us-ascii')
-## raises(UnicodeError, Header, u'\u83ca\u5730\u6642\u592b', 'iso-8859-1')
-
- def test_utf8_shortest(self):
- eq = self.assertEqual
- h = Header('p\xf6stal', 'utf-8')
- eq(h.encode(), '=?utf-8?q?p=C3=B6stal?=')
- h = Header('\u83ca\u5730\u6642\u592b', 'utf-8')
- eq(h.encode(), '=?utf-8?b?6I+K5Zyw5pmC5aSr?=')
-
- def test_bad_8bit_header(self):
- raises = self.assertRaises
- eq = self.assertEqual
- x = 'Ynwp4dUEbay Auction Semiar- No Charge \x96 Earn Big'
- raises(UnicodeError, Header, x)
- h = Header()
- raises(UnicodeError, h.append, x)
- eq(str(Header(x, errors='replace')), x)
- h.append(x, errors='replace')
- eq(str(h), x)
-
- def test_encoded_adjacent_nonencoded(self):
- eq = self.assertEqual
- h = Header()
- h.append('hello', 'iso-8859-1')
- h.append('world')
- s = h.encode()
- eq(s, '=?iso-8859-1?q?hello?= world')
- h = make_header(decode_header(s))
- eq(h.encode(), s)
-
- def test_whitespace_eater(self):
- eq = self.assertEqual
- s = 'Subject: =?koi8-r?b?8NLP18XSy8EgzsEgxsnOwczYztk=?= =?koi8-r?q?=CA?= zz.'
- parts = decode_header(s)
- eq(parts, [('Subject:', None), ('\xf0\xd2\xcf\xd7\xc5\xd2\xcb\xc1 \xce\xc1 \xc6\xc9\xce\xc1\xcc\xd8\xce\xd9\xca', 'koi8-r'), ('zz.', None)])
- hdr = make_header(parts)
- eq(hdr.encode(),
- 'Subject: =?koi8-r?b?8NLP18XSy8EgzsEgxsnOwczYztnK?= zz.')
-
- def test_broken_base64_header(self):
- raises = self.assertRaises
- s = 'Subject: =?EUC-KR?B?CSixpLDtKSC/7Liuvsax4iC6uLmwMcijIKHaILzSwd/H0SC8+LCjwLsgv7W/+Mj3IQ?='
- raises(errors.HeaderParseError, decode_header, s)
-
-
-
-# Test RFC 2231 header parameters (en/de)coding
-class TestRFC2231(TestEmailBase):
- def test_get_param(self):
- eq = self.assertEqual
- msg = self._msgobj('msg_29.txt')
- eq(msg.get_param('title'),
- ('us-ascii', 'en', 'This is even more ***fun*** isn\'t it!'))
- eq(msg.get_param('title', unquote=False),
- ('us-ascii', 'en', '"This is even more ***fun*** isn\'t it!"'))
-
- def test_set_param(self):
- eq = self.assertEqual
- msg = Message()
- msg.set_param('title', 'This is even more ***fun*** isn\'t it!',
- charset='us-ascii')
- eq(msg.get_param('title'),
- ('us-ascii', '', 'This is even more ***fun*** isn\'t it!'))
- msg.set_param('title', 'This is even more ***fun*** isn\'t it!',
- charset='us-ascii', language='en')
- eq(msg.get_param('title'),
- ('us-ascii', 'en', 'This is even more ***fun*** isn\'t it!'))
- msg = self._msgobj('msg_01.txt')
- msg.set_param('title', 'This is even more ***fun*** isn\'t it!',
- charset='us-ascii', language='en')
- eq(msg.as_string(), """\
-Return-Path: <bbb@zzz.org>
-Delivered-To: bbb@zzz.org
-Received: by mail.zzz.org (Postfix, from userid 889)
-\tid 27CEAD38CC; Fri, 4 May 2001 14:05:44 -0400 (EDT)
-MIME-Version: 1.0
-Content-Transfer-Encoding: 7bit
-Message-ID: <15090.61304.110929.45684@aaa.zzz.org>
-From: bbb@ddd.com (John X. Doe)
-To: bbb@zzz.org
-Subject: This is a test message
-Date: Fri, 4 May 2001 14:05:44 -0400
-Content-Type: text/plain; charset=us-ascii;
-\ttitle*="us-ascii'en'This%20is%20even%20more%20%2A%2A%2Afun%2A%2A%2A%20isn%27t%20it%21"
-
-
-Hi,
-
-Do you like this message?
-
--Me
-""")
-
- def test_del_param(self):
- eq = self.ndiffAssertEqual
- msg = self._msgobj('msg_01.txt')
- msg.set_param('foo', 'bar', charset='us-ascii', language='en')
- msg.set_param('title', 'This is even more ***fun*** isn\'t it!',
- charset='us-ascii', language='en')
- msg.del_param('foo', header='Content-Type')
- eq(msg.as_string(), """\
-Return-Path: <bbb@zzz.org>
-Delivered-To: bbb@zzz.org
-Received: by mail.zzz.org (Postfix, from userid 889)
-\tid 27CEAD38CC; Fri, 4 May 2001 14:05:44 -0400 (EDT)
-MIME-Version: 1.0
-Content-Transfer-Encoding: 7bit
-Message-ID: <15090.61304.110929.45684@aaa.zzz.org>
-From: bbb@ddd.com (John X. Doe)
-To: bbb@zzz.org
-Subject: This is a test message
-Date: Fri, 4 May 2001 14:05:44 -0400
-Content-Type: text/plain; charset="us-ascii";
-\ttitle*="us-ascii'en'This%20is%20even%20more%20%2A%2A%2Afun%2A%2A%2A%20isn%27t%20it%21"
-
-
-Hi,
-
-Do you like this message?
-
--Me
-""")
-
- def test_rfc2231_get_content_charset(self):
- eq = self.assertEqual
- msg = self._msgobj('msg_32.txt')
- eq(msg.get_content_charset(), 'us-ascii')
-
- def test_rfc2231_no_language_or_charset(self):
- m = '''\
-Content-Transfer-Encoding: 8bit
-Content-Disposition: inline; filename="file____C__DOCUMENTS_20AND_20SETTINGS_FABIEN_LOCAL_20SETTINGS_TEMP_nsmail.htm"
-Content-Type: text/html; NAME*0=file____C__DOCUMENTS_20AND_20SETTINGS_FABIEN_LOCAL_20SETTINGS_TEM; NAME*1=P_nsmail.htm
-
-'''
- msg = email.message_from_string(m)
- param = msg.get_param('NAME')
- self.failIf(isinstance(param, tuple))
- self.assertEqual(
- param,
- 'file____C__DOCUMENTS_20AND_20SETTINGS_FABIEN_LOCAL_20SETTINGS_TEMP_nsmail.htm')
-
- def test_rfc2231_no_language_or_charset_in_filename(self):
- m = '''\
-Content-Disposition: inline;
-\tfilename*0*="''This%20is%20even%20more%20";
-\tfilename*1*="%2A%2A%2Afun%2A%2A%2A%20";
-\tfilename*2="is it not.pdf"
-
-'''
- msg = email.message_from_string(m)
- self.assertEqual(msg.get_filename(),
- 'This is even more ***fun*** is it not.pdf')
-
- def test_rfc2231_no_language_or_charset_in_filename_encoded(self):
- m = '''\
-Content-Disposition: inline;
-\tfilename*0*="''This%20is%20even%20more%20";
-\tfilename*1*="%2A%2A%2Afun%2A%2A%2A%20";
-\tfilename*2="is it not.pdf"
-
-'''
- msg = email.message_from_string(m)
- self.assertEqual(msg.get_filename(),
- 'This is even more ***fun*** is it not.pdf')
-
- def test_rfc2231_partly_encoded(self):
- m = '''\
-Content-Disposition: inline;
-\tfilename*0="''This%20is%20even%20more%20";
-\tfilename*1*="%2A%2A%2Afun%2A%2A%2A%20";
-\tfilename*2="is it not.pdf"
-
-'''
- msg = email.message_from_string(m)
- self.assertEqual(
- msg.get_filename(),
- 'This%20is%20even%20more%20***fun*** is it not.pdf')
-
- def test_rfc2231_partly_nonencoded(self):
- m = '''\
-Content-Disposition: inline;
-\tfilename*0="This%20is%20even%20more%20";
-\tfilename*1="%2A%2A%2Afun%2A%2A%2A%20";
-\tfilename*2="is it not.pdf"
-
-'''
- msg = email.message_from_string(m)
- self.assertEqual(
- msg.get_filename(),
- 'This%20is%20even%20more%20%2A%2A%2Afun%2A%2A%2A%20is it not.pdf')
-
- def test_rfc2231_no_language_or_charset_in_boundary(self):
- m = '''\
-Content-Type: multipart/alternative;
-\tboundary*0*="''This%20is%20even%20more%20";
-\tboundary*1*="%2A%2A%2Afun%2A%2A%2A%20";
-\tboundary*2="is it not.pdf"
-
-'''
- msg = email.message_from_string(m)
- self.assertEqual(msg.get_boundary(),
- 'This is even more ***fun*** is it not.pdf')
-
- def test_rfc2231_no_language_or_charset_in_charset(self):
- # This is a nonsensical charset value, but tests the code anyway
- m = '''\
-Content-Type: text/plain;
-\tcharset*0*="This%20is%20even%20more%20";
-\tcharset*1*="%2A%2A%2Afun%2A%2A%2A%20";
-\tcharset*2="is it not.pdf"
-
-'''
- msg = email.message_from_string(m)
- self.assertEqual(msg.get_content_charset(),
- 'this is even more ***fun*** is it not.pdf')
-
- def test_rfc2231_bad_encoding_in_filename(self):
- m = '''\
-Content-Disposition: inline;
-\tfilename*0*="bogus'xx'This%20is%20even%20more%20";
-\tfilename*1*="%2A%2A%2Afun%2A%2A%2A%20";
-\tfilename*2="is it not.pdf"
-
-'''
- msg = email.message_from_string(m)
- self.assertEqual(msg.get_filename(),
- 'This is even more ***fun*** is it not.pdf')
-
- def test_rfc2231_bad_encoding_in_charset(self):
- m = """\
-Content-Type: text/plain; charset*=bogus''utf-8%E2%80%9D
-
-"""
- msg = email.message_from_string(m)
- # This should return None because non-ascii characters in the charset
- # are not allowed.
- self.assertEqual(msg.get_content_charset(), None)
-
- def test_rfc2231_bad_character_in_charset(self):
- m = """\
-Content-Type: text/plain; charset*=ascii''utf-8%E2%80%9D
-
-"""
- msg = email.message_from_string(m)
- # This should return None because non-ascii characters in the charset
- # are not allowed.
- self.assertEqual(msg.get_content_charset(), None)
-
- def test_rfc2231_bad_character_in_filename(self):
- m = '''\
-Content-Disposition: inline;
-\tfilename*0*="ascii'xx'This%20is%20even%20more%20";
-\tfilename*1*="%2A%2A%2Afun%2A%2A%2A%20";
-\tfilename*2*="is it not.pdf%E2"
-
-'''
- msg = email.message_from_string(m)
- self.assertEqual(msg.get_filename(),
- 'This is even more ***fun*** is it not.pdf\ufffd')
-
- def test_rfc2231_unknown_encoding(self):
- m = """\
-Content-Transfer-Encoding: 8bit
-Content-Disposition: inline; filename*=X-UNKNOWN''myfile.txt
-
-"""
- msg = email.message_from_string(m)
- self.assertEqual(msg.get_filename(), 'myfile.txt')
-
- def test_rfc2231_single_tick_in_filename_extended(self):
- eq = self.assertEqual
- m = """\
-Content-Type: application/x-foo;
-\tname*0*=\"Frank's\"; name*1*=\" Document\"
-
-"""
- msg = email.message_from_string(m)
- charset, language, s = msg.get_param('name')
- eq(charset, None)
- eq(language, None)
- eq(s, "Frank's Document")
-
- def test_rfc2231_single_tick_in_filename(self):
- m = """\
-Content-Type: application/x-foo; name*0=\"Frank's\"; name*1=\" Document\"
-
-"""
- msg = email.message_from_string(m)
- param = msg.get_param('name')
- self.failIf(isinstance(param, tuple))
- self.assertEqual(param, "Frank's Document")
-
- def test_rfc2231_tick_attack_extended(self):
- eq = self.assertEqual
- m = """\
-Content-Type: application/x-foo;
-\tname*0*=\"us-ascii'en-us'Frank's\"; name*1*=\" Document\"
-
-"""
- msg = email.message_from_string(m)
- charset, language, s = msg.get_param('name')
- eq(charset, 'us-ascii')
- eq(language, 'en-us')
- eq(s, "Frank's Document")
-
- def test_rfc2231_tick_attack(self):
- m = """\
-Content-Type: application/x-foo;
-\tname*0=\"us-ascii'en-us'Frank's\"; name*1=\" Document\"
-
-"""
- msg = email.message_from_string(m)
- param = msg.get_param('name')
- self.failIf(isinstance(param, tuple))
- self.assertEqual(param, "us-ascii'en-us'Frank's Document")
-
- def test_rfc2231_no_extended_values(self):
- eq = self.assertEqual
- m = """\
-Content-Type: application/x-foo; name=\"Frank's Document\"
-
-"""
- msg = email.message_from_string(m)
- eq(msg.get_param('name'), "Frank's Document")
-
- def test_rfc2231_encoded_then_unencoded_segments(self):
- eq = self.assertEqual
- m = """\
-Content-Type: application/x-foo;
-\tname*0*=\"us-ascii'en-us'My\";
-\tname*1=\" Document\";
-\tname*2*=\" For You\"
-
-"""
- msg = email.message_from_string(m)
- charset, language, s = msg.get_param('name')
- eq(charset, 'us-ascii')
- eq(language, 'en-us')
- eq(s, 'My Document For You')
-
- def test_rfc2231_unencoded_then_encoded_segments(self):
- eq = self.assertEqual
- m = """\
-Content-Type: application/x-foo;
-\tname*0=\"us-ascii'en-us'My\";
-\tname*1*=\" Document\";
-\tname*2*=\" For You\"
-
-"""
- msg = email.message_from_string(m)
- charset, language, s = msg.get_param('name')
- eq(charset, 'us-ascii')
- eq(language, 'en-us')
- eq(s, 'My Document For You')
-
-
-
-def _testclasses():
- mod = sys.modules[__name__]
- return [getattr(mod, name) for name in dir(mod) if name.startswith('Test')]
-
-
-def suite():
- suite = unittest.TestSuite()
- for testclass in _testclasses():
- suite.addTest(unittest.makeSuite(testclass))
- return suite
-
-
-def test_main():
- for testclass in _testclasses():
- run_unittest(testclass)
-
-
-
-if __name__ == '__main__':
- unittest.main(defaultTest='suite')
diff --git a/Lib/email/test/test_email_torture.py b/Lib/email/test/test_email_torture.py
deleted file mode 100644
index 67f106a..0000000
--- a/Lib/email/test/test_email_torture.py
+++ /dev/null
@@ -1,136 +0,0 @@
-# Copyright (C) 2002-2004 Python Software Foundation
-#
-# A torture test of the email package. This should not be run as part of the
-# standard Python test suite since it requires several meg of email messages
-# collected in the wild. These source messages are not checked into the
-# Python distro, but are available as part of the standalone email package at
-# http://sf.net/projects/mimelib
-
-import sys
-import os
-import unittest
-from io import StringIO
-from types import ListType
-
-from email.test.test_email import TestEmailBase
-from test.test_support import TestSkipped
-
-import email
-from email import __file__ as testfile
-from email.Iterators import _structure
-
-def openfile(filename):
- from os.path import join, dirname, abspath
- path = abspath(join(dirname(testfile), os.pardir, 'moredata', filename))
- return open(path, 'r')
-
-# Prevent this test from running in the Python distro
-try:
- openfile('crispin-torture.txt')
-except IOError:
- raise TestSkipped
-
-
-
-class TortureBase(TestEmailBase):
- def _msgobj(self, filename):
- fp = openfile(filename)
- try:
- msg = email.message_from_file(fp)
- finally:
- fp.close()
- return msg
-
-
-
-class TestCrispinTorture(TortureBase):
- # Mark Crispin's torture test from the SquirrelMail project
- def test_mondo_message(self):
- eq = self.assertEqual
- neq = self.ndiffAssertEqual
- msg = self._msgobj('crispin-torture.txt')
- payload = msg.get_payload()
- eq(type(payload), ListType)
- eq(len(payload), 12)
- eq(msg.preamble, None)
- eq(msg.epilogue, '\n')
- # Probably the best way to verify the message is parsed correctly is to
- # dump its structure and compare it against the known structure.
- fp = StringIO()
- _structure(msg, fp=fp)
- neq(fp.getvalue(), """\
-multipart/mixed
- text/plain
- message/rfc822
- multipart/alternative
- text/plain
- multipart/mixed
- text/richtext
- application/andrew-inset
- message/rfc822
- audio/basic
- audio/basic
- image/pbm
- message/rfc822
- multipart/mixed
- multipart/mixed
- text/plain
- audio/x-sun
- multipart/mixed
- image/gif
- image/gif
- application/x-be2
- application/atomicmail
- audio/x-sun
- message/rfc822
- multipart/mixed
- text/plain
- image/pgm
- text/plain
- message/rfc822
- multipart/mixed
- text/plain
- image/pbm
- message/rfc822
- application/postscript
- image/gif
- message/rfc822
- multipart/mixed
- audio/basic
- audio/basic
- message/rfc822
- multipart/mixed
- application/postscript
- text/plain
- message/rfc822
- multipart/mixed
- text/plain
- multipart/parallel
- image/gif
- audio/basic
- application/atomicmail
- message/rfc822
- audio/x-sun
-""")
-
-
-def _testclasses():
- mod = sys.modules[__name__]
- return [getattr(mod, name) for name in dir(mod) if name.startswith('Test')]
-
-
-def suite():
- suite = unittest.TestSuite()
- for testclass in _testclasses():
- suite.addTest(unittest.makeSuite(testclass))
- return suite
-
-
-def test_main():
- for testclass in _testclasses():
- test_support.run_unittest(testclass)
-
-
-
-if __name__ == '__main__':
- unittest.main(defaultTest='suite')