aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2022-11-30 05:58:17 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2022-11-30 05:58:17 +0100
commita7b40a5256ecc17d34d4eaac9337a00b014e3843 (patch)
tree1cdedeafde132c5d2f581ecf7bae051a770bd8be
parentMove stylesheet to other file. (diff)
downloadmu4web-a7b40a5256ecc17d34d4eaac9337a00b014e3843.tar.gz
mu4web-a7b40a5256ecc17d34d4eaac9337a00b014e3843.tar.xz
Add maildir listing on frontpage.
-rw-r--r--mu4web/main.py50
-rw-r--r--mu4web/static/style.css6
2 files changed, 44 insertions, 12 deletions
diff --git a/mu4web/main.py b/mu4web/main.py
index fe02f3b..de2bbd4 100644
--- a/mu4web/main.py
+++ b/mu4web/main.py
@@ -22,6 +22,7 @@ from html_render import HTML, render_document
from user.local import LocalUser
from user.pam import PamUser
+import subprocess
from flask import (
Flask,
@@ -131,7 +132,7 @@ def page_base(title: Optional[str] = None,
('nav',
('menu',
('li',
- ('h1', 'Mu4Web'),
+ ('h1', ('a', {'href': '/'}, 'Mu4Web')),
('li',
user_info(current_user.get_id())
if current_user.is_authenticated else login_prompt())
@@ -189,12 +190,12 @@ def response_for(id: str, username: Optional[str] = None) -> str:
def search_field(q: str) -> HTML:
- return ('form', {'id': 'searchform',
- 'action': '/search',
+ return ('form', {'id': 'searchform',
+ 'action': '/search',
'method': 'GET'},
('label', {'for': 'search'},
'Mu Search Query'),
- ('input', {'id': 'search',
+ ('input', {'id': 'search',
'type': 'text',
'placeholder': 'Sök...',
'name': 'q',
@@ -246,12 +247,27 @@ def mu_info():
d = mu.info()
rows = []
for key, value in d.items():
- rows.append(('tr',
+ rows.append(('tr',
('td', key),
('td', value)))
return ('table', ('tbody', rows))
+def find_maildirs(basedir) -> dict[str, list[str]]:
+ cmd = subprocess.run(['find', basedir,
+ '-type', 'd',
+ '-name', 'cur',
+ '-print0'],
+ capture_output=True)
+ groups = {}
+ # Group by first component
+ for entry in cmd.stdout.split(b'\0'):
+ dir = os.path.split(entry)[0][len(basedir) + 1:].decode('UTF-8')
+ if not dir:
+ continue
+ parts = dir.split(os.path.sep)
+ groups.setdefault(parts[0], []).append(parts[1:])
+ return groups
def index_page():
ids = [
@@ -259,13 +275,23 @@ def index_page():
'CA+pcBt-gLb0GtbFOjJ5_7Q_WXtqApVPQ9w-3O7GH=VqCEQat6g@mail.gmail.com',
]
- body = [ mu_info(),
- ('hr',),
- ('h1', "Sample ID's"),
- ('ul',
- [('li', ('a', {'href': '?' + urlencode({'id': id})}, id))
- for id in ids]
- ),
+ data = mu.info()
+ groups = find_maildirs(data['maildir'])
+
+ entries = []
+
+ for key, values in sorted(groups.items(), key=lambda p: p[0]):
+ entries.append(('li',
+ ('details',
+ ('summary', key),
+ ('ul',
+ [('li',
+ ('a', {'href': 'search?' + urlencode({'q': f'maildir:"/{key}/{v}"'})}, v))
+ for v in sorted(os.path.sep.join(value) for value in values)]))))
+
+
+ body = [('div', mu_info()),
+ ('din', ('ul', entries)),
]
return render_document(page_base(title='Mail index',
diff --git a/mu4web/static/style.css b/mu4web/static/style.css
index b8df022..e8d16c2 100644
--- a/mu4web/static/style.css
+++ b/mu4web/static/style.css
@@ -2,6 +2,12 @@ body, html {
padding: 0;
margin: 0;
}
+
+h1 a {
+ text-decoration: none;
+ color: inherit;
+}
+
nav {
display: block;
height: 4em;