From 9392391dd580be60cb6e2efc2293db82b9e4badf Mon Sep 17 00:00:00 2001 From: Nguyễn Gia Phong Date: Sat, 21 Oct 2023 07:44:42 +0900 Subject: Replace dependencies Bleach has been deprecated along with html5lib, and its replacement nh3 lacks the linkify function, so mistune is used for markdown for its url plugin. --- src/formbox.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/formbox.py b/src/formbox.py index 3943401..236c473 100755 --- a/src/formbox.py +++ b/src/formbox.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # Format mbox as HTML/XML -# Copyright (C) 2021-2022 Nguyễn Gia Phong +# Copyright (C) 2021-2023 Nguyễn Gia Phong # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published @@ -24,13 +24,14 @@ from mailbox import mbox from pathlib import Path from urllib.parse import quote, unquote, urlencode -from bleach import clean, linkify -from markdown import markdown +from mistune import create_markdown +from nh3 import clean -sanitise = partial(clean, tags=('a', 'code', 'em', 'strong', 'sub', 'sup', - 'blockquote', 'p', 'pre', 'ul', 'ol', 'li'), - protocols=('ftp', 'gemini', 'gopher', 'http', 'https', - 'irc', 'ircs', 'mailto', 'matrix', 'xmpp')) +markdown = create_markdown(plugins=['url']) +sanitise = partial(clean, tags={'a', 'code', 'em', 'strong', 'sub', 'sup', + 'blockquote', 'p', 'pre', 'ul', 'ol', 'li'}, + url_schemes={'ftp', 'gemini', 'gopher', 'http', 'https', + 'irc', 'ircs', 'mailto', 'matrix', 'xmpp'}) def get_body(message): @@ -40,7 +41,7 @@ def get_body(message): if payload is not None: return payload elif message.get_content_type() in ('text/markdown', 'text/plain'): payload = message.get_payload(decode=True).decode() - return sanitise(linkify(markdown(payload, output_format='html5'))) + return sanitise(markdown(payload)) return None -- cgit 1.4.1