From b1345d547928b8fe51f15225355c5d83db6a6f8b Mon Sep 17 00:00:00 2001 From: slateny <46876382+slateny@users.noreply.github.com> Date: Sat, 24 Sep 2022 11:49:48 -0700 Subject: [PATCH 1/2] Create blank function instead of invalid import for email example --- Doc/includes/email-read-alternative.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Doc/includes/email-read-alternative.py b/Doc/includes/email-read-alternative.py index 5ea84e62584a46..896348bab153b8 100644 --- a/Doc/includes/email-read-alternative.py +++ b/Doc/includes/email-read-alternative.py @@ -8,8 +8,15 @@ from email import policy from email.parser import BytesParser -# An imaginary module that would make this work and be safe. -from imaginary import magic_html_parser + +def magic_html_parser(html_text, partfiles): + """Return safety sanitized html linked to partfiles. + + Rewrite the href="cid:...." attributes to point to the filenames in partfiles. + Though not trivial, this should be possible using html.parser. + """ + raise NotImplementedError("Add the magic needed") + # In a real program you'd get the filename from the arguments. with open('outgoing.msg', 'rb') as fp: @@ -62,9 +69,6 @@ print("Don't know how to display {}".format(richest.get_content_type())) sys.exit() with tempfile.NamedTemporaryFile(mode='w', delete=False) as f: - # The magic_html_parser has to rewrite the href="cid:...." attributes to - # point to the filenames in partfiles. It also has to do a safety-sanitize - # of the html. It could be written using html.parser. f.write(magic_html_parser(body.get_content(), partfiles)) webbrowser.open(f.name) os.remove(f.name) From 81291595e9944c8326ed34fd2d8342bad2a03ac6 Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Sun, 25 Sep 2022 21:33:12 -0400 Subject: [PATCH 2/2] Update Doc/includes/email-read-alternative.py --- Doc/includes/email-read-alternative.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/includes/email-read-alternative.py b/Doc/includes/email-read-alternative.py index 896348bab153b8..8d0b4e6eb6b6b5 100644 --- a/Doc/includes/email-read-alternative.py +++ b/Doc/includes/email-read-alternative.py @@ -10,7 +10,7 @@ def magic_html_parser(html_text, partfiles): - """Return safety sanitized html linked to partfiles. + """Return safety-sanitized html linked to partfiles. Rewrite the href="cid:...." attributes to point to the filenames in partfiles. Though not trivial, this should be possible using html.parser.