From b231bcd19e57267ce1fc21d42d46f0b65fdcfcf8 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Fri, 15 Mar 2024 12:51:40 +0100 Subject: [PATCH] Refs #34900 -- 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 --- django/core/mail/message.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/django/core/mail/message.py b/django/core/mail/message.py index 4f8c93e9e5..205c680561 100644 --- a/django/core/mail/message.py +++ b/django/core/mail/message.py @@ -168,7 +168,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