Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e99e2f5

Browse files
committed
test_set_param(), test_del_param(): Test RFC 2231 encoding support by
Oleg Broytmann in SF patch #600096. Whitespace normalized by Barry.
1 parent 3c25535 commit e99e2f5

1 file changed

Lines changed: 68 additions & 1 deletion

File tree

Lib/email/test/test_email.py

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2105,7 +2105,7 @@ def test_string_charset(self):
21052105

21062106

21072107

2108-
# Test RFC 2231 header parameters decoding
2108+
# Test RFC 2231 header parameters (en/de)coding
21092109
class TestRFC2231(TestEmailBase):
21102110
def test_get_param(self):
21112111
eq = self.assertEqual
@@ -2115,6 +2115,73 @@ def test_get_param(self):
21152115
eq(msg.get_param('title', unquote=0),
21162116
('us-ascii', 'en', '"This is even more ***fun*** isn\'t it!"'))
21172117

2118+
def test_set_param(self):
2119+
eq = self.assertEqual
2120+
msg = Message()
2121+
msg.set_param('title', 'This is even more ***fun*** isn\'t it!',
2122+
charset='us-ascii')
2123+
eq(msg.get_param('title'),
2124+
('us-ascii', '', 'This is even more ***fun*** isn\'t it!'))
2125+
msg.set_param('title', 'This is even more ***fun*** isn\'t it!',
2126+
charset='us-ascii', language='en')
2127+
eq(msg.get_param('title'),
2128+
('us-ascii', 'en', 'This is even more ***fun*** isn\'t it!'))
2129+
msg = self._msgobj('msg_01.txt')
2130+
msg.set_param('title', 'This is even more ***fun*** isn\'t it!',
2131+
charset='us-ascii', language='en')
2132+
eq(msg.as_string(), """\
2133+
Return-Path: <[email protected]>
2134+
Delivered-To: [email protected]
2135+
Received: by mail.zzz.org (Postfix, from userid 889)
2136+
\tid 27CEAD38CC; Fri, 4 May 2001 14:05:44 -0400 (EDT)
2137+
MIME-Version: 1.0
2138+
Content-Transfer-Encoding: 7bit
2139+
Message-ID: <[email protected]>
2140+
From: [email protected] (John X. Doe)
2141+
2142+
Subject: This is a test message
2143+
Date: Fri, 4 May 2001 14:05:44 -0400
2144+
Content-Type: text/plain; charset=us-ascii;
2145+
\ttitle*="us-ascii'en'This%20is%20even%20more%20%2A%2A%2Afun%2A%2A%2A%20isn%27t%20it%21"
2146+
2147+
2148+
Hi,
2149+
2150+
Do you like this message?
2151+
2152+
-Me
2153+
""")
2154+
2155+
def test_del_param(self):
2156+
eq = self.ndiffAssertEqual
2157+
msg = self._msgobj('msg_01.txt')
2158+
msg.set_param('foo', 'bar', charset='us-ascii', language='en')
2159+
msg.set_param('title', 'This is even more ***fun*** isn\'t it!',
2160+
charset='us-ascii', language='en')
2161+
msg.del_param('foo', header='Content-Type')
2162+
eq(msg.as_string(), """\
2163+
Return-Path: <[email protected]>
2164+
Delivered-To: [email protected]
2165+
Received: by mail.zzz.org (Postfix, from userid 889)
2166+
\tid 27CEAD38CC; Fri, 4 May 2001 14:05:44 -0400 (EDT)
2167+
MIME-Version: 1.0
2168+
Content-Transfer-Encoding: 7bit
2169+
Message-ID: <[email protected]>
2170+
From: [email protected] (John X. Doe)
2171+
2172+
Subject: This is a test message
2173+
Date: Fri, 4 May 2001 14:05:44 -0400
2174+
Content-Type: text/plain; charset="us-ascii";
2175+
\ttitle*="us-ascii'en'This%20is%20even%20more%20%2A%2A%2Afun%2A%2A%2A%20isn%27t%20it%21"
2176+
2177+
2178+
Hi,
2179+
2180+
Do you like this message?
2181+
2182+
-Me
2183+
""")
2184+
21182185

21192186

21202187
def _testclasses():

0 commit comments

Comments
 (0)