diff --git a/backend/app/api/sources.py b/backend/app/api/sources.py index 01be898..e74bc68 100644 --- a/backend/app/api/sources.py +++ b/backend/app/api/sources.py @@ -186,15 +186,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) + return _mail_bytes(item.data, item.media_type or "application/octet-stream", item.filename, inline=True) -def _mail_bytes(data: bytes, media_type: str, filename: str) -> Response: +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) return Response( content=data, media_type=media_type, headers={ - "Content-Disposition": content_disposition(filename), + "Content-Disposition": disposition, "X-Content-Type-Options": "nosniff", "Cache-Control": "private, no-store", }, diff --git a/backend/tests/test_mailboxes.py b/backend/tests/test_mailboxes.py index 7740c69..fa70fb5 100644 --- a/backend/tests/test_mailboxes.py +++ b/backend/tests/test_mailboxes.py @@ -263,6 +263,8 @@ def test_an_adopted_message_loads_in_full_with_its_attachment(client, db, monkey attachment = _raw(ada, f"/api/v1/external-refs/{created['id']}/mail/attachments/0") assert attachment.status_code == 200 assert attachment.content.startswith(b"%PDF") + assert attachment.headers["content-type"].startswith("application/pdf") + assert attachment.headers["content-disposition"].startswith("inline;") ada.request( "POST", "/api/v1/external-refs", diff --git a/frontend/src/api.js b/frontend/src/api.js index 69232cc..c2a3c0a 100644 --- a/frontend/src/api.js +++ b/frontend/src/api.js @@ -76,16 +76,21 @@ function mailQuery(context) { return params; } -export async function downloadMailPart(elementId, context, suffix, filename) { +export async function fetchMailPart(elementId, context, suffix) { const response = await fetch(`/api/v1/external-refs/${elementId}/mail/${suffix}?${mailQuery(context)}`, { credentials: "include", headers: scopeHeaders(), }); if (!response.ok) { const data = await response.json().catch(() => null); - throw new Error(data?.detail || "Die vollständige E-Mail ist nicht verfügbar."); + const fallback = suffix === "original" ? "Die vollständige E-Mail ist nicht verfügbar." : "Die Anlage ist nicht verfügbar."; + throw new Error(data?.detail || fallback); } - const blob = await response.blob(); + return response.blob(); +} + +export async function downloadMailPart(elementId, context, suffix, filename) { + const blob = await fetchMailPart(elementId, context, suffix); const url = URL.createObjectURL(blob); const link = document.createElement("a"); link.href = url; diff --git a/frontend/src/pages/ReadingPane.jsx b/frontend/src/pages/ReadingPane.jsx index 4018c61..e7bb5fc 100644 --- a/frontend/src/pages/ReadingPane.jsx +++ b/frontend/src/pages/ReadingPane.jsx @@ -1,5 +1,5 @@ import { useEffect, useRef, useState } from "react"; -import { documentToText, downloadMailPart, fetchFile, fetchPaperless, markDirty, textToDocument, api } from "../api.js"; +import { documentToText, downloadMailPart, fetchFile, fetchMailPart, fetchPaperless, markDirty, textToDocument, api } from "../api.js"; import { ErrorNote } from "./widgets.jsx"; import { dateCaption, DirectionChoice, DirectionColumn, directionWord, formatDate, mailFacts, MarkdownEditor, sourceLabel } from "./content.jsx"; import { NavIcon } from "./icons.jsx"; @@ -7,14 +7,22 @@ import workerSrc from "pdfjs-dist/build/pdf.worker.min.mjs?url"; const SCALES = [0.75, 1, 1.25, 1.5, 2]; -function MailAttachments({ files, onOpen }) { +function previewKind(type, filename) { + const media = (type || "").toLowerCase(); + const name = (filename || "").toLowerCase(); + if (media.startsWith("image/") || /\.(png|jpe?g|gif|webp)$/.test(name)) return "image"; + if (media.includes("pdf") || name.endsWith(".pdf")) return "pdf"; + return "other"; +} + +function MailAttachments({ files, current, onOpen }) { if (!files?.length) return
Keine Anhänge.
; return (Kopie {mailDetail.message_cc}
: null} {letter?.complete ? ( <> -Anlage: {shownFile.filename}
: null} + {shownFile && phase === "loading" ?Die Anlage wird geladen …
: null} + {media === "image" && blobUrl ? ( +Diese Anlage lässt sich hier nicht als Seite zeigen.
+ Anlage öffnen +{letter.text} : (
Diese Nachricht hat keinen lesbaren Text. Die vollständige E-Mail bleibt abrufbar.
)} @@ -428,25 +522,25 @@ export function ReadingPane({ binding, context, backLabel, onClose, onReload, ca />Keine Angabe bleibt leer. Versand- und Zugangsdatum ändern die Richtung nicht.
- {phase === "loading" ?Vorschau wird geladen …
: null} - {phase === "missing" ? ( + {!isMail && phase === "loading" ?Vorschau wird geladen …
: null} + {!isMail && phase === "missing" ? (Für diesen Inhalt gibt es keine eingebaute Vorschau.
Die Vorschau ist nicht verfügbar.
Die Datei ist geladen, aber hier nicht als Seite darstellbar.
Original öffnen diff --git a/frontend/src/styles.css b/frontend/src/styles.css index f142a55..54b5ea7 100644 --- a/frontend/src/styles.css +++ b/frontend/src/styles.css @@ -714,7 +714,9 @@ button.hierarchy__row { width: 100%; min-height: 34px; padding: 6px 8px; border: .mail-preview p, .mail-letter p { margin: 0; overflow-wrap: anywhere; } .mail-preview p span, .mail-letter p span { display: inline-block; min-width: 3.2rem; color: var(--text3); font-size: 12px; font-weight: 700; } .mail-preview__party { font-weight: 700; } -.mail-files { margin: 0; padding-left: 1.1rem; } +.mail-files { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; } +.mail-files button.is-current { background: var(--accent-light); color: var(--text); } +.mail-attachment__caption { margin: 12px 0 0; font-weight: 650; } .preview-row--linked { box-shadow: inset 3px 0 0 var(--accent); } .bezug { flex: 1 1 100%; display: grid; gap: 2px; min-width: 0; } .bezug__link, a.bezug__link, p.bezug__link {