Skip to content

Commit

Permalink
Tests: fix broken inbound test
Browse files Browse the repository at this point in the history
Django SafeMIMEText corner case
behaves differently in Python
3.11.9+, 3.12.3+, likely due to
python/cpython#116125
  • Loading branch information
medmunds committed May 16, 2024
1 parent daef82c commit 4c62f7b
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions tests/test_inbound.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from email.utils import collapse_rfc2231_value
from textwrap import dedent

from django.core.mail import SafeMIMEText
from django.test import SimpleTestCase

from anymail.exceptions import AnymailDeprecationWarning
Expand Down Expand Up @@ -245,7 +244,17 @@ def test_parse_raw_mime_8bit_utf8(self):
# (This might be a Django bug; plain old MIMEText avoids the problem by using
# 'Content-Transfer-Encoding: base64', which parses fine as text or bytes.)
# Either way, AnymailInboundMessage should try to sidestep the whole issue.
raw = SafeMIMEText("Unicode ✓", "plain", "utf-8").as_string()
# (This test might no longer be relevant--this might have been a corner case
# in Django's SafeMIME code in Python 2.7 only.)
raw = dedent(
# django.core.mail.message.SafeMIMEText("Unicode ✓", "plain", "utf-8").as_string()
"""\
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Unicode ✓"""
)
msg = AnymailInboundMessage.parse_raw_mime(raw)
self.assertEqual(msg.text, "Unicode ✓") # *not* "Unicode \\u2713"

Expand Down

0 comments on commit 4c62f7b

Please sign in to comment.