Skip to content

Commit

Permalink
[4.2.x] Refs #34900, Refs #35361 -- Fixed SafeMIMEText.set_payload() …
Browse files Browse the repository at this point in the history
…crash on Python 3.13.

Payloads with surrogates are passed to the set_payload() since
python/cpython@f97f25e

Backport of b231bcd from main.
  • Loading branch information
felixxm authored and sarahboyce committed Apr 10, 2024
1 parent a76c52b commit 0d3ddca
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion django/core/mail/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ def __setitem__(self, name, val):
def set_payload(self, payload, charset=None):
if charset == "utf-8" and not isinstance(charset, Charset.Charset):
has_long_lines = any(
len(line.encode()) > RFC5322_EMAIL_LINE_LENGTH_LIMIT
len(line.encode(errors="surrogateescape"))
> RFC5322_EMAIL_LINE_LENGTH_LIMIT
for line in payload.splitlines()
)
# Quoted-Printable encoding has the side effect of shortening long
Expand Down

0 comments on commit 0d3ddca

Please sign in to comment.