Skip to content

Commit 0d3ddca

Browse files
felixxmsarahboyce
authored andcommitted
[4.2.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 a76c52b commit 0d3ddca

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

django/core/mail/message.py

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

0 commit comments

Comments
 (0)