diff options
Diffstat (limited to 'src/formbox.py')
-rw-r--r-- | src/formbox.py | 9 |
1 files changed, 4 insertions, 5 deletions
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='') |