Skip to content

Commit df82b8c

Browse files
committed
Normalize email data subject before sending
1 parent a5f1dc6 commit df82b8c

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

Diff for: h/services/email.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ def message(self) -> pyramid_mailer.message.Message:
3434
extra_headers = {"X-MC-Tags": self.tag}
3535
if self.subaccount:
3636
extra_headers["X-MC-Subaccount"] = self.subaccount
37+
subject = " ".join(self.subject.splitlines())
3738
return pyramid_mailer.message.Message(
38-
subject=self.subject,
39+
subject=subject,
3940
recipients=self.recipients,
4041
body=self.body,
4142
html=self.html,

Diff for: tests/unit/h/services/email_test.py

+19
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,25 @@ def test_send_creates_email_message_with_subaccount(
6969
extra_headers={"X-MC-Tags": EmailTag.TEST, "X-MC-Subaccount": "subaccount"},
7070
)
7171

72+
def test_send_creates_email_message_normalizing_subject(
73+
self, task_data, email_service, pyramid_mailer
74+
):
75+
email = EmailData(
76+
recipients=["[email protected]"],
77+
subject="My email\r\nsubject",
78+
body="Some text body",
79+
tag=EmailTag.TEST,
80+
)
81+
email_service.send(email, task_data)
82+
83+
pyramid_mailer.message.Message.assert_called_once_with(
84+
recipients=["[email protected]"],
85+
subject="My email subject",
86+
body="Some text body",
87+
html=None,
88+
extra_headers={"X-MC-Tags": EmailTag.TEST},
89+
)
90+
7291
def test_send_creates_mention_email_when_sender_limit_not_reached(
7392
self,
7493
mention_email_data,

0 commit comments

Comments
 (0)