From 9c74569ec9c694dbd1622b565448165ee486d3bc Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Thu, 26 Sep 2002 17:21:02 +0000 Subject: [PATCH] Fixing some RFC 2231 related issues as reported in the Spambayes project, and with assistance from Oleg Broytmann. Specifically, added some new tests to make sure we handle RFC 2231 encoded parameters correctly. Two new data files were added which contain RFC 2231 encoded parameters. --- Lib/email/test/data/msg_32.txt | 14 ++++++++++++++ Lib/email/test/data/msg_33.txt | 29 +++++++++++++++++++++++++++++ Lib/email/test/test_email.py | 23 +++++++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 Lib/email/test/data/msg_32.txt create mode 100644 Lib/email/test/data/msg_33.txt diff --git a/Lib/email/test/data/msg_32.txt b/Lib/email/test/data/msg_32.txt new file mode 100644 index 00000000000..07ec5af9a3d --- /dev/null +++ b/Lib/email/test/data/msg_32.txt @@ -0,0 +1,14 @@ +Delivered-To: freebsd-isp@freebsd.org +Date: Tue, 26 Sep 2000 12:23:03 -0500 +From: Anne Person +To: Barney Dude +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 new file mode 100644 index 00000000000..042787a4fd8 --- /dev/null +++ b/Lib/email/test/data/msg_33.txt @@ -0,0 +1,29 @@ +Delivered-To: freebsd-isp@freebsd.org +Date: Wed, 27 Sep 2000 11:11:09 -0500 +From: Anne Person +To: Barney Dude +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/test_email.py b/Lib/email/test/test_email.py index 7df5fcc5874..a63adc87d55 100644 --- a/Lib/email/test/test_email.py +++ b/Lib/email/test/test_email.py @@ -1465,6 +1465,14 @@ 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_content_type(self): eq = self.assertEquals unless = self.failUnless @@ -1514,6 +1522,7 @@ def test_parser(self): self.failUnless(isinstance(msg1.get_payload(), StringType)) eq(msg1.get_payload(), '\n') + # Test various other bits of the package's functionality class TestMiscellaneous(unittest.TestCase): @@ -2147,6 +2156,15 @@ def test_string_charset(self): 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') + # Test RFC 2231 header parameters (en/de)coding @@ -2226,6 +2244,11 @@ def test_del_param(self): -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 _testclasses():