From 247d2fcae18f7c75e15e24ba53ca1027f69a273b Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Sat, 25 Jan 2025 21:10:08 -0800 Subject: [PATCH] Setting for .eml files consumed outside of mail fetch --- docs/configuration.md | 12 ++++++++++++ src/paperless/settings.py | 5 +++++ src/paperless_mail/parsers.py | 6 +++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/docs/configuration.md b/docs/configuration.md index 799620c05..a46b20c88 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -198,6 +198,18 @@ Docker, this may be the `environment` key of the webserver or a containing the configuration parameters. Be sure to use the correct format and watch out for indentation if editing the YAML file. +### Email Parsing + +#### [`PAPERLESS_EMAIL_PARSE_DEFAULT_LAYOUT=`(#PAPERLESS_EMAIL_PARSE_DEFAULT_LAYOUT) {#PAPERLESS_EMAIL_PARSE_DEFAULT_LAYOUT} + +: The default layout to use for emails that are consumed as documents. Must be one of the integer choices below. Note that mail +rules can specify this setting, thus this fallback is used for .eml files consumed by other means. + + - `1` = Text, then HTML + - `2` = HTML, then text + - `3` = HTML only + - `4` = Text only + ## Paths and folders #### [`PAPERLESS_CONSUMPTION_DIR=`](#PAPERLESS_CONSUMPTION_DIR) {#PAPERLESS_CONSUMPTION_DIR} diff --git a/src/paperless/settings.py b/src/paperless/settings.py index a817abd70..846b9e0ee 100644 --- a/src/paperless/settings.py +++ b/src/paperless/settings.py @@ -1030,6 +1030,11 @@ CONVERT_MEMORY_LIMIT = os.getenv("PAPERLESS_CONVERT_MEMORY_LIMIT") GS_BINARY = os.getenv("PAPERLESS_GS_BINARY", "gs") +# Fallback layout for .eml consumption +EMAIL_PARSE_DEFAULT_LAYOUT = __get_int( + "PAPERLESS_EMAIL_PARSE_DEFAULT_LAYOUT", + 1, # MailRule.PdfLayout.TEXT_HTML but that can't be imported here +) # Pre-2.x versions of Paperless stored your documents locally with GPG # encryption, but that is no longer the default. This behaviour is still diff --git a/src/paperless_mail/parsers.py b/src/paperless_mail/parsers.py index 682f8285c..5c2622a52 100644 --- a/src/paperless_mail/parsers.py +++ b/src/paperless_mail/parsers.py @@ -231,12 +231,16 @@ class MailDocumentParser(DocumentParser): def generate_pdf( self, mail_message: MailMessage, - pdf_layout: MailRule.PdfLayout = MailRule.PdfLayout.TEXT_HTML, + pdf_layout: MailRule.PdfLayout | None = None, ) -> Path: archive_path = Path(self.tempdir) / "merged.pdf" mail_pdf_file = self.generate_pdf_from_mail(mail_message) + pdf_layout = ( + pdf_layout or settings.EMAIL_PARSE_DEFAULT_LAYOUT + ) # EMAIL_PARSE_DEFAULT_LAYOUT is a MailRule.PdfLayout + # If no HTML content, create the PDF from the message # Otherwise, create 2 PDFs and merge them with Gotenberg if not mail_message.html: