Skip to content

Commit 2e6ae1e

Browse files
felixxmsarahboyce
authored andcommitted
[5.0.x] Refs #34900, Refs #35361 -- Fixed SafeMIMEText.set_payload() crash on Python 3.13.
Payloads with surrogates are passed to the set_payload() since python/cpython@f97f25e Backport of b231bcd from main.
1 parent f075a19 commit 2e6ae1e

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

django/core/mail/message.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ def __setitem__(self, name, val):
168168
def set_payload(self, payload, charset=None):
169169
if charset == "utf-8" and not isinstance(charset, Charset.Charset):
170170
has_long_lines = any(
171-
len(line.encode()) > RFC5322_EMAIL_LINE_LENGTH_LIMIT
171+
len(line.encode(errors="surrogateescape"))
172+
> RFC5322_EMAIL_LINE_LENGTH_LIMIT
172173
for line in payload.splitlines()
173174
)
174175
# Quoted-Printable encoding has the side effect of shortening long

0 commit comments

Comments
 (0)