Zeige PDF-Anlagen in der Mail-Ansicht, damit der Browser sie nicht unter einem zufälligen Namen speichert.
Deploy Development / deploy (push) Successful in 47s
Test Suite / pytest-backend (push) Successful in 6m16s
Test Suite / smoke-dev (push) Successful in 1s
Test Suite / frontend-build (push) Successful in 22s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-10-23 12:59:07 +02:00
1 parent d0f09830bb
commit cd239a3ab8
5 files changed
+164 -26

No files matched your search

+9 -4
View File
@@ -242,13 +242,18 @@ def download_mail_attachment(
if index < 0 or index >= len(parsed.attachments):
raise not_found()
item = parsed.attachments[index]
return _mail_bytes(item.data, item.media_type or "application/octet-stream", item.filename, inline=True)
name = item.display_name or item.filename or "anlage"
media = (item.media_type or "application/octet-stream").split(";", 1)[0].strip()
if item.data[:1024].lstrip(b"\xef\xbb\xbf\r\n\t ").startswith(b"%PDF"):
media = "application/pdf"
if not name.lower().endswith(".pdf"):
leaf = name.replace("\\", "/").split("/")[-1]
name = name if "." in leaf else f"{name}.pdf"
return _mail_bytes(item.data, media or "application/octet-stream", name, inline=True)
def _mail_bytes(data: bytes, media_type: str, filename: str, inline: bool = False) -> Response:
disposition = content_disposition(filename)
if inline:
disposition = disposition.replace("attachment;", "inline;", 1)
disposition = content_disposition(filename, inline=inline)
return Response(
content=data,
media_type=media_type,