Beispiel #1
0
 def test_msg_rfc822(self):
     with resource_open('mailman.handlers.tests.data',
                        'msg_rfc822.eml') as fp:
         msg = email.message_from_binary_file(fp)
     process = config.handlers['mime-delete'].process
     # Mock this so that the X-Content-Filtered-By header isn't sensitive to
     # Mailman version bumps.
     with patch('mailman.handlers.mime_delete.VERSION', '123'):
         expected_msg = read_text('mailman.handlers.tests.data',
                                  'msg_rfc822_out.eml')
         process(self._mlist, msg, {})
         self.assertEqual(msg.as_string(), expected_msg)
Beispiel #2
0
 def test_html_part_with_non_ascii(self):
     # Ensure we can convert HTML to plain text in an HTML sub-part which
     # contains non-ascii.
     with resource_open('mailman.handlers.tests.data',
                        'html_to_plain.eml') as fp:
         msg = email.message_from_binary_file(fp)
     process = config.handlers['mime-delete'].process
     with dummy_script():
         process(self._mlist, msg, {})
     part = msg.get_payload(1)
     cset = part.get_content_charset('us-ascii')
     text = part.get_payload(decode=True).decode(cset).splitlines()
     self.assertEqual(text[0], 'Converted text/html to text/plain')
     self.assertEqual(text[2], 'Um frühere Nachrichten')
Beispiel #3
0
 def test_collapse_alternatives_non_ascii(self):
     # Ensure we can flatten as bytes a message whose non-ascii payload
     # has been reset.
     with resource_open('mailman.handlers.tests.data',
                        'c_a_non_ascii.eml') as fp:
         msg = email.message_from_binary_file(fp)
     process = config.handlers['mime-delete'].process
     process(self._mlist, msg, {})
     self.assertFalse(msg.is_multipart())
     self.assertEqual(
         msg.get_payload(decode=True),
         b'Body with non-ascii can\xe2\x80\x99t see '
         b'won\xe2\x80\x99t know\n')
     # Ensure we can flatten it.
     dummy = msg.as_bytes()  # noqa: F841
Beispiel #4
0
    def test_collapse_alternatives(self):
        with resource_open('mailman.handlers.tests.data',
                           'collapse_alternatives.eml') as fp:
            msg = email.message_from_binary_file(fp)
        process = config.handlers['mime-delete'].process
        process(self._mlist, msg, {})
        structure = StringIO()
        email.iterators._structure(msg, fp=structure)
        self.assertEqual(
            structure.getvalue(), """\
multipart/signed
    multipart/mixed
        text/plain
        text/plain
    application/pgp-signature
""")