summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2024-03-15 12:51:40 +0100
committerGitHub <noreply@github.com>2024-03-15 12:51:40 +0100
commitb231bcd19e57267ce1fc21d42d46f0b65fdcfcf8 (patch)
tree0d4f65d153a3ae5cbe37a4c804d2d3137d4be2be
parent36a000858b5eee13b039aaad490c33b037a1dc05 (diff)
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
-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 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