Setting for .eml files consumed outside of mail fetch

This commit is contained in:
shamoon 2025-01-25 21:10:08 -08:00
parent 1ac4dfce7e
commit 247d2fcae1
3 changed files with 22 additions and 1 deletions

View File

@ -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 containing the configuration parameters. Be sure to use the correct format
and watch out for indentation if editing the YAML file. and watch out for indentation if editing the YAML file.
### Email Parsing
#### [`PAPERLESS_EMAIL_PARSE_DEFAULT_LAYOUT=<int>`(#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 ## Paths and folders
#### [`PAPERLESS_CONSUMPTION_DIR=<path>`](#PAPERLESS_CONSUMPTION_DIR) {#PAPERLESS_CONSUMPTION_DIR} #### [`PAPERLESS_CONSUMPTION_DIR=<path>`](#PAPERLESS_CONSUMPTION_DIR) {#PAPERLESS_CONSUMPTION_DIR}

View File

@ -1030,6 +1030,11 @@ CONVERT_MEMORY_LIMIT = os.getenv("PAPERLESS_CONVERT_MEMORY_LIMIT")
GS_BINARY = os.getenv("PAPERLESS_GS_BINARY", "gs") 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 # Pre-2.x versions of Paperless stored your documents locally with GPG
# encryption, but that is no longer the default. This behaviour is still # encryption, but that is no longer the default. This behaviour is still

View File

@ -231,12 +231,16 @@ class MailDocumentParser(DocumentParser):
def generate_pdf( def generate_pdf(
self, self,
mail_message: MailMessage, mail_message: MailMessage,
pdf_layout: MailRule.PdfLayout = MailRule.PdfLayout.TEXT_HTML, pdf_layout: MailRule.PdfLayout | None = None,
) -> Path: ) -> Path:
archive_path = Path(self.tempdir) / "merged.pdf" archive_path = Path(self.tempdir) / "merged.pdf"
mail_pdf_file = self.generate_pdf_from_mail(mail_message) 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 # If no HTML content, create the PDF from the message
# Otherwise, create 2 PDFs and merge them with Gotenberg # Otherwise, create 2 PDFs and merge them with Gotenberg
if not mail_message.html: if not mail_message.html: