Back to index

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

List of all members.

Public Member Functions

def test_get_all
def test_getset_charset
def test_set_charset_from_string
def test_set_payload_with_charset
def test_get_charsets
def test_get_filename
def test_get_filename_with_name_parameter
def test_get_boundary
def test_set_boundary
def test_make_boundary
def test_message_rfc822_only
def test_get_decoded_payload
def test_get_decoded_uu_payload
def test_get_payload_n_raises_on_non_multipart
def test_decoded_generator
def test__contains__
def test_as_string
def test_bad_param
def test_missing_filename
def test_bogus_filename
def test_missing_boundary
def test_get_params
def test_get_param_liberal
def test_get_param
def test_get_param_funky_continuation_lines
def test_get_param_with_semis_in_quotes
def test_get_param_with_quotes
def test_field_containment
def test_set_param
def test_del_param
def test_del_param_on_other_header
def test_del_param_on_nonexistent_header
def test_del_nonexistent_param
def test_set_type
def test_set_type_on_other_header
def test_get_content_type_missing
def test_get_content_type_missing_with_default_type
def test_get_content_type_from_message_implicit
def test_get_content_type_from_message_explicit
def test_get_content_type_from_message_text_plain_implicit
def test_get_content_type_from_message_text_plain_explicit
def test_get_content_maintype_missing
def test_get_content_maintype_missing_with_default_type
def test_get_content_maintype_from_message_implicit
def test_get_content_maintype_from_message_explicit
def test_get_content_maintype_from_message_text_plain_implicit
def test_get_content_maintype_from_message_text_plain_explicit
def test_get_content_subtype_missing
def test_get_content_subtype_missing_with_default_type
def test_get_content_subtype_from_message_implicit
def test_get_content_subtype_from_message_explicit
def test_get_content_subtype_from_message_text_plain_implicit
def test_get_content_subtype_from_message_text_plain_explicit
def test_get_content_maintype_error
def test_get_content_subtype_error
def test_replace_header
def test_broken_base64_payload
def test_broken_unicode_payload
def test_questionable_bytes_payload
def test_ascii_add_header
def test_noascii_add_header
def test_nonascii_add_header_via_triple
def test_ascii_add_header_with_tspecial
def test_nonascii_add_header_with_tspecial
def test_add_header_with_name_only_param
def test_add_header_with_no_value
def test_embeded_header_via_Header_rejected
def test_embeded_header_via_string_rejected
def ndiffAssertEqual

Detailed Description

Definition at line 74 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 253 of file test_email.py.

00253 
00254     def test__contains__(self):
00255         msg = Message()
00256         msg['From'] = 'Me'
00257         msg['to'] = 'You'
00258         # Check for case insensitivity
00259         self.assertTrue('from' in msg)
00260         self.assertTrue('From' in msg)
00261         self.assertTrue('FROM' in msg)
00262         self.assertTrue('to' in msg)
00263         self.assertTrue('To' in msg)
00264         self.assertTrue('TO' in msg)

Here is the call graph for this function:

Definition at line 600 of file test_email.py.

00600 
00601     def test_add_header_with_name_only_param(self):
00602         msg = Message()
00603         msg.add_header('Content-Disposition', 'inline', foo_bar=None)
00604         self.assertEqual("inline; foo-bar", msg['Content-Disposition'])

Here is the call graph for this function:

Definition at line 605 of file test_email.py.

00605 
00606     def test_add_header_with_no_value(self):
00607         msg = Message()
00608         msg.add_header('X-Status', None)
00609         self.assertEqual('', msg['X-Status'])

Here is the call graph for this function:

Definition at line 265 of file test_email.py.

00265 
00266     def test_as_string(self):
00267         eq = self.ndiffAssertEqual
00268         msg = self._msgobj('msg_01.txt')
00269         with openfile('msg_01.txt') as fp:
00270             text = fp.read()
00271         eq(text, str(msg))
00272         fullrepr = msg.as_string(unixfrom=True)
00273         lines = fullrepr.split('\n')
00274         self.assertTrue(lines[0].startswith('From '))
00275         eq(text, NL.join(lines[1:]))

Here is the call graph for this function:

Definition at line 561 of file test_email.py.

00561 
00562     def test_ascii_add_header(self):
00563         msg = Message()
00564         msg.add_header('Content-Disposition', 'attachment',
00565                        filename='bud.gif')
00566         self.assertEqual('attachment; filename="bud.gif"',
00567             msg['Content-Disposition'])

Here is the call graph for this function:

Definition at line 584 of file test_email.py.

00584 
00585     def test_ascii_add_header_with_tspecial(self):
00586         msg = Message()
00587         msg.add_header('Content-Disposition', 'attachment',
00588             filename="windows [filename].ppt")
00589         self.assertEqual(
00590             'attachment; filename="windows [filename].ppt"',
00591             msg['Content-Disposition'])

Here is the call graph for this function:

Definition at line 276 of file test_email.py.

00276 
00277     def test_bad_param(self):
00278         msg = email.message_from_string("Content-Type: blarg; baz; boo\n")
00279         self.assertEqual(msg.get_param('baz'), '')

Here is the call graph for this function:

Definition at line 284 of file test_email.py.

00284 
00285     def test_bogus_filename(self):
00286         msg = email.message_from_string(
00287         "Content-Disposition: blarg; filename\n")
00288         self.assertEqual(msg.get_filename(), '')

Here is the call graph for this function:

Definition at line 530 of file test_email.py.

00530 
00531     def test_broken_base64_payload(self):
00532         x = 'AwDp0P7//y6LwKEAcPa/6Q=9'
00533         msg = Message()
00534         msg['content-type'] = 'audio/x-midi'
00535         msg['content-transfer-encoding'] = 'base64'
00536         msg.set_payload(x)
00537         self.assertEqual(msg.get_payload(decode=True),
00538                          bytes(x, 'raw-unicode-escape'))

Here is the call graph for this function:

Definition at line 539 of file test_email.py.

00539 
00540     def test_broken_unicode_payload(self):
00541         # This test improves coverage but is not a compliance test.
00542         # The behavior in this situation is currently undefined by the API.
00543         x = 'this is a br\xf6ken thing to do'
00544         msg = Message()
00545         msg['content-type'] = 'text/plain'
00546         msg['content-transfer-encoding'] = '8bit'
00547         msg.set_payload(x)
00548         self.assertEqual(msg.get_payload(decode=True),
00549                          bytes(x, 'raw-unicode-escape'))

Here is the call graph for this function:

Definition at line 243 of file test_email.py.

00243 
00244     def test_decoded_generator(self):
00245         eq = self.assertEqual
00246         msg = self._msgobj('msg_07.txt')
00247         with openfile('msg_17.txt') as fp:
00248             text = fp.read()
00249         s = StringIO()
00250         g = DecodedGenerator(s)
00251         g.flatten(msg)
00252         eq(s.getvalue(), text)

Here is the call graph for this function:

Definition at line 402 of file test_email.py.

00402 
00403     def test_del_nonexistent_param(self):
00404         msg = Message()
00405         msg.add_header('Content-Type', 'text/plain', charset='utf-8')
00406         existing_header = msg['Content-Type']
00407         msg.del_param('foobar', header='Content-Type')
00408         self.assertEqual(msg['Content-Type'], 'text/plain; charset="utf-8"')

Here is the call graph for this function:

Definition at line 375 of file test_email.py.

00375 
00376     def test_del_param(self):
00377         eq = self.assertEqual
00378         msg = self._msgobj('msg_05.txt')
00379         eq(msg.get_params(),
00380            [('multipart/report', ''), ('report-type', 'delivery-status'),
00381             ('boundary', 'D1690A7AC1.996856090/mail.example.com')])
00382         old_val = msg.get_param("report-type")
00383         msg.del_param("report-type")
00384         eq(msg.get_params(),
00385            [('multipart/report', ''),
00386             ('boundary', 'D1690A7AC1.996856090/mail.example.com')])
00387         msg.set_param("report-type", old_val)
00388         eq(msg.get_params(),
00389            [('multipart/report', ''),
00390             ('boundary', 'D1690A7AC1.996856090/mail.example.com'),
00391             ('report-type', old_val)])

Here is the call graph for this function:

Definition at line 398 of file test_email.py.

00398 
00399     def test_del_param_on_nonexistent_header(self):
00400         msg = Message()
00401         msg.del_param('filename', 'content-disposition')

Definition at line 392 of file test_email.py.

00392 
00393     def test_del_param_on_other_header(self):
00394         msg = Message()
00395         msg.add_header('Content-Disposition', 'attachment', filename='bud.gif')
00396         msg.del_param('filename', 'content-disposition')
00397         self.assertEqual(msg['content-disposition'], 'attachment')

Here is the call graph for this function:

Definition at line 612 of file test_email.py.

00612 
00613     def test_embeded_header_via_Header_rejected(self):
00614         msg = Message()
00615         msg['Dummy'] = Header('dummy\nX-Injected-Header: test')
00616         self.assertRaises(errors.HeaderParseError, msg.as_string)

Here is the call graph for this function:

Definition at line 617 of file test_email.py.

00617 
00618     def test_embeded_header_via_string_rejected(self):
00619         msg = Message()
00620         msg['Dummy'] = 'dummy\nX-Injected-Header: test'
00621         self.assertRaises(errors.HeaderParseError, msg.as_string)
00622 
# Test the email.encoders module

Here is the call graph for this function:

Definition at line 350 of file test_email.py.

00350 
00351     def test_field_containment(self):
00352         unless = self.assertTrue
00353         msg = email.message_from_string('Header: exists')
00354         unless('header' in msg)
00355         unless('Header' in msg)
00356         unless('HEADER' in msg)
00357         self.assertFalse('headerx' in msg)

Here is the call graph for this function:

Definition at line 75 of file test_email.py.

00075 
00076     def test_get_all(self):
00077         eq = self.assertEqual
00078         msg = self._msgobj('msg_20.txt')
00079         eq(msg.get_all('cc'), ['ccc@zzz.org', 'ddd@zzz.org', 'eee@zzz.org'])
00080         eq(msg.get_all('xx', 'n/a'), 'n/a')

Here is the call graph for this function:

Definition at line 155 of file test_email.py.

00155 
00156     def test_get_boundary(self):
00157         eq = self.assertEqual
00158         msg = self._msgobj('msg_07.txt')
00159         # No quotes!
00160         eq(msg.get_boundary(), 'BOUNDARY')

Here is the call graph for this function:

Definition at line 120 of file test_email.py.

00120 
00121     def test_get_charsets(self):
00122         eq = self.assertEqual
00123 
00124         msg = self._msgobj('msg_08.txt')
00125         charsets = msg.get_charsets()
00126         eq(charsets, [None, 'us-ascii', 'iso-8859-1', 'iso-8859-2', 'koi8-r'])
00127 
00128         msg = self._msgobj('msg_09.txt')
00129         charsets = msg.get_charsets('dingbat')
00130         eq(charsets, ['dingbat', 'us-ascii', 'iso-8859-1', 'dingbat',
00131                       'koi8-r'])
00132 
00133         msg = self._msgobj('msg_12.txt')
00134         charsets = msg.get_charsets()
00135         eq(charsets, [None, 'us-ascii', 'iso-8859-1', None, 'iso-8859-2',
00136                       'iso-8859-3', 'us-ascii', 'koi8-r'])

Here is the call graph for this function:

Definition at line 503 of file test_email.py.

00503 
00504     def test_get_content_maintype_error(self):
00505         msg = Message()
00506         msg['Content-Type'] = 'no-slash-in-this-string'
00507         self.assertEqual(msg.get_content_maintype(), 'text')

Here is the call graph for this function:

Definition at line 466 of file test_email.py.

00466 
00467     def test_get_content_maintype_from_message_explicit(self):
00468         msg = self._msgobj('msg_28.txt')
00469         self.assertEqual(msg.get_payload(0).get_content_maintype(), 'message')

Here is the call graph for this function:

Definition at line 462 of file test_email.py.

00462 
00463     def test_get_content_maintype_from_message_implicit(self):
00464         msg = self._msgobj('msg_30.txt')
00465         self.assertEqual(msg.get_payload(0).get_content_maintype(), 'message')

Here is the call graph for this function:

Definition at line 474 of file test_email.py.

00474 
00475     def test_get_content_maintype_from_message_text_plain_explicit(self):
00476         msg = self._msgobj('msg_01.txt')
00477         self.assertEqual(msg.get_content_maintype(), 'text')

Here is the call graph for this function:

Definition at line 470 of file test_email.py.

00470 
00471     def test_get_content_maintype_from_message_text_plain_implicit(self):
00472         msg = self._msgobj('msg_03.txt')
00473         self.assertEqual(msg.get_content_maintype(), 'text')

Here is the call graph for this function:

Definition at line 453 of file test_email.py.

00453 
00454     def test_get_content_maintype_missing(self):
00455         msg = Message()
00456         self.assertEqual(msg.get_content_maintype(), 'text')

Here is the call graph for this function:

Definition at line 457 of file test_email.py.

00457 
00458     def test_get_content_maintype_missing_with_default_type(self):
00459         msg = Message()
00460         msg.set_default_type('message/rfc822')
00461         self.assertEqual(msg.get_content_maintype(), 'message')

Here is the call graph for this function:

Definition at line 508 of file test_email.py.

00508 
00509     def test_get_content_subtype_error(self):
00510         msg = Message()
00511         msg['Content-Type'] = 'no-slash-in-this-string'
00512         self.assertEqual(msg.get_content_subtype(), 'plain')

Here is the call graph for this function:

Definition at line 491 of file test_email.py.

00491 
00492     def test_get_content_subtype_from_message_explicit(self):
00493         msg = self._msgobj('msg_28.txt')
00494         self.assertEqual(msg.get_payload(0).get_content_subtype(), 'rfc822')

Here is the call graph for this function:

Definition at line 487 of file test_email.py.

00487 
00488     def test_get_content_subtype_from_message_implicit(self):
00489         msg = self._msgobj('msg_30.txt')
00490         self.assertEqual(msg.get_payload(0).get_content_subtype(), 'rfc822')

Here is the call graph for this function:

Definition at line 499 of file test_email.py.

00499 
00500     def test_get_content_subtype_from_message_text_plain_explicit(self):
00501         msg = self._msgobj('msg_01.txt')
00502         self.assertEqual(msg.get_content_subtype(), 'plain')

Here is the call graph for this function:

Definition at line 495 of file test_email.py.

00495 
00496     def test_get_content_subtype_from_message_text_plain_implicit(self):
00497         msg = self._msgobj('msg_03.txt')
00498         self.assertEqual(msg.get_content_subtype(), 'plain')

Here is the call graph for this function:

Definition at line 478 of file test_email.py.

00478 
00479     def test_get_content_subtype_missing(self):
00480         msg = Message()
00481         self.assertEqual(msg.get_content_subtype(), 'plain')

Here is the call graph for this function:

Definition at line 482 of file test_email.py.

00482 
00483     def test_get_content_subtype_missing_with_default_type(self):
00484         msg = Message()
00485         msg.set_default_type('message/rfc822')
00486         self.assertEqual(msg.get_content_subtype(), 'rfc822')

Here is the call graph for this function:

Definition at line 440 of file test_email.py.

00440 
00441     def test_get_content_type_from_message_explicit(self):
00442         msg = self._msgobj('msg_28.txt')
00443         self.assertEqual(msg.get_payload(0).get_content_type(),
00444                          'message/rfc822')

Here is the call graph for this function:

Definition at line 435 of file test_email.py.

00435 
00436     def test_get_content_type_from_message_implicit(self):
00437         msg = self._msgobj('msg_30.txt')
00438         self.assertEqual(msg.get_payload(0).get_content_type(),
00439                          'message/rfc822')

Here is the call graph for this function:

Definition at line 449 of file test_email.py.

00449 
00450     def test_get_content_type_from_message_text_plain_explicit(self):
00451         msg = self._msgobj('msg_01.txt')
00452         self.assertEqual(msg.get_content_type(), 'text/plain')

Here is the call graph for this function:

Definition at line 445 of file test_email.py.

00445 
00446     def test_get_content_type_from_message_text_plain_implicit(self):
00447         msg = self._msgobj('msg_03.txt')
00448         self.assertEqual(msg.get_content_type(), 'text/plain')

Here is the call graph for this function:

Definition at line 426 of file test_email.py.

00426 
00427     def test_get_content_type_missing(self):
00428         msg = Message()
00429         self.assertEqual(msg.get_content_type(), 'text/plain')

Here is the call graph for this function:

Definition at line 430 of file test_email.py.

00430 
00431     def test_get_content_type_missing_with_default_type(self):
00432         msg = Message()
00433         msg.set_default_type('message/rfc822')
00434         self.assertEqual(msg.get_content_type(), 'message/rfc822')

Here is the call graph for this function:

Definition at line 206 of file test_email.py.

00206 
00207     def test_get_decoded_payload(self):
00208         eq = self.assertEqual
00209         msg = self._msgobj('msg_10.txt')
00210         # The outer message is a multipart
00211         eq(msg.get_payload(decode=True), None)
00212         # Subpart 1 is 7bit encoded
00213         eq(msg.get_payload(0).get_payload(decode=True),
00214            b'This is a 7bit encoded message.\n')
00215         # Subpart 2 is quopri
00216         eq(msg.get_payload(1).get_payload(decode=True),
00217            b'\xa1This is a Quoted Printable encoded message!\n')
00218         # Subpart 3 is base64
00219         eq(msg.get_payload(2).get_payload(decode=True),
00220            b'This is a Base64 encoded message.')
00221         # Subpart 4 is base64 with a trailing newline, which
00222         # used to be stripped (issue 7143).
00223         eq(msg.get_payload(3).get_payload(decode=True),
00224            b'This is a Base64 encoded message.\n')
00225         # Subpart 5 has no Content-Transfer-Encoding: header.
00226         eq(msg.get_payload(4).get_payload(decode=True),
00227            b'This has no Content-Transfer-Encoding: header.\n')

Here is the call graph for this function:

Definition at line 228 of file test_email.py.

00228 
00229     def test_get_decoded_uu_payload(self):
00230         eq = self.assertEqual
00231         msg = Message()
00232         msg.set_payload('begin 666 -\n+:&5L;&\\@=V]R;&0 \n \nend\n')
00233         for cte in ('x-uuencode', 'uuencode', 'uue', 'x-uue'):
00234             msg['content-transfer-encoding'] = cte
00235             eq(msg.get_payload(decode=True), b'hello world')
00236         # Now try some bogus data
00237         msg.set_payload('foo')
00238         eq(msg.get_payload(decode=True), b'foo')

Here is the call graph for this function:

Definition at line 137 of file test_email.py.

00137 
00138     def test_get_filename(self):
00139         eq = self.assertEqual
00140 
00141         msg = self._msgobj('msg_04.txt')
00142         filenames = [p.get_filename() for p in msg.get_payload()]
00143         eq(filenames, ['msg.txt', 'msg.txt'])
00144 
00145         msg = self._msgobj('msg_07.txt')
00146         subpart = msg.get_payload(1)
00147         eq(subpart.get_filename(), 'dingusfish.gif')

Here is the call graph for this function:

Definition at line 148 of file test_email.py.

00148 
00149     def test_get_filename_with_name_parameter(self):
00150         eq = self.assertEqual
00151 
00152         msg = self._msgobj('msg_44.txt')
00153         filenames = [p.get_filename() for p in msg.get_payload()]
00154         eq(filenames, ['msg.txt', 'msg.txt'])

Here is the call graph for this function:

Definition at line 314 of file test_email.py.

00314 
00315     def test_get_param(self):
00316         eq = self.assertEqual
00317         msg = email.message_from_string(
00318             "X-Header: foo=one; bar=two; baz=three\n")
00319         eq(msg.get_param('bar', header='x-header'), 'two')
00320         eq(msg.get_param('quuz', header='x-header'), None)
00321         eq(msg.get_param('quuz'), None)
00322         msg = email.message_from_string(
00323             'X-Header: foo; bar="one"; baz=two\n')
00324         eq(msg.get_param('foo', header='x-header'), '')
00325         eq(msg.get_param('bar', header='x-header'), 'one')
00326         eq(msg.get_param('baz', header='x-header'), 'two')
00327         # XXX: We are not RFC-2045 compliant!  We cannot parse:
00328         # msg["Content-Type"] = 'text/plain; weird="hey; dolly? [you] @ <\\"home\\">?"'
00329         # msg.get_param("weird")
00330         # yet.

Here is the call graph for this function:

Definition at line 331 of file test_email.py.

00331 
00332     def test_get_param_funky_continuation_lines(self):
00333         msg = self._msgobj('msg_22.txt')
00334         self.assertEqual(msg.get_payload(1).get_param('name'), 'wibble.JPG')

Here is the call graph for this function:

Definition at line 309 of file test_email.py.

00309 
00310     def test_get_param_liberal(self):
00311         msg = Message()
00312         msg['Content-Type'] = 'Content-Type: Multipart/mixed; boundary = "CPIMSSMTPC06p5f3tG"'
00313         self.assertEqual(msg.get_param('boundary'), 'CPIMSSMTPC06p5f3tG')

Here is the call graph for this function:

Definition at line 342 of file test_email.py.

00342 
00343     def test_get_param_with_quotes(self):
00344         msg = email.message_from_string(
00345             'Content-Type: foo; bar*0="baz\\"foobar"; bar*1="\\"baz"')
00346         self.assertEqual(msg.get_param('bar'), 'baz"foobar"baz')
00347         msg = email.message_from_string(
00348             "Content-Type: foo; bar*0=\"baz\\\"foobar\"; bar*1=\"\\\"baz\"")
00349         self.assertEqual(msg.get_param('bar'), 'baz"foobar"baz')

Here is the call graph for this function:

Definition at line 335 of file test_email.py.

00335 
00336     def test_get_param_with_semis_in_quotes(self):
00337         msg = email.message_from_string(
00338             'Content-Type: image/pjpeg; name="Jim&amp;&amp;Jill"\n')
00339         self.assertEqual(msg.get_param('name'), 'Jim&amp;&amp;Jill')
00340         self.assertEqual(msg.get_param('name', unquote=False),
00341                          '"Jim&amp;&amp;Jill"')

Here is the call graph for this function:

Definition at line 293 of file test_email.py.

00293 
00294     def test_get_params(self):
00295         eq = self.assertEqual
00296         msg = email.message_from_string(
00297             'X-Header: foo=one; bar=two; baz=three\n')
00298         eq(msg.get_params(header='x-header'),
00299            [('foo', 'one'), ('bar', 'two'), ('baz', 'three')])
00300         msg = email.message_from_string(
00301             'X-Header: foo; bar=one; baz=two\n')
00302         eq(msg.get_params(header='x-header'),
00303            [('foo', ''), ('bar', 'one'), ('baz', 'two')])
00304         eq(msg.get_params(), None)
00305         msg = email.message_from_string(
00306             'X-Header: foo; bar="one"; baz=two\n')
00307         eq(msg.get_params(header='x-header'),
00308            [('foo', ''), ('bar', 'one'), ('baz', 'two')])

Here is the call graph for this function:

Definition at line 239 of file test_email.py.

00239 
00240     def test_get_payload_n_raises_on_non_multipart(self):
00241         msg = Message()
00242         self.assertRaises(TypeError, msg.get_payload, 1)

Here is the call graph for this function:

Definition at line 81 of file test_email.py.

00081 
00082     def test_getset_charset(self):
00083         eq = self.assertEqual
00084         msg = Message()
00085         eq(msg.get_charset(), None)
00086         charset = Charset('iso-8859-1')
00087         msg.set_charset(charset)
00088         eq(msg['mime-version'], '1.0')
00089         eq(msg.get_content_type(), 'text/plain')
00090         eq(msg['content-type'], 'text/plain; charset="iso-8859-1"')
00091         eq(msg.get_param('charset'), 'iso-8859-1')
00092         eq(msg['content-transfer-encoding'], 'quoted-printable')
00093         eq(msg.get_charset().input_charset, 'iso-8859-1')
00094         # Remove the charset
00095         msg.set_charset(None)
00096         eq(msg.get_charset(), None)
00097         eq(msg['content-type'], 'text/plain')
00098         # Try adding a charset when there's already MIME headers present
00099         msg = Message()
00100         msg['MIME-Version'] = '2.0'
00101         msg['Content-Type'] = 'text/x-weird'
00102         msg['Content-Transfer-Encoding'] = 'quinted-puntable'
00103         msg.set_charset(charset)
00104         eq(msg['mime-version'], '2.0')
00105         eq(msg['content-type'], 'text/x-weird; charset="iso-8859-1"')
00106         eq(msg['content-transfer-encoding'], 'quinted-puntable')

Here is the call graph for this function:

Definition at line 183 of file test_email.py.

00183 
00184     def test_make_boundary(self):
00185         msg = MIMEMultipart('form-data')
00186         # Note that when the boundary gets created is an implementation
00187         # detail and might change.
00188         self.assertEqual(msg.items()[0][1], 'multipart/form-data')
00189         # Trigger creation of boundary
00190         msg.as_string()
00191         self.assertEqual(msg.items()[0][1][:33],
00192                         'multipart/form-data; boundary="==')
00193         # XXX: there ought to be tests of the uniqueness of the boundary, too.

Here is the call graph for this function:

Definition at line 194 of file test_email.py.

00194 
00195     def test_message_rfc822_only(self):
00196         # Issue 7970: message/rfc822 not in multipart parsed by
00197         # HeaderParser caused an exception when flattened.
00198         with openfile(findfile('msg_46.txt')) as fp:
00199             msgdata = fp.read()
00200         parser = HeaderParser()
00201         msg = parser.parsestr(msgdata)
00202         out = StringIO()
00203         gen = Generator(out, True, 0)
00204         gen.flatten(msg, False)
00205         self.assertEqual(out.getvalue(), msgdata)

Here is the call graph for this function:

Definition at line 289 of file test_email.py.

00289 
00290     def test_missing_boundary(self):
00291         msg = email.message_from_string("From: foo\n")
00292         self.assertEqual(msg.get_boundary(), None)

Here is the call graph for this function:

Definition at line 280 of file test_email.py.

00280 
00281     def test_missing_filename(self):
00282         msg = email.message_from_string("From: foo\n")
00283         self.assertEqual(msg.get_filename(), None)

Here is the call graph for this function:

Definition at line 568 of file test_email.py.

00568 
00569     def test_noascii_add_header(self):
00570         msg = Message()
00571         msg.add_header('Content-Disposition', 'attachment',
00572             filename="Fußballer.ppt")
00573         self.assertEqual(
00574             'attachment; filename*=utf-8\'\'Fu%C3%9Fballer.ppt',
00575             msg['Content-Disposition'])

Here is the call graph for this function:

Definition at line 576 of file test_email.py.

00576 
00577     def test_nonascii_add_header_via_triple(self):
00578         msg = Message()
00579         msg.add_header('Content-Disposition', 'attachment',
00580             filename=('iso-8859-1', '', 'Fußballer.ppt'))
00581         self.assertEqual(
00582             'attachment; filename*=iso-8859-1\'\'Fu%DFballer.ppt',
00583             msg['Content-Disposition'])

Here is the call graph for this function:

Definition at line 592 of file test_email.py.

00592 
00593     def test_nonascii_add_header_with_tspecial(self):
00594         msg = Message()
00595         msg.add_header('Content-Disposition', 'attachment',
00596             filename="Fußballer [filename].ppt")
00597         self.assertEqual(
00598             "attachment; filename*=utf-8''Fu%C3%9Fballer%20%5Bfilename%5D.ppt",
00599             msg['Content-Disposition'])

Here is the call graph for this function:

Definition at line 550 of file test_email.py.

00550 
00551     def test_questionable_bytes_payload(self):
00552         # This test improves coverage but is not a compliance test,
00553         # since it involves poking inside the black box.
00554         x = 'this is a quéstionable thing to do'.encode('utf-8')
00555         msg = Message()
00556         msg['content-type'] = 'text/plain; charset="utf-8"'
00557         msg['content-transfer-encoding'] = '8bit'
00558         msg._payload = x
00559         self.assertEqual(msg.get_payload(decode=True), x)

Here is the call graph for this function:

Definition at line 513 of file test_email.py.

00513 
00514     def test_replace_header(self):
00515         eq = self.assertEqual
00516         msg = Message()
00517         msg.add_header('First', 'One')
00518         msg.add_header('Second', 'Two')
00519         msg.add_header('Third', 'Three')
00520         eq(msg.keys(), ['First', 'Second', 'Third'])
00521         eq(msg.values(), ['One', 'Two', 'Three'])
00522         msg.replace_header('Second', 'Twenty')
00523         eq(msg.keys(), ['First', 'Second', 'Third'])
00524         eq(msg.values(), ['One', 'Twenty', 'Three'])
00525         msg.add_header('First', 'Eleven')
00526         msg.replace_header('First', 'One Hundred')
00527         eq(msg.keys(), ['First', 'Second', 'Third', 'First'])
00528         eq(msg.values(), ['One Hundred', 'Twenty', 'Three', 'Eleven'])
00529         self.assertRaises(KeyError, msg.replace_header, 'Fourth', 'Missing')

Here is the call graph for this function:

Definition at line 161 of file test_email.py.

00161 
00162     def test_set_boundary(self):
00163         eq = self.assertEqual
00164         # This one has no existing boundary parameter, but the Content-Type:
00165         # header appears fifth.
00166         msg = self._msgobj('msg_01.txt')
00167         msg.set_boundary('BOUNDARY')
00168         header, value = msg.items()[4]
00169         eq(header.lower(), 'content-type')
00170         eq(value, 'text/plain; charset="us-ascii"; boundary="BOUNDARY"')
00171         # This one has a Content-Type: header, with a boundary, stuck in the
00172         # middle of its headers.  Make sure the order is preserved; it should
00173         # be fifth.
00174         msg = self._msgobj('msg_04.txt')
00175         msg.set_boundary('BOUNDARY')
00176         header, value = msg.items()[4]
00177         eq(header.lower(), 'content-type')
00178         eq(value, 'multipart/mixed; boundary="BOUNDARY"')
00179         # And this one has no Content-Type: header at all.
00180         msg = self._msgobj('msg_03.txt')
00181         self.assertRaises(errors.HeaderParseError,
00182                           msg.set_boundary, 'BOUNDARY')

Here is the call graph for this function:

Definition at line 107 of file test_email.py.

00107 
00108     def test_set_charset_from_string(self):
00109         eq = self.assertEqual
00110         msg = Message()
00111         msg.set_charset('us-ascii')
00112         eq(msg.get_charset().input_charset, 'us-ascii')
00113         eq(msg['content-type'], 'text/plain; charset="us-ascii"')

Here is the call graph for this function:

Definition at line 358 of file test_email.py.

00358 
00359     def test_set_param(self):
00360         eq = self.assertEqual
00361         msg = Message()
00362         msg.set_param('charset', 'iso-2022-jp')
00363         eq(msg.get_param('charset'), 'iso-2022-jp')
00364         msg.set_param('importance', 'high value')
00365         eq(msg.get_param('importance'), 'high value')
00366         eq(msg.get_param('importance', unquote=False), '"high value"')
00367         eq(msg.get_params(), [('text/plain', ''),
00368                               ('charset', 'iso-2022-jp'),
00369                               ('importance', 'high value')])
00370         eq(msg.get_params(unquote=False), [('text/plain', ''),
00371                                        ('charset', '"iso-2022-jp"'),
00372                                        ('importance', '"high value"')])
00373         msg.set_param('charset', 'iso-9999-xx', header='X-Jimmy')
00374         eq(msg.get_param('charset', header='X-Jimmy'), 'iso-9999-xx')

Here is the call graph for this function:

Definition at line 114 of file test_email.py.

00114 
00115     def test_set_payload_with_charset(self):
00116         msg = Message()
00117         charset = Charset('iso-8859-1')
00118         msg.set_payload('This is a string payload', charset)
00119         self.assertEqual(msg.get_charset().input_charset, 'iso-8859-1')

Here is the call graph for this function:

Definition at line 409 of file test_email.py.

00409 
00410     def test_set_type(self):
00411         eq = self.assertEqual
00412         msg = Message()
00413         self.assertRaises(ValueError, msg.set_type, 'text')
00414         msg.set_type('text/plain')
00415         eq(msg['content-type'], 'text/plain')
00416         msg.set_param('charset', 'us-ascii')
00417         eq(msg['content-type'], 'text/plain; charset="us-ascii"')
00418         msg.set_type('text/html')
00419         eq(msg['content-type'], 'text/html; charset="us-ascii"')

Here is the call graph for this function:

Definition at line 420 of file test_email.py.

00420 
00421     def test_set_type_on_other_header(self):
00422         msg = Message()
00423         msg['X-Content-Type'] = 'text/plain'
00424         msg.set_type('application/octet-stream', 'X-Content-Type')
00425         self.assertEqual(msg['x-content-type'], 'application/octet-stream')

Here is the call graph for this function:


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