bpo-40597: Allow email.contextmanager set_content() to set a null string. (GH-20542)
This commit is contained in:
parent
61fc23ca10
commit
4fa61a7732
|
@ -146,7 +146,7 @@ def _encode_text(string, charset, cte, policy):
|
||||||
def normal_body(lines): return b'\n'.join(lines) + b'\n'
|
def normal_body(lines): return b'\n'.join(lines) + b'\n'
|
||||||
if cte==None:
|
if cte==None:
|
||||||
# Use heuristics to decide on the "best" encoding.
|
# Use heuristics to decide on the "best" encoding.
|
||||||
if max(len(x) for x in lines) <= policy.max_line_length:
|
if max((len(x) for x in lines), default=0) <= policy.max_line_length:
|
||||||
try:
|
try:
|
||||||
return '7bit', normal_body(lines).decode('ascii')
|
return '7bit', normal_body(lines).decode('ascii')
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
|
|
|
@ -303,6 +303,19 @@ class TestRawDataManager(TestEmailBase):
|
||||||
self.assertEqual(m.get_payload(decode=True).decode('utf-8'), content)
|
self.assertEqual(m.get_payload(decode=True).decode('utf-8'), content)
|
||||||
self.assertEqual(m.get_content(), content)
|
self.assertEqual(m.get_content(), content)
|
||||||
|
|
||||||
|
def test_set_text_plain_null(self):
|
||||||
|
m = self._make_message()
|
||||||
|
content = ''
|
||||||
|
raw_data_manager.set_content(m, content)
|
||||||
|
self.assertEqual(str(m), textwrap.dedent("""\
|
||||||
|
Content-Type: text/plain; charset="utf-8"
|
||||||
|
Content-Transfer-Encoding: 7bit
|
||||||
|
|
||||||
|
|
||||||
|
"""))
|
||||||
|
self.assertEqual(m.get_payload(decode=True).decode('utf-8'), '\n')
|
||||||
|
self.assertEqual(m.get_content(), '\n')
|
||||||
|
|
||||||
def test_set_text_html(self):
|
def test_set_text_html(self):
|
||||||
m = self._make_message()
|
m = self._make_message()
|
||||||
content = "<p>Simple message.</p>\n"
|
content = "<p>Simple message.</p>\n"
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Fixed email.contentmanager to allow set_content() to set a null string.
|
Loading…
Reference in New Issue