-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Amazon SES: Fix header encoding problem
A combination of long display name and commas (or other special characters) could result in invalid address headers. See details in #369. Fix by removing unnecessary email.policy override, which was causing new header folding code to run with headers built using Compat32 legacy header encoding. The two don't mix. Fixes #369
- Loading branch information
Showing
3 changed files
with
40 additions
and
9 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
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 |
---|---|---|
|
@@ -318,6 +318,17 @@ def test_commas_in_subject(self): | |
sent_message = self.get_sent_message() | ||
self.assertEqual(sent_message["Subject"], self.message.subject) | ||
|
||
def test_broken_address_header(self): | ||
# https://github.com/anymail/django-anymail/issues/369 | ||
self.message.to = ['"Người nhận a very very long, name" <[email protected]>'] | ||
self.message.cc = [ | ||
'"A véry long name with non-ASCII char and, comma" <[email protected]>' | ||
] | ||
self.message.send() | ||
sent_message = self.get_sent_message() | ||
self.assertEqual(sent_message["To"], self.message.to[0]) | ||
self.assertEqual(sent_message["Cc"], self.message.cc[0]) | ||
|
||
def test_no_cte_8bit(self): | ||
"""Anymail works around an Amazon SES bug that can corrupt non-ASCII bodies.""" | ||
# (see detailed comments in the backend code) | ||
|
@@ -333,12 +344,14 @@ def test_no_cte_8bit(self): | |
self.message.attach(att) | ||
|
||
self.message.send() | ||
sent_message = self.get_sent_message() | ||
raw_mime = self.get_send_params()["Content"]["Raw"]["Data"] | ||
self.assertTrue(raw_mime.isascii()) # 7-bit clean | ||
|
||
# Make sure none of the resulting parts use `Content-Transfer-Encoding: 8bit`. | ||
# (Technically, either quoted-printable or base64 would be OK, but base64 text | ||
# parts have a reputation for triggering spam filters, so just require | ||
# quoted-printable for them.) | ||
sent_message = self.get_sent_message() | ||
part_encodings = [ | ||
(part.get_content_type(), part["Content-Transfer-Encoding"]) | ||
for part in sent_message.walk() | ||
|
@@ -355,6 +368,21 @@ def test_no_cte_8bit(self): | |
], | ||
) | ||
|
||
def test_no_cte_8bit_root(self): | ||
# Same test as above, but with a non-multipart message using 8bit at root | ||
self.message.body = "Это text body" | ||
self.message.send() | ||
|
||
raw_mime = self.get_send_params()["Content"]["Raw"]["Data"] | ||
self.assertTrue(raw_mime.isascii()) # 7-bit clean | ||
|
||
sent_message = self.get_sent_message() | ||
part_encodings = [ | ||
(part.get_content_type(), part["Content-Transfer-Encoding"]) | ||
for part in sent_message.walk() | ||
] | ||
self.assertEqual(part_encodings, [("text/plain", "quoted-printable")]) | ||
|
||
def test_api_failure(self): | ||
error_response = { | ||
"Error": { | ||
|