1
0
Fork 0

Fix text content with text attachment (#170)

* Add tests case for text content with text attachment

* Fix parsing text message with text attachment
This commit is contained in:
Adam Dobrawy 2018-02-09 09:13:39 +01:00 committed by Adam Coddington
parent dfad0f8f9c
commit 7eecb0d41d
2 changed files with 4 additions and 1 deletions

View file

@ -401,6 +401,7 @@ class TestProcessEmail(EmailMessageTestCase):
msg = self.mailbox.process_incoming_message(email_object) msg = self.mailbox.process_incoming_message(email_object)
self.assertEqual(msg.attachments.all().count(), 1) self.assertEqual(msg.attachments.all().count(), 1)
self.assertEqual('Has an attached text document, too!', msg.text)
def test_message_with_long_content(self): def test_message_with_long_content(self):
email_object = self._get_email_object( email_object = self._get_email_object(
@ -468,4 +469,4 @@ class TestProcessEmail(EmailMessageTestCase):
with gzip.open(msg.eml.name, 'rb') as f: with gzip.open(msg.eml.name, 'rb') as f:
self.assertEqual(f.read(), self.assertEqual(f.read(),
self._get_email_as_text('generic_message.eml')) self._get_email_as_text('generic_message.eml'))

View file

@ -108,6 +108,8 @@ def get_body_from_message(message, maintype, subtype):
""" """
body = six.text_type('') body = six.text_type('')
for part in message.walk(): for part in message.walk():
if part.get('content-disposition', '').startswith('attachment;'):
continue
if part.get_content_maintype() == maintype and \ if part.get_content_maintype() == maintype and \
part.get_content_subtype() == subtype: part.get_content_subtype() == subtype:
charset = part.get_content_charset() charset = part.get_content_charset()