aboutsummaryrefslogtreecommitdiff
path: root/mu4web/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'mu4web/main.py')
-rw-r--r--mu4web/main.py35
1 files changed, 14 insertions, 21 deletions
diff --git a/mu4web/main.py b/mu4web/main.py
index d57cc64..276f261 100644
--- a/mu4web/main.py
+++ b/mu4web/main.py
@@ -1,9 +1,6 @@
from email.message import EmailMessage
from email.headerregistry import Address
from urllib.parse import urlencode
-import password
-from password import Passwords
-import os
from datetime import datetime
from flask_login import (
LoginManager,
@@ -13,9 +10,7 @@ from flask_login import (
logout_user,
)
from typing import (
- Literal,
Optional,
- Union,
cast,
)
from mu import get_mail
@@ -25,11 +20,9 @@ from user.local import LocalUser
from user.pam import PamUser
from maildir import find_maildirs, serialize_maildir
-
import flask
from flask import (
Flask,
- session,
request,
redirect,
url_for,
@@ -179,7 +172,7 @@ def page_base(title: Optional[str] = None,
))))
-def response_for(id: str, username: Optional[str] = None) -> str:
+def response_for(id: str) -> str:
mail = cast(EmailMessage, get_mail(id))
@@ -264,11 +257,8 @@ def search_field(q: str) -> HTML:
('input', {'type': 'Submit', 'value': 'Sök'}))
-SortDirection = Union[Literal['rising'],
- Literal['falling']]
-
-
-def search_result(q: str, by: Optional[mu.Sortfield], direction: SortDirection) -> HTML:
+def search_result(q: str, by: Optional[str], direction: str) -> HTML:
+ assert direction in ('rising', 'falling')
# keys = ['from', 'to', 'subject', 'date', 'size', 'maildir', 'msgid']
keys = ['from', 'to', 'subject', 'date']
@@ -317,8 +307,8 @@ def search_result(q: str, by: Optional[mu.Sortfield], direction: SortDirection)
('tbody', body)))
-def search_page(q: str, by: Optional[mu.Sortfield],
- direction: SortDirection) -> str:
+def search_page(q: str, by: Optional[str],
+ direction: str) -> str:
main_body = [search_field(q)]
if q:
@@ -342,7 +332,6 @@ def index_page():
body = [('div', ('table', ('tbody', rows))),
('div', entries),
]
-
return render_document(page_base(title='Mail index',
body=body))
@@ -376,7 +365,7 @@ def search_page_():
direction = request.args.get('direction', DEFAULT_DIRECTION)
if direction not in ('rising', 'falling'):
direction = DEFAULT_DIRECTION
- return search_page(request.args.get('q'),
+ return search_page(request.args.get('q', ''),
request.args.get('by', None),
direction)
@@ -396,7 +385,7 @@ def multipart_page(msg_id: str,
attachement_idx - Index of attachement in top level mail.
Needed for links to work.
"""
- tree, idx = attachement_tree(msg_id, attachement, attachement_idx)
+ tree, _ = attachement_tree(msg_id, attachement, attachement_idx)
body: list[HTML] = [('a', {'href': '/?' + urlencode({'id': msg_id})},
'Återvänd till brev'),
('ul', tree),
@@ -422,7 +411,7 @@ def attachement_response(attachement: EmailMessage):
@app.route('/raw')
@login_required
def raw_message():
- msg_id = request.args.get('id')
+ msg_id = request.args.get('id', '')
filename = mu.find_file(msg_id)
if not filename:
return 'No message with that id', 404
@@ -433,12 +422,16 @@ def raw_message():
@login_required
def attachement_part_page():
msg_id = request.args.get('id')
- attachement_idx = int(request.args.get('idx'))
+ if not msg_id:
+ return "Message id required", 404
+ attachement_idx = int(request.args.get('idx', 0))
mail = cast(EmailMessage, get_mail(msg_id))
attachement = list(mail.walk())[attachement_idx]
if attachement.is_multipart():
- return multipart_page()
+ return multipart_page(msg_id,
+ attachement,
+ attachement_idx)
else:
return attachement_response(attachement)