about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNguyễn Gia Phong <mcsinyx@disroot.org>2022-01-10 20:55:17 +0700
committerNguyễn Gia Phong <mcsinyx@disroot.org>2022-01-11 21:57:29 +0700
commit03c249a5326f412dc63b4f5a5465ea80fd822dda (patch)
tree8656500a81a2a8614728d3bbfbc774bb62c5590d
parent52541db07e34db6507416537150e4250b0617d5f (diff)
downloadformbox-03c249a5326f412dc63b4f5a5465ea80fd822dda.tar.gz
Minimize sorting
-rw-r--r--pyproject.toml2
-rw-r--r--src/formbox.py9
2 files changed, 6 insertions, 5 deletions
diff --git a/pyproject.toml b/pyproject.toml
index d69bee3..b3a8166 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -14,9 +14,11 @@ maintainers = [ { name = "Nguyễn Gia Phong", email = "mcsinyx@disroot.org" } ]
 keywords = [ "email", "format", "html", "mbox", "template", "xml" ]
 classifiers = [
     "Development Status :: 4 - Beta",
+    "Environment :: Console",
     "License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)",
     "Operating System :: OS Independent",
     "Programming Language :: Python",
+    "Topic :: Communications :: Email",
     "Topic :: Utilities" ]
 dependencies = [ "bleach", "markdown" ]
 urls = { SourceHut = "https://sr.ht/~cnx/formbox" }
diff --git a/src/formbox.py b/src/formbox.py
index 46bad22..776b3e0 100644
--- a/src/formbox.py
+++ b/src/formbox.py
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 # Format mbox as HTML/XML
-# Copyright (C) 2021  Nguyễn Gia Phong
+# Copyright (C) 2021-2022  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
@@ -70,7 +70,7 @@ def date(message):
 
 def render(template, archive, parent):
     """Render the thread recursively based on given template."""
-    for self in archive[parent]:
+    for self in sorted(archive[parent], key=date):
         body = get_body(self)
         if body is None: continue
         message_id = self['Message-Id']
@@ -88,14 +88,13 @@ def render(template, archive, parent):
 def main():
     """Parse command-line arguments and pass them to routines."""
     parser = ArgumentParser(description='format mbox as HTML/XML')
-    parser.add_argument('mbox', help='path to mbox file')
+    parser.add_argument('mbox', type=mbox, help='path to mbox file')
     parser.add_argument('id', type=unquote, help='root message ID')
     parser.add_argument('template', type=Path, help='path to template')
     args = parser.parse_args()
 
     archive = defaultdict(list)
-    for message in sorted(mbox(args.mbox), key=date):
-        archive[message['In-Reply-To']].append(message)
+    for message in args.mbox: archive[message['In-Reply-To']].append(message)
     template = args.template.read_text()
     print(*render(template, archive, args.id), sep='', end='')