aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2023-08-07 12:49:54 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2023-08-07 15:16:41 +0200
commit0498331a15cfa8de7f2c3f4a761695ae21ae6245 (patch)
tree6c4a19fe4275a2b5a83fb9ec2da3648acb8a31ec
parentStop reusing salt for passwords. (diff)
downloadmu4web-0498331a15cfa8de7f2c3f4a761695ae21ae6245.tar.gz
mu4web-0498331a15cfa8de7f2c3f4a761695ae21ae6245.tar.xz
Introduce dl function.
-rw-r--r--mu4web/components.py10
-rw-r--r--mu4web/main.py26
2 files changed, 21 insertions, 15 deletions
diff --git a/mu4web/components.py b/mu4web/components.py
index e9701de..07ab400 100644
--- a/mu4web/components.py
+++ b/mu4web/components.py
@@ -9,6 +9,16 @@ from .html_render import HTML
from typing import cast, Optional
from urllib.parse import urlencode
from email.message import EmailMessage
+from typing import Iterable
+
+
+def dl(entries: Iterable[tuple[HTML, HTML]]) -> HTML:
+ """Build a description list."""
+ items = []
+ for k, v in entries:
+ items += [('dt', k),
+ ('dd', v)]
+ return ('dl', items)
def format_email(addr: Address) -> list[HTML]:
diff --git a/mu4web/main.py b/mu4web/main.py
index e782233..bfade9d 100644
--- a/mu4web/main.py
+++ b/mu4web/main.py
@@ -35,16 +35,15 @@ from flask import (
get_flashed_messages
)
from .components import (
+ attachement_tree,
+ dl,
+ flashed_messages,
header_format,
-)
-from .components import (
include_stylesheet,
- flashed_messages,
+ login_page,
login_prompt,
- user_info,
search_field,
- attachement_tree,
- login_page,
+ user_info,
)
from .util import MutableString
@@ -447,20 +446,17 @@ def response_for(id: str, mail: EmailMessage) -> str:
for (key, value) in mail.items():
headers[key.lower()] = value
- head = []
+ header_entries = []
for h in app.config['MESSAGE_HEADERS']:
if x := headers.get(h.lower()):
- head += [('dt', h.title()),
- ('dd', header_format(h.lower(), x))]
+ header_entries.append((h.title(),
+ header_format(h.lower(), x)))
- all_heads = []
- for key, value in mail.items():
- all_heads += [('dt', key.title()),
- ('dd', value)]
+ header_list = dl(header_entries)
full_headers = ('details',
('summary', 'Alla mailhuvuden'),
- ('dl', *all_heads))
+ dl((key.title(), value) for (key, value) in mail.items()))
# Setup title
if t := headers.get('subject'):
@@ -496,7 +492,7 @@ def response_for(id: str, mail: EmailMessage) -> str:
# Setup attachements
tree, idx = attachement_tree(id, mail)
- main_body: list[HTML] = [('dl', *head),
+ main_body: list[HTML] = [header_list,
full_headers,
('hr',),
('main', body),