From ebe21a01140aa5d492c34fc88be63cdfcc57b025 Mon Sep 17 00:00:00 2001 From: phail Date: Sun, 20 Nov 2022 14:22:30 +0100 Subject: [PATCH] eml parsing requires tika --- src/paperless_mail/apps.py | 4 +++- src/paperless_mail/parsers.py | 13 ++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/paperless_mail/apps.py b/src/paperless_mail/apps.py index fa6b1a267..719400e76 100644 --- a/src/paperless_mail/apps.py +++ b/src/paperless_mail/apps.py @@ -1,4 +1,5 @@ from django.apps import AppConfig +from django.conf import settings from django.utils.translation import gettext_lazy as _ from paperless_mail.signals import mail_consumer_declaration @@ -11,5 +12,6 @@ class PaperlessMailConfig(AppConfig): def ready(self): from documents.signals import document_consumer_declaration - document_consumer_declaration.connect(mail_consumer_declaration) + if settings.TIKA_ENABLED: + document_consumer_declaration.connect(mail_consumer_declaration) AppConfig.ready(self) diff --git a/src/paperless_mail/parsers.py b/src/paperless_mail/parsers.py index 902619fd7..b325b79d5 100644 --- a/src/paperless_mail/parsers.py +++ b/src/paperless_mail/parsers.py @@ -159,7 +159,12 @@ class MailDocumentParser(DocumentParser): pdf_collection.append(("1_mail.pdf", self.generate_pdf_from_mail(mail))) - if mail.html != "": + if mail.html == "": + with open(pdf_path, "wb") as file: + file.write(pdf_collection[0][1]) + file.close() + return pdf_path + else: pdf_collection.append( ( "2_html.pdf", @@ -167,12 +172,6 @@ class MailDocumentParser(DocumentParser): ), ) - if len(pdf_collection) == 1: - with open(pdf_path, "wb") as file: - file.write(pdf_collection[0][1]) - file.close() - return pdf_path - files = {} for name, content in pdf_collection: files[name] = (name, BytesIO(content))