1
0
Fork 1
mirror of https://github.com/coddingtonbear/django-mailbox.git synced 2026-07-09 22:38:19 +02:00

Adding tests and minor code changes to ensure that we properly handle the distinction between bytes and text when dehydrating/rehydrating messages.

This commit is contained in:
Adam Coddington 2013-07-26 19:13:35 -07:00
parent 3ee4b43936
commit adb17e7d67
5 changed files with 109 additions and 24 deletions

View file

@ -131,3 +131,61 @@ class TestProcessEmail(EmailMessageTestCase):
expected_text,
actual_text,
)
def test_message_with_unknown_charset(self):
""" Ensure that we gracefully fail at handling unknown encodings.
Should an unknown encoding be used, we should:
- Add a X-Django-Mailbox-Altered-Message header
- Use UTF-8 (with replacement) as the de-facto (and probably incorrect)
encoding for this payload part.
"""
email_object = self._get_email_object(
'message_with_invalid_payload_encoding.eml'
)
msg = self.mailbox.process_incoming_message(email_object)
actual_body = msg.get_text_body()
expected_body = (
u'\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd '
u'\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd'
u'\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd '
u'\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd '
u'\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd'
u'\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd '
u'\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd'
u'\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd.'
)
self.assertEqual(
expected_body,
actual_body,
)
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:
- Decode the message (with replacement) using the declared encoding.
- Always return a payload body in the declared encoding, using python's
usual replacement mechanisms.
"""
email_object = self._get_email_object(
'message_with_invalid_content_for_declared_encoding.eml',
)
msg = self.mailbox.process_incoming_message(email_object)
actual_body = msg.get_text_body()
expected_body = '??? ????????? ????? ???????????? ?????????.'
self.assertEqual(
actual_body,
expected_body,
)