示例#1
0
    def test_message_with_invalid_content_for_declared_encoding(self):
        """ Ensure that we gracefully handle mis-encoded bodies.

        Should a payload body be misencoded, we should:

        - Not explode

        Note: there is (intentionally) no assertion below; the only guarantee
        we make via this library is that processing this e-mail message will
        not cause an exception to be raised.

        """
        email_object = self._get_email_object(
            'message_with_invalid_content_for_declared_encoding.eml',
        )
        default_settings = get_config()

        with mock.patch('django_mail_admin.settings.get_config') as get_settings:
            altered = copy.deepcopy(default_settings)
            altered['STORE_ORIGINAL_MESSAGE'] = False
            get_settings.return_value = altered

            msg = self.mailbox.process_incoming_message(email_object)

        msg.text
示例#2
0
    def test_message_saving_ignored(self):
        message = self._get_email_object('generic_message.eml')

        default_settings = get_config()

        with mock.patch('django_mail_admin.settings.get_config') as get_settings:
            altered = copy.deepcopy(default_settings)
            altered['STORE_ORIGINAL_MESSAGE'] = False
            get_settings.return_value = altered

            msg = self.mailbox.process_incoming_message(message)

        self.assertEquals(msg.eml, None)
    def test_message_content_type_stripping(self):
        incoming_email_object = self._get_email_object(
            'message_with_many_multiparts.eml', )
        expected_email_object = self._get_email_object(
            'message_with_many_multiparts_stripped_html.eml', )
        default_settings = get_config()
        with mock.patch(
                'django_mail_admin.settings.get_config') as get_settings:
            altered = copy.deepcopy(default_settings)

            altered['STRIP_UNALLOWED_MIMETYPES'] = True
            altered['ALLOWED_MIMETYPES'] = ['text/plain']
            get_settings.return_value = altered

            msg = self.mailbox.process_incoming_message(incoming_email_object)

        actual_email_object = msg.get_email_object()
示例#4
0
    def test_message_compressed(self):
        message = self._get_email_object('generic_message.eml')

        default_settings = get_config()

        with mock.patch('django_mail_admin.settings.get_config') as get_settings:
            altered = copy.deepcopy(default_settings)

            altered['COMPRESS_ORIGINAL_MESSAGE'] = True
            altered['STORE_ORIGINAL_MESSAGE'] = True
            get_settings.return_value = altered

            msg = self.mailbox.process_incoming_message(message)

        actual_email_object = msg.get_email_object()

        self.assertTrue(msg.eml.name.endswith('.eml.gz'))

        with gzip.open(msg.eml.name, 'rb') as f:
            self.assertEqual(f.read(),
                             self._get_email_as_text('generic_message.eml'))