From a673b17fb3fa41fe168d940d87e25849934d5ffe Mon Sep 17 00:00:00 2001 From: Adam Dobrawy Date: Wed, 7 Feb 2018 21:19:23 +0100 Subject: [PATCH] Fix parsing text message with text attachment --- django_mailbox/tests/test_process_email.py | 2 +- django_mailbox/utils.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/django_mailbox/tests/test_process_email.py b/django_mailbox/tests/test_process_email.py index b72e8c0..831eeaf 100644 --- a/django_mailbox/tests/test_process_email.py +++ b/django_mailbox/tests/test_process_email.py @@ -401,7 +401,7 @@ class TestProcessEmail(EmailMessageTestCase): msg = self.mailbox.process_incoming_message(email_object) self.assertEqual(msg.attachments.all().count(), 1) - self.assertNotIn('This is an attachment.', msg.text) + self.assertEqual('Has an attached text document, too!', msg.text) def test_message_with_long_content(self): email_object = self._get_email_object( diff --git a/django_mailbox/utils.py b/django_mailbox/utils.py index f33f3bb..48e76be 100644 --- a/django_mailbox/utils.py +++ b/django_mailbox/utils.py @@ -108,6 +108,8 @@ def get_body_from_message(message, maintype, subtype): """ body = six.text_type('') for part in message.walk(): + if part.get('content-disposition', '').startswith('attachment;'): + continue if part.get_content_maintype() == maintype and \ part.get_content_subtype() == subtype: charset = part.get_content_charset()