From 030000165a13fae269f0e47e031cba644b266ef0 Mon Sep 17 00:00:00 2001 From: Sandro Mani Date: Wed, 3 Jul 2024 11:38:28 +0200 Subject: [PATCH] Fix SafeMIMEText.set_payload() crash on Python 3.13 See https://github.com/django/django/commit/b231bcd19e57267ce1fc21d42d46f0b65fdcfcf8 --- flask_mailman/message.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flask_mailman/message.py b/flask_mailman/message.py index 3451b6f..cce499c 100644 --- a/flask_mailman/message.py +++ b/flask_mailman/message.py @@ -159,7 +159,7 @@ 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 for line in payload.splitlines()) + has_long_lines = any(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 # lines, if any (#22561). charset = utf8_charset_qp if has_long_lines else utf8_charset