summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2024-03-15 12:51:40 +0100
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2024-04-10 18:18:52 +0200
commit0d3ddcaf2c74638a32781f361d467af572ced95f (patch)
tree87abe4333af5ba73a21cfd04ae0946c5ef848f43
parenta76c52b19a221147f3a903848f711daa367e2e20 (diff)
[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 https://github.com/python/cpython/commit/f97f25ef5dfcdfec0d9a359fd970abd139cf3428 Backport of b231bcd19e57267ce1fc21d42d46f0b65fdcfcf8 from main.
-rw-r--r--django/core/mail/message.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/django/core/mail/message.py b/django/core/mail/message.py
index f3fe6186c7..1d4c5271c8 100644
--- a/django/core/mail/message.py
+++ b/django/core/mail/message.py
@@ -166,7 +166,8 @@ class SafeMIMEText(MIMEMixin, MIMEText):
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