-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Perform unfolding of headers when parsing message (#71)
* ✅ [#70] Test newlines not being added to subject * ✨ [#70] Add the email.policy.EmailPolicy https://docs.python.org/3/library/email.policy.html#email.policy.EmailPolicy This results in the unfolding of headers that have previously been folded, so that new lines don't cause errors.
- Loading branch information
1 parent
b9523a8
commit 27a5ae8
Showing
2 changed files
with
29 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
from email.generator import _fmt | ||
from unittest.mock import patch | ||
|
||
from django.core.mail import EmailMultiAlternatives | ||
from django.core.mail import EmailMessage, EmailMultiAlternatives | ||
from django.test import TestCase | ||
from django.utils import timezone | ||
|
||
|
@@ -200,3 +200,26 @@ def reset_mock(): | |
with self.subTest("compare message as_string"): | ||
self.assertEqual(reconstructed_msg.as_string(), ref_as_string) | ||
reset_mock() | ||
|
||
def test_email_with_long_subject(self): | ||
email_message = EmailMessage( | ||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor " | ||
"incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco " | ||
"laboris nisi ut aliquip ex ea commodo consequat.", | ||
"Message body", | ||
'[email protected]', | ||
['[email protected]'] | ||
) | ||
|
||
message = Message.objects.create( | ||
to_address=','.join(email_message.to), | ||
cc_address=','.join(email_message.cc), | ||
bcc_address=','.join(email_message.bcc), | ||
from_address=email_message.from_email, | ||
subject=email_message.subject, | ||
message_data=email_message.message().as_string(), | ||
) | ||
|
||
parsed_message = message.get_email_message() | ||
|
||
self.assertNotIn("\n", parsed_message.subject) |