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", }, ),