diff options
Diffstat (limited to 'mu4web/main.py')
-rw-r--r-- | mu4web/main.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/mu4web/main.py b/mu4web/main.py index bfade9d..59f14c7 100644 --- a/mu4web/main.py +++ b/mu4web/main.py @@ -18,12 +18,16 @@ from typing import ( Optional, cast, ) +import sqlite3 + from .mu import get_mail from . import mu +from . import message_db from .html_render import HTML, render_document from .user.local import LocalUser from .user.pam import PamUser from .maildir import find_maildirs, serialize_maildir +from .tree import fetch_relation_tree, Tree import flask from flask import ( @@ -431,6 +435,29 @@ def search_result(q: str, by: Optional[str], direction: str) -> HTML: ('tbody', body))) +def tree_to_html(current_id: str, tree: Tree) -> HTML: + """ + Format the given tree as HTML. + + Currently this is specific to a specific kind of trees. + """ + body: list[HTML] + if current_id == tree.data.entry: + body = [ + f"{tree.data.date:%Y-%m-%d %H:%M} {tree.data.from_}", + ] + else: + body = [ + ('a', {'href': '?' + urlencode({'id': tree.data.entry})}, + f"{tree.data.date:%Y-%m-%d %H:%M} {tree.data.from_}", + # tree.data.subject, + ) + ] + if tree.children: + body += [('ul', [tree_to_html(current_id, c) for c in tree.children])] + return ('li', body) + + def response_for(id: str, mail: EmailMessage) -> str: """ Build response page for an email or a tree. @@ -489,12 +516,23 @@ def response_for(id: str, mail: EmailMessage) -> str: body.append(('a', {'href': url}, at.get_filename() or at.get_content_type())) + con = sqlite3.connect(message_db) + cur = con.cursor() + relation_tree_data = fetch_relation_tree(cur, mail) + relation_tree: HTML + if not relation_tree_data: + relation_tree = '' + else: + relation_tree = ('ul', tree_to_html(id, relation_tree_data)) + # Setup attachements tree, idx = attachement_tree(id, mail) main_body: list[HTML] = [header_list, full_headers, ('hr',), + relation_tree, + ('hr',), ('main', body), ('hr',), ('a', {'href': '/raw?' + urlencode({'id': id})}, |