Back to index

python3.2  3.2.2
Public Member Functions
email.test.test_email.TestRFC2231 Class Reference
Inheritance diagram for email.test.test_email.TestRFC2231:
Inheritance graph
[legend]
Collaboration diagram for email.test.test_email.TestRFC2231:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def test_get_param
def test_set_param
def test_set_param_requote
def test_del_param
def test_rfc2231_get_content_charset
def test_rfc2231_parse_rfc_quoting
def test_rfc2231_parse_extra_quoting
def test_rfc2231_no_language_or_charset
def test_rfc2231_no_language_or_charset_in_filename
def test_rfc2231_no_language_or_charset_in_filename_encoded
def test_rfc2231_partly_encoded
def test_rfc2231_partly_nonencoded
def test_rfc2231_no_language_or_charset_in_boundary
def test_rfc2231_no_language_or_charset_in_charset
def test_rfc2231_bad_encoding_in_filename
def test_rfc2231_bad_encoding_in_charset
def test_rfc2231_bad_character_in_charset
def test_rfc2231_bad_character_in_filename
def test_rfc2231_unknown_encoding
def test_rfc2231_single_tick_in_filename_extended
def test_rfc2231_single_tick_in_filename
def test_rfc2231_tick_attack_extended
def test_rfc2231_tick_attack
def test_rfc2231_no_extended_values
def test_rfc2231_encoded_then_unencoded_segments
def test_rfc2231_unencoded_then_encoded_segments
def ndiffAssertEqual

Detailed Description

Definition at line 4249 of file test_email.py.


Member Function Documentation

def email.test.test_email.TestEmailBase.ndiffAssertEqual (   self,
  first,
  second 
) [inherited]
Like assertEqual except use ndiff for readable output.

Definition at line 57 of file test_email.py.

00057 
00058     def ndiffAssertEqual(self, first, second):
00059         """Like assertEqual except use ndiff for readable output."""
00060         if first != second:
00061             sfirst = str(first)
00062             ssecond = str(second)
00063             rfirst = [repr(line) for line in sfirst.splitlines()]
00064             rsecond = [repr(line) for line in ssecond.splitlines()]
00065             diff = difflib.ndiff(rfirst, rsecond)
00066             raise self.failureException(NL + NL.join(diff))

Here is the call graph for this function:

Definition at line 4305 of file test_email.py.

04305 
04306     def test_del_param(self):
04307         eq = self.ndiffAssertEqual
04308         msg = self._msgobj('msg_01.txt')
04309         msg.set_param('foo', 'bar', charset='us-ascii', language='en')
04310         msg.set_param('title', 'This is even more ***fun*** isn\'t it!',
04311             charset='us-ascii', language='en')
04312         msg.del_param('foo', header='Content-Type')
04313         eq(msg.as_string(maxheaderlen=78), """\
04314 Return-Path: <bbb@zzz.org>
04315 Delivered-To: bbb@zzz.org
04316 Received: by mail.zzz.org (Postfix, from userid 889)
04317 \tid 27CEAD38CC; Fri,  4 May 2001 14:05:44 -0400 (EDT)
04318 MIME-Version: 1.0
04319 Content-Transfer-Encoding: 7bit
04320 Message-ID: <15090.61304.110929.45684@aaa.zzz.org>
04321 From: bbb@ddd.com (John X. Doe)
04322 To: bbb@zzz.org
04323 Subject: This is a test message
04324 Date: Fri, 4 May 2001 14:05:44 -0400
04325 Content-Type: text/plain; charset="us-ascii";
04326  title*=us-ascii'en'This%20is%20even%20more%20%2A%2A%2Afun%2A%2A%2A%20isn%27t%20it%21
04327 
04328 
04329 Hi,
04330 
04331 Do you like this message?
04332 
04333 -Me
04334 """)

Here is the call graph for this function:

Definition at line 4250 of file test_email.py.

04250 
04251     def test_get_param(self):
04252         eq = self.assertEqual
04253         msg = self._msgobj('msg_29.txt')
04254         eq(msg.get_param('title'),
04255            ('us-ascii', 'en', 'This is even more ***fun*** isn\'t it!'))
04256         eq(msg.get_param('title', unquote=False),
04257            ('us-ascii', 'en', '"This is even more ***fun*** isn\'t it!"'))

Here is the call graph for this function:

Definition at line 4477 of file test_email.py.

04477 
04478     def test_rfc2231_bad_character_in_charset(self):
04479         m = """\
04480 Content-Type: text/plain; charset*=ascii''utf-8%E2%80%9D
04481 
04482 """
04483         msg = email.message_from_string(m)
04484         # This should return None because non-ascii characters in the charset
04485         # are not allowed.
04486         self.assertEqual(msg.get_content_charset(), None)

Here is the call graph for this function:

Definition at line 4487 of file test_email.py.

04487 
04488     def test_rfc2231_bad_character_in_filename(self):
04489         m = '''\
04490 Content-Disposition: inline;
04491 \tfilename*0*="ascii'xx'This%20is%20even%20more%20";
04492 \tfilename*1*="%2A%2A%2Afun%2A%2A%2A%20";
04493 \tfilename*2*="is it not.pdf%E2"
04494 
04495 '''
04496         msg = email.message_from_string(m)
04497         self.assertEqual(msg.get_filename(),
04498                          'This is even more ***fun*** is it not.pdf\ufffd')

Here is the call graph for this function:

Definition at line 4467 of file test_email.py.

04467 
04468     def test_rfc2231_bad_encoding_in_charset(self):
04469         m = """\
04470 Content-Type: text/plain; charset*=bogus''utf-8%E2%80%9D
04471 
04472 """
04473         msg = email.message_from_string(m)
04474         # This should return None because non-ascii characters in the charset
04475         # are not allowed.
04476         self.assertEqual(msg.get_content_charset(), None)

Here is the call graph for this function:

Definition at line 4455 of file test_email.py.

04455 
04456     def test_rfc2231_bad_encoding_in_filename(self):
04457         m = '''\
04458 Content-Disposition: inline;
04459 \tfilename*0*="bogus'xx'This%20is%20even%20more%20";
04460 \tfilename*1*="%2A%2A%2Afun%2A%2A%2A%20";
04461 \tfilename*2="is it not.pdf"
04462 
04463 '''
04464         msg = email.message_from_string(m)
04465         self.assertEqual(msg.get_filename(),
04466                          'This is even more ***fun*** is it not.pdf')

Here is the call graph for this function:

Definition at line 4564 of file test_email.py.

04564 
04565     def test_rfc2231_encoded_then_unencoded_segments(self):
04566         eq = self.assertEqual
04567         m = """\
04568 Content-Type: application/x-foo;
04569 \tname*0*=\"us-ascii'en-us'My\";
04570 \tname*1=\" Document\";
04571 \tname*2*=\" For You\"
04572 
04573 """
04574         msg = email.message_from_string(m)
04575         charset, language, s = msg.get_param('name')
04576         eq(charset, 'us-ascii')
04577         eq(language, 'en-us')
04578         eq(s, 'My Document For You')

Here is the call graph for this function:

Definition at line 4335 of file test_email.py.

04335 
04336     def test_rfc2231_get_content_charset(self):
04337         eq = self.assertEqual
04338         msg = self._msgobj('msg_32.txt')
04339         eq(msg.get_content_charset(), 'us-ascii')

Here is the call graph for this function:

Definition at line 4555 of file test_email.py.

04555 
04556     def test_rfc2231_no_extended_values(self):
04557         eq = self.assertEqual
04558         m = """\
04559 Content-Type: application/x-foo; name=\"Frank's Document\"
04560 
04561 """
04562         msg = email.message_from_string(m)
04563         eq(msg.get_param('name'), "Frank's Document")

Here is the call graph for this function:

Definition at line 4366 of file test_email.py.

04366 
04367     def test_rfc2231_no_language_or_charset(self):
04368         m = '''\
04369 Content-Transfer-Encoding: 8bit
04370 Content-Disposition: inline; filename="file____C__DOCUMENTS_20AND_20SETTINGS_FABIEN_LOCAL_20SETTINGS_TEMP_nsmail.htm"
04371 Content-Type: text/html; NAME*0=file____C__DOCUMENTS_20AND_20SETTINGS_FABIEN_LOCAL_20SETTINGS_TEM; NAME*1=P_nsmail.htm
04372 
04373 '''
04374         msg = email.message_from_string(m)
04375         param = msg.get_param('NAME')
04376         self.assertFalse(isinstance(param, tuple))
04377         self.assertEqual(
04378             param,
04379             'file____C__DOCUMENTS_20AND_20SETTINGS_FABIEN_LOCAL_20SETTINGS_TEMP_nsmail.htm')

Here is the call graph for this function:

Definition at line 4430 of file test_email.py.

04430 
04431     def test_rfc2231_no_language_or_charset_in_boundary(self):
04432         m = '''\
04433 Content-Type: multipart/alternative;
04434 \tboundary*0*="''This%20is%20even%20more%20";
04435 \tboundary*1*="%2A%2A%2Afun%2A%2A%2A%20";
04436 \tboundary*2="is it not.pdf"
04437 
04438 '''
04439         msg = email.message_from_string(m)
04440         self.assertEqual(msg.get_boundary(),
04441                          'This is even more ***fun*** is it not.pdf')

Here is the call graph for this function:

Definition at line 4442 of file test_email.py.

04442 
04443     def test_rfc2231_no_language_or_charset_in_charset(self):
04444         # This is a nonsensical charset value, but tests the code anyway
04445         m = '''\
04446 Content-Type: text/plain;
04447 \tcharset*0*="This%20is%20even%20more%20";
04448 \tcharset*1*="%2A%2A%2Afun%2A%2A%2A%20";
04449 \tcharset*2="is it not.pdf"
04450 
04451 '''
04452         msg = email.message_from_string(m)
04453         self.assertEqual(msg.get_content_charset(),
04454                          'this is even more ***fun*** is it not.pdf')

Here is the call graph for this function:

Definition at line 4380 of file test_email.py.

04380 
04381     def test_rfc2231_no_language_or_charset_in_filename(self):
04382         m = '''\
04383 Content-Disposition: inline;
04384 \tfilename*0*="''This%20is%20even%20more%20";
04385 \tfilename*1*="%2A%2A%2Afun%2A%2A%2A%20";
04386 \tfilename*2="is it not.pdf"
04387 
04388 '''
04389         msg = email.message_from_string(m)
04390         self.assertEqual(msg.get_filename(),
04391                          'This is even more ***fun*** is it not.pdf')

Here is the call graph for this function:

Definition at line 4392 of file test_email.py.

04392 
04393     def test_rfc2231_no_language_or_charset_in_filename_encoded(self):
04394         m = '''\
04395 Content-Disposition: inline;
04396 \tfilename*0*="''This%20is%20even%20more%20";
04397 \tfilename*1*="%2A%2A%2Afun%2A%2A%2A%20";
04398 \tfilename*2="is it not.pdf"
04399 
04400 '''
04401         msg = email.message_from_string(m)
04402         self.assertEqual(msg.get_filename(),
04403                          'This is even more ***fun*** is it not.pdf')

Here is the call graph for this function:

Definition at line 4353 of file test_email.py.

04353 
04354     def test_rfc2231_parse_extra_quoting(self):
04355         m = textwrap.dedent('''\
04356             Content-Disposition: inline;
04357             \tfilename*0*="''This%20is%20even%20more%20";
04358             \tfilename*1*="%2A%2A%2Afun%2A%2A%2A%20";
04359             \tfilename*2="is it not.pdf"
04360 
04361             ''')
04362         msg = email.message_from_string(m)
04363         self.assertEqual(msg.get_filename(),
04364                          'This is even more ***fun*** is it not.pdf')
04365         self.assertEqual(m, msg.as_string())

Here is the call graph for this function:

Definition at line 4340 of file test_email.py.

04340 
04341     def test_rfc2231_parse_rfc_quoting(self):
04342         m = textwrap.dedent('''\
04343             Content-Disposition: inline;
04344             \tfilename*0*=''This%20is%20even%20more%20;
04345             \tfilename*1*=%2A%2A%2Afun%2A%2A%2A%20;
04346             \tfilename*2="is it not.pdf"
04347 
04348             ''')
04349         msg = email.message_from_string(m)
04350         self.assertEqual(msg.get_filename(),
04351                          'This is even more ***fun*** is it not.pdf')
04352         self.assertEqual(m, msg.as_string())

Here is the call graph for this function:

Definition at line 4404 of file test_email.py.

04404 
04405     def test_rfc2231_partly_encoded(self):
04406         m = '''\
04407 Content-Disposition: inline;
04408 \tfilename*0="''This%20is%20even%20more%20";
04409 \tfilename*1*="%2A%2A%2Afun%2A%2A%2A%20";
04410 \tfilename*2="is it not.pdf"
04411 
04412 '''
04413         msg = email.message_from_string(m)
04414         self.assertEqual(
04415             msg.get_filename(),
04416             'This%20is%20even%20more%20***fun*** is it not.pdf')

Here is the call graph for this function:

Definition at line 4417 of file test_email.py.

04417 
04418     def test_rfc2231_partly_nonencoded(self):
04419         m = '''\
04420 Content-Disposition: inline;
04421 \tfilename*0="This%20is%20even%20more%20";
04422 \tfilename*1="%2A%2A%2Afun%2A%2A%2A%20";
04423 \tfilename*2="is it not.pdf"
04424 
04425 '''
04426         msg = email.message_from_string(m)
04427         self.assertEqual(
04428             msg.get_filename(),
04429             'This%20is%20even%20more%20%2A%2A%2Afun%2A%2A%2A%20is it not.pdf')

Here is the call graph for this function:

Definition at line 4521 of file test_email.py.

04521 
04522     def test_rfc2231_single_tick_in_filename(self):
04523         m = """\
04524 Content-Type: application/x-foo; name*0=\"Frank's\"; name*1=\" Document\"
04525 
04526 """
04527         msg = email.message_from_string(m)
04528         param = msg.get_param('name')
04529         self.assertFalse(isinstance(param, tuple))
04530         self.assertEqual(param, "Frank's Document")

Here is the call graph for this function:

Definition at line 4508 of file test_email.py.

04508 
04509     def test_rfc2231_single_tick_in_filename_extended(self):
04510         eq = self.assertEqual
04511         m = """\
04512 Content-Type: application/x-foo;
04513 \tname*0*=\"Frank's\"; name*1*=\" Document\"
04514 
04515 """
04516         msg = email.message_from_string(m)
04517         charset, language, s = msg.get_param('name')
04518         eq(charset, None)
04519         eq(language, None)
04520         eq(s, "Frank's Document")

Here is the call graph for this function:

Definition at line 4544 of file test_email.py.

04544 
04545     def test_rfc2231_tick_attack(self):
04546         m = """\
04547 Content-Type: application/x-foo;
04548 \tname*0=\"us-ascii'en-us'Frank's\"; name*1=\" Document\"
04549 
04550 """
04551         msg = email.message_from_string(m)
04552         param = msg.get_param('name')
04553         self.assertFalse(isinstance(param, tuple))
04554         self.assertEqual(param, "us-ascii'en-us'Frank's Document")

Here is the call graph for this function:

Definition at line 4531 of file test_email.py.

04531 
04532     def test_rfc2231_tick_attack_extended(self):
04533         eq = self.assertEqual
04534         m = """\
04535 Content-Type: application/x-foo;
04536 \tname*0*=\"us-ascii'en-us'Frank's\"; name*1*=\" Document\"
04537 
04538 """
04539         msg = email.message_from_string(m)
04540         charset, language, s = msg.get_param('name')
04541         eq(charset, 'us-ascii')
04542         eq(language, 'en-us')
04543         eq(s, "Frank's Document")

Here is the call graph for this function:

Definition at line 4579 of file test_email.py.

04579 
04580     def test_rfc2231_unencoded_then_encoded_segments(self):
04581         eq = self.assertEqual
04582         m = """\
04583 Content-Type: application/x-foo;
04584 \tname*0=\"us-ascii'en-us'My\";
04585 \tname*1*=\" Document\";
04586 \tname*2*=\" For You\"
04587 
04588 """
04589         msg = email.message_from_string(m)
04590         charset, language, s = msg.get_param('name')
04591         eq(charset, 'us-ascii')
04592         eq(language, 'en-us')
04593         eq(s, 'My Document For You')
04594 
04595 
04596 
04597 # Tests to ensure that signed parts of an email are completely preserved, as
04598 # required by RFC1847 section 2.1.  Note that these are incomplete, because the
# email package does not currently always preserve the body.  See issue 1670765.

Here is the call graph for this function:

Definition at line 4499 of file test_email.py.

04499 
04500     def test_rfc2231_unknown_encoding(self):
04501         m = """\
04502 Content-Transfer-Encoding: 8bit
04503 Content-Disposition: inline; filename*=X-UNKNOWN''myfile.txt
04504 
04505 """
04506         msg = email.message_from_string(m)
04507         self.assertEqual(msg.get_filename(), 'myfile.txt')

Here is the call graph for this function:

Definition at line 4258 of file test_email.py.

04258 
04259     def test_set_param(self):
04260         eq = self.ndiffAssertEqual
04261         msg = Message()
04262         msg.set_param('title', 'This is even more ***fun*** isn\'t it!',
04263                       charset='us-ascii')
04264         eq(msg.get_param('title'),
04265            ('us-ascii', '', 'This is even more ***fun*** isn\'t it!'))
04266         msg.set_param('title', 'This is even more ***fun*** isn\'t it!',
04267                       charset='us-ascii', language='en')
04268         eq(msg.get_param('title'),
04269            ('us-ascii', 'en', 'This is even more ***fun*** isn\'t it!'))
04270         msg = self._msgobj('msg_01.txt')
04271         msg.set_param('title', 'This is even more ***fun*** isn\'t it!',
04272                       charset='us-ascii', language='en')
04273         eq(msg.as_string(maxheaderlen=78), """\
04274 Return-Path: <bbb@zzz.org>
04275 Delivered-To: bbb@zzz.org
04276 Received: by mail.zzz.org (Postfix, from userid 889)
04277 \tid 27CEAD38CC; Fri,  4 May 2001 14:05:44 -0400 (EDT)
04278 MIME-Version: 1.0
04279 Content-Transfer-Encoding: 7bit
04280 Message-ID: <15090.61304.110929.45684@aaa.zzz.org>
04281 From: bbb@ddd.com (John X. Doe)
04282 To: bbb@zzz.org
04283 Subject: This is a test message
04284 Date: Fri, 4 May 2001 14:05:44 -0400
04285 Content-Type: text/plain; charset=us-ascii;
04286  title*=us-ascii'en'This%20is%20even%20more%20%2A%2A%2Afun%2A%2A%2A%20isn%27t%20it%21
04287 
04288 
04289 Hi,
04290 
04291 Do you like this message?
04292 
04293 -Me
04294 """)

Here is the call graph for this function:

Definition at line 4295 of file test_email.py.

04295 
04296     def test_set_param_requote(self):
04297         msg = Message()
04298         msg.set_param('title', 'foo')
04299         self.assertEqual(msg['content-type'], 'text/plain; title="foo"')
04300         msg.set_param('title', 'bar', requote=False)
04301         self.assertEqual(msg['content-type'], 'text/plain; title=bar')
04302         # tspecial is still quoted.
04303         msg.set_param('title', "(bar)bell", requote=False)
04304         self.assertEqual(msg['content-type'], 'text/plain; title="(bar)bell"')

Here is the call graph for this function:


The documentation for this class was generated from the following file: