Skip to content

A community-supported supercharged document management system: scan, index and archive all your documents

Fix: handle hidden line breaks in email subjects when sending email (#13402)

shamoon5bd72014a68e
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],
- "subject": "Bulk email test",
+ "subject": "Bulk email\n test",
"message": "Here are your documents",
},
),