summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2017-01-06 10:33:53 +0100
committerClaude Paroz <claude@2xlibre.net>2017-01-06 16:04:59 +0100
commit9390533951efa2c5d0113f82850192113afda543 (patch)
tree53a1a62bf80173726450e09d89f2b4efd3aae700
parentad7f3c0b7baad3d2b46bebc4809e90d4853bc3c6 (diff)
Fixed #27696 -- Measured email long lines on encoded content
Thanks Pavel Pokrovskiy for the report and Tim Graham for the review.
-rw-r--r--django/core/mail/message.py5
-rw-r--r--tests/mail/tests.py3
2 files changed, 6 insertions, 2 deletions
diff --git a/django/core/mail/message.py b/django/core/mail/message.py
index 97703cac0f..3cebbaf9d2 100644
--- a/django/core/mail/message.py
+++ b/django/core/mail/message.py
@@ -219,7 +219,10 @@ class SafeMIMEText(MIMEMixin, MIMEText):
def set_payload(self, payload, charset=None):
if charset == 'utf-8':
- has_long_lines = any(len(l) > RFC5322_EMAIL_LINE_LENGTH_LIMIT for l in payload.splitlines())
+ has_long_lines = any(
+ len(l.encode('utf-8')) > RFC5322_EMAIL_LINE_LENGTH_LIMIT
+ for l 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
diff --git a/tests/mail/tests.py b/tests/mail/tests.py
index 8e7458bc49..fd2a185fb5 100644
--- a/tests/mail/tests.py
+++ b/tests/mail/tests.py
@@ -779,7 +779,8 @@ class BaseEmailBackendTests(HeadersCheckMixin, object):
Message body containing longer lines are converted to Quoted-Printable
to avoid having to insert newlines, which could be hairy to do properly.
"""
- email = EmailMessage('Subject', "Comment ça va? " * 100, 'from@example.com', ['to@example.com'])
+ # Unencoded body length is < 998 (840) but > 998 when utf-8 encoded.
+ email = EmailMessage('Subject', 'В южных морях ' * 60, 'from@example.com', ['to@example.com'])
email.send()
message = self.get_the_message()
self.assertMessageHasHeaders(message, {