From eeeb246ed7115c2a99de7972047bd1fa4d313c39 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Sun, 7 Oct 2018 04:25:58 -0400 Subject: [PATCH] Restore use of the .store_body variable accidentally remove in 63a77d0235ffef3cd49924ba280879313c622682. Thanks to TheOneValen @TheOneValen for the report. Signed-off-by: Roberto Rosario --- mayan/apps/sources/models.py | 25 +++++++++++++------------ mayan/apps/sources/tests/test_models.py | 22 ++++++++++++++++++++++ 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/mayan/apps/sources/models.py b/mayan/apps/sources/models.py index 16d42d43db..2c60648d32 100644 --- a/mayan/apps/sources/models.py +++ b/mayan/apps/sources/models.py @@ -632,18 +632,19 @@ class EmailBaseModel(IntervalBaseModel): else: label = 'email_body.txt' - with ContentFile(content=message.body, name=label) as file_object: - documents = source.handle_upload( - document_type=source.document_type, - file_object=file_object, - expand=SOURCE_UNCOMPRESS_CHOICE_N - ) - if metadata_dictionary: - for document in documents: - set_bulk_metadata( - document=document, - metadata_dictionary=metadata_dictionary - ) + if source.store_body: + with ContentFile(content=message.body, name=label) as file_object: + documents = source.handle_upload( + document_type=source.document_type, + file_object=file_object, + expand=SOURCE_UNCOMPRESS_CHOICE_N + ) + if metadata_dictionary: + for document in documents: + set_bulk_metadata( + document=document, + metadata_dictionary=metadata_dictionary + ) class IMAPEmail(EmailBaseModel): diff --git a/mayan/apps/sources/tests/test_models.py b/mayan/apps/sources/tests/test_models.py index 1460afeb80..351abc5c2e 100644 --- a/mayan/apps/sources/tests/test_models.py +++ b/mayan/apps/sources/tests/test_models.py @@ -160,6 +160,28 @@ class EmailFilenameDecodingTestCase(BaseTestCase): TEST_EMAIL_BASE64_FILENAME_SUBJECT ) + def test_document_upload_no_body(self): + self._create_email_source() + self.source.store_body = False + self.source.save() + + EmailBaseModel.process_message( + source=self.source, message_text=TEST_EMAIL_ATTACHMENT_AND_INLINE + ) + + # Only two attachments, no body document + self.assertEqual(2, Document.objects.count()) + + def test_document_upload_with_body(self): + self._create_email_source() + + EmailBaseModel.process_message( + source=self.source, message_text=TEST_EMAIL_ATTACHMENT_AND_INLINE + ) + + # Only two attachments and a body document + self.assertEqual(3, Document.objects.count()) + @override_settings(OCR_AUTO_OCR=False) class POP3SourceTestCase(BaseTestCase):