about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNguyễn Gia Phong <cnx@loang.net>2023-10-21 07:44:42 +0900
committerNguyễn Gia Phong <cnx@loang.net>2023-10-21 07:44:42 +0900
commit9392391dd580be60cb6e2efc2293db82b9e4badf (patch)
tree8d8acd78d9e8d0309426870867ea857087758456
parenta632a4ccc505876144ae6ca8b3fd68cdf4bdb64a (diff)
downloadformbox-9392391dd580be60cb6e2efc2293db82b9e4badf.tar.gz
Replace dependencies 0.4.2
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.
-rw-r--r--README.md13
-rw-r--r--pyproject.toml10
-rwxr-xr-xsrc/formbox.py17
3 files changed, 20 insertions, 20 deletions
diff --git a/README.md b/README.md
index 4e05c61..fa218f0 100644
--- a/README.md
+++ b/README.md
@@ -5,14 +5,14 @@ for rendering email replies on websites and their [RSS] feed.
 
 ## Prerequisites
 
-This Python package depends on [bleach] for HTML sanitising
-and [markdown] for, well, rendering Markdown to HTML.  It is, however,
+This Python package depends on [nh3] for HTML sanitization
+and [mistune] for rendering Markdown to HTML.  It is, however,
 not designed to work with HTML emails with all those CSS and Java scripts.
 
 ## Installation
 
 It is recommended to install this package from a downstream repository,
-such as [Nix] or [IPWHL].
+such as [nixpkgs].
 
 ## Usage
 
@@ -40,7 +40,6 @@ by the Free Software Foundation, either version 3 of the License, or
 
 [mbox]: https://en.wikipedia.org/wiki/Mbox
 [RSS]: https://www.rssboard.org
-[bleach]: https://bleach.readthedocs.io
-[markdown]: https://python-markdown.github.io
-[Nix]: https://search.nixos.org/packages?channel=unstable&query=formbox
-[IPWHL]: https://man.sr.ht/~cnx/ipwhl
+[nh3]: https://nh3.readthedocs.io
+[mistune]: https://mistune.lepture.com
+[nixpkgs]: https://search.nixos.org/packages?channel=unstable&query=formbox
diff --git a/pyproject.toml b/pyproject.toml
index 4763535..3786313 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -4,13 +4,13 @@ build-backend = "flit_core.buildapi"
 
 [project]
 name = "formbox"
-version = "0.4.1"
+version = "0.4.2"
 description = "Format mbox as HTML/XML"
 readme = "README.md"
 requires-python = ">=3.6"
 license = { file = "COPYING" }
-authors = [ { name = "Nguyễn Gia Phong", email = "mcsinyx@disroot.org" } ]
-maintainers = [ { name = "Nguyễn Gia Phong", email = "mcsinyx@disroot.org" } ]
+authors = [ { name = "Nguyễn Gia Phong", email = "cnx@loang.net" } ]
+maintainers = [ { name = "Nguyễn Gia Phong", email = "cnx@loang.net" } ]
 keywords = [ "email", "format", "html", "mbox", "template", "xml" ]
 classifiers = [
     "Development Status :: 4 - Beta",
@@ -20,6 +20,6 @@ classifiers = [
     "Programming Language :: Python",
     "Topic :: Communications :: Email",
     "Topic :: Utilities" ]
-dependencies = [ "bleach", "markdown" ]
-urls = { SourceHut = "https://sr.ht/~cnx/formbox" }
+dependencies = [ "mistune", "nh3" ]
+urls = { Source = "https://trong.loang.net/~cnx/formbox" }
 scripts = { formbox = "formbox:main" }
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