Commit 8cb56116 authored by Mark Sapiro's avatar Mark Sapiro

Merge branch 'fix_732' into 'master'

Fix to not return surrogates.

Closes #732

See merge request !665
parents 6b276b9c 9209030a
Pipeline #157457055 passed with stage
in 10 minutes and 46 seconds
......@@ -23,6 +23,8 @@ Bugs
(Closes #725)
* The ``dmarc`` rule no longer misses if DNS returns a name containing upper
case. (Closes #726)
* Fixed ```` to not return unicode
surrogates. (Closes #732)
Command line
......@@ -55,7 +55,8 @@ class Message(email.message.Message):
except (KeyError, LookupError, UnicodeEncodeError):
value = email.message.Message.as_bytes(self).decode(
'ascii', 'replace')
return value
# Also ensure no unicode surrogates in the returned string.
return email.utils._sanitize(value)
def sender(self):
From: [email protected]
To: [email protected]
Subject: Test Message
Message-ID: <[email protected]>
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="zzz123"
Ce message est au format MIME. Comme votre logiciel de courrier ne comprend
pas ce format, tout ou partie de ce message pourrait être illisible.
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Plain Text
Content-Type: text/html; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Not really HTML
......@@ -22,6 +22,7 @@ import unittest
from email import message_from_binary_file
from email.header import Header
from email.parser import FeedParser
from email.utils import _has_surrogates
from importlib_resources import path
from import create_list
from import Message, UserNotification
......@@ -121,6 +122,12 @@ Test content
text ='ascii', 'replace')
self.assertEqual(msg.as_string(), text)
def test_as_string_unicode_surrogates(self):
with path('', 'bad_email_4.eml') as email_path:
with open(str(email_path), 'rb') as fp:
msg = message_from_binary_file(fp, Message)
def test_bogus_content_charset(self):
with path('', 'bad_email_3.eml') as email_path:
with open(str(email_path), 'rb') as fp:
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment