Lade eine uebernommene E-Mail bei Bedarf vollstaendig, damit Anzeige und Export nicht an der Vorschau haengen.
Deploy Development / deploy (push) Successful in 27s
Test Suite / pytest-backend (push) Failing after 1m10s
Test Suite / smoke-dev (push) Successful in 0s
Test Suite / frontend-build (push) Successful in 10s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-10-17 18:59:18 +02:00
1 parent 17a3b3a736
commit 7626c56f3d
7 files changed
+740 -19

No files matched your search

+59
View File
@@ -67,6 +67,35 @@ export async function api(path, { method = "GET", body, form } = {}) {
return data;
}
function mailQuery(context) {
const params = new URLSearchParams();
if (context?.kind && context?.id) {
params.set("context_kind", context.kind);
params.set("context_id", context.id);
}
return params;
}
export async function downloadMailPart(elementId, context, suffix, filename) {
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 blob = await response.blob();
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = url;
link.download = filename || "nachricht.eml";
document.body.appendChild(link);
link.click();
link.remove();
setTimeout(() => URL.revokeObjectURL(url), 60000);
}
export async function fetchPaperless(elementId, context) {
const params = new URLSearchParams();
if (context?.kind && context?.id) {
@@ -122,6 +151,36 @@ export async function downloadFile(elementId, context, filename) {
URL.revokeObjectURL(url);
}
export async function downloadPost(path, body, fallbackName) {
const headers = { ...scopeHeaders(), "Content-Type": "application/json" };
if (csrf) headers["X-CSRF-Token"] = csrf;
const response = await fetch(path, {
method: "POST",
headers,
body: JSON.stringify(body),
credentials: "include",
});
if (!response.ok) {
const data = await response.json().catch(() => null);
const error = new Error(data?.detail || "Die Anfrage ist fehlgeschlagen.");
error.status = response.status;
throw error;
}
const blob = await response.blob();
const disposition = response.headers.get("Content-Disposition") || "";
const extended = disposition.match(/filename\*=UTF-8''([^;]+)/i);
const plain = disposition.match(/filename="([^"]+)"/);
const filename = extended ? decodeURIComponent(extended[1]) : (plain && plain[1]) || fallbackName || "uebergabe.zip";
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = url;
link.download = filename;
document.body.appendChild(link);
link.click();
link.remove();
URL.revokeObjectURL(url);
}
export function textToDocument(text) {
return { version: 1, blocks: [{ type: "markdown", text: text || "" }] };
}
+28 -7
View File
@@ -1,5 +1,5 @@
import { useEffect, useRef, useState } from "react";
import { documentToText, fetchFile, fetchPaperless, markDirty, textToDocument, api } from "../api.js";
import { documentToText, downloadMailPart, fetchFile, fetchPaperless, markDirty, textToDocument, api } from "../api.js";
import { ErrorNote } from "./widgets.jsx";
import { dateCaption, DirectionChoice, DirectionMark, formatDate, mailFacts, MarkdownEditor, sourceLabel } from "./content.jsx";
import { NavIcon } from "./icons.jsx";
@@ -7,11 +7,17 @@ import workerSrc from "pdfjs-dist/build/pdf.worker.min.mjs?url";
const SCALES = [0.75, 1, 1.25, 1.5, 2];
function MailAttachments({ files }) {
function MailAttachments({ files, onOpen }) {
if (!files?.length) return <p className="muted">Keine Anhänge.</p>;
return (
<ul className="mail-files">
{files.map((file) => <li key={file.filename}>{file.filename}</li>)}
{files.map((file) => (
<li key={`${file.index ?? "name"}-${file.filename}`}>
{onOpen && Number.isInteger(file.index) ? (
<button type="button" className="quiet" onClick={() => onOpen(file)}>{file.filename}</button>
) : file.filename}
</li>
))}
</ul>
);
}
@@ -218,6 +224,15 @@ export function ReadingPane({ binding, context, backLabel, onClose, onReload, ca
return () => window.removeEventListener("keydown", onKey);
}, [onClose, pages]);
async function openMailPart(suffix, filename) {
setError("");
try {
await downloadMailPart(element.id, context, suffix, filename);
} catch (err) {
setError(err.message);
}
}
async function openOriginal() {
setError("");
try {
@@ -380,11 +395,17 @@ export function ReadingPane({ binding, context, backLabel, onClose, onReload, ca
<p><span>Von</span> {mailDetail.message_from || "Ohne Absender"}</p>
<p><span>An</span> {mailDetail.message_to || "Ohne Empfänger"}</p>
{mailDetail.message_cc ? <p><span>Kopie</span> {mailDetail.message_cc}</p> : null}
<MailAttachments files={mailDetail.attachments} />
{letter?.text ? <pre className="mail-letter__body">{letter.text}</pre> : (
<p className="muted">{error || "Zu dieser Nachricht liegt kein Text vor. Absender und Empfänger bleiben gespeichert."}</p>
{letter?.complete ? (
<>
<MailAttachments files={letter.attachments} onOpen={(file) => openMailPart(`attachments/${file.index}`, file.filename)} />
{letter.text ? <pre className="mail-letter__body">{letter.text}</pre> : (
<p className="muted">Diese Nachricht hat keinen lesbaren Text. Die vollständige E-Mail bleibt abrufbar.</p>
)}
<button type="button" onClick={() => openMailPart("original", "nachricht.eml")}>Vollständige E-Mail</button>
</>
) : (
<p className="muted">{error ? "Die vollständige Nachricht konnte nicht geladen werden." : "Die vollständige Nachricht wird geladen …"}</p>
)}
{letter?.text_truncated ? <p className="muted">Der Text ist gekürzt. Die Nachricht selbst ist größer als die Vorschau.</p> : null}
</article>
) : null}
{element.kind === "note" ? (