From 370d4608ad9b534dc1e16c768e0b64ce9bf1ba5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Thu, 1 Dec 2022 00:05:54 +0100 Subject: Sugest download for unknown filetypes. --- mu4web/main.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mu4web/main.py b/mu4web/main.py index 86a0b38..a35d7c4 100644 --- a/mu4web/main.py +++ b/mu4web/main.py @@ -87,9 +87,13 @@ def attachement_tree(id: str, mail: EmailMessage, idx=0) -> tuple[HTML, int]: body = f'{ct} {fn}' else: body = str(ct) + download = {} + if mail.get_content_type() == 'application/octet-stream': + download['download'] = mail.get_filename() or '' return ('li', ('a', {'data-idx': str(_idx), 'href': '/part?' + urlencode({'id': id, 'idx': _idx}), + **download, }, body), content), idx # -------------------------------------------------- @@ -214,6 +218,11 @@ def response_for(id: str, username: Optional[str] = None) -> str: })) elif at.get_content_type() == 'text/plain': body.append(('pre', at.get_content())) + elif at.get_content_type() == 'application/octet-stream': + url = '/part?' + urlencode({'id': id, 'idx': idx}) + body.append(('a', {'href': url, + 'download': at.get_filename() or ''}, + at.get_filename() or at.get_content_type())) else: url = '/part?' + urlencode({'id': id, 'idx': idx}) body.append(('a', {'href': url}, -- cgit v1.2.3