From 5bd72014a68e16023d5ccc83569ac2b0dca74e5c Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Wed, 29 Jul 2026 07:35:30 -0700 Subject: [PATCH] Fix: handle hidden line breaks in email subjects when sending email (#13402) --- src/documents/mail.py | 3 +++ src/documents/tests/test_api_email.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/documents/mail.py b/src/documents/mail.py index 21bf03c7a..e9c4cf6ad 100644 --- a/src/documents/mail.py +++ b/src/documents/mail.py @@ -36,6 +36,9 @@ def send_email( TODO: re-evaluate this pending https://code.djangoproject.com/ticket/35581 / https://github.com/django/django/pull/18966 """ + if "\r" in subject or "\n" in subject: + subject = " ".join(line.strip(" \t") for line in subject.splitlines()) + email = EmailMessage( subject=subject, body=body, diff --git a/src/documents/tests/test_api_email.py b/src/documents/tests/test_api_email.py index f6f30a226..90a629e1a 100644 --- a/src/documents/tests/test_api_email.py +++ b/src/documents/tests/test_api_email.py @@ -75,7 +75,7 @@ class TestEmail(DirectoriesMixin, SampleDirMixin, APITestCase): { "documents": [self.doc1.pk, self.doc2.pk], "addresses": "hello@paperless-ngx.com,test@example.com", - "subject": "Bulk email test", + "subject": "Bulk email\n test", "message": "Here are your documents", }, ),