-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Postmark inbound: Fix ValueError with long, non-ASCII name
Receiving a Postmark inbound message with a long From or recipient Name field could result in "ValueError: Header values may not contain linefeed or carriage return characters" if the name included non-ASCII characters. Anymail's EmailAddress calls Django's sanitize_address(), which can introduce folding whitespace, causing an error in the AnymailInboundMessage constructor. Only Postmark inbound is affected, as no other webhooks construct an EmailAddress. (Longer-term, Anymail should stop using the undocumented Django sanitize_address.)
- Loading branch information
Showing
3 changed files
with
37 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -392,3 +392,32 @@ def test_check_payload(self): | |
) | ||
# Don't care about the actual test message contents here, | ||
# just want to make sure it parses and signals inbound without error. | ||
|
||
def test_spammy_address(self): | ||
# This long FromFull.Name caused an error in AnymailInboundMessage construction, | ||
# due to folding introduced in EmailAddress.formataddr() | ||
from_name = ( | ||
"* * * 💲 Snag Your Free Gift! Click Here: " | ||
"https://spam.example.com/uploads/phish.php?123456 💲 * * *" | ||
) | ||
raw_event = { | ||
"MessageStream": "inbound", | ||
"FromFull": { | ||
"Email": "[email protected]", | ||
"Name": from_name, | ||
}, | ||
} | ||
response = self.client.post( | ||
"/anymail/postmark/inbound/", | ||
content_type="application/json", | ||
data=json.dumps(raw_event), | ||
) | ||
self.assertEqual(response.status_code, 200) | ||
kwargs = self.assert_handler_called_once_with( | ||
self.inbound_handler, | ||
sender=PostmarkInboundWebhookView, | ||
event=ANY, | ||
esp_name="Postmark", | ||
) | ||
message = kwargs["event"].message | ||
self.assertEqual(message.from_email.display_name, from_name) |