diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/formbox.py | 17 |
1 files changed, 9 insertions, 8 deletions
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 |