Korrigiere IMAP-Ordner, MIME-Ansicht und die gemeinsamen Leser, damit große Postfächer, Notizen und verspätete Quellenantworten zuverlässig bleiben.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
34c4084a7c
commit
c29bd29f34
29 files changed
+2562
-410
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { api, fetchBlob } from "../api.js";
|
||||
import { MailBody } from "../mail-view.jsx";
|
||||
import { SourceFrame, moduleFor, registerSourceModule, sourceModules } from "../sources/registry.jsx";
|
||||
|
||||
const SEARCH_LIMITS = {
|
||||
@@ -201,6 +202,9 @@ export function PaperlessPicker({ context, placement, chapterId = "", chapterTit
|
||||
const [previewUrl, setPreviewUrl] = useState("");
|
||||
const [pending, setPending] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
const searchRef = useRef(0);
|
||||
const previewRef = useRef(0);
|
||||
const facetRef = useRef(0);
|
||||
|
||||
useEffect(() => {
|
||||
api("/api/v1/connectors")
|
||||
@@ -217,13 +221,15 @@ export function PaperlessPicker({ context, placement, chapterId = "", chapterTit
|
||||
setFacets({ correspondents: [], document_types: [], tags: [] });
|
||||
return undefined;
|
||||
}
|
||||
const token = facetRef.current + 1;
|
||||
facetRef.current = token;
|
||||
let alive = true;
|
||||
api(`/api/v1/sources/paperless/facets?connector_id=${connectorId}`)
|
||||
.then((data) => {
|
||||
if (alive) setFacets(data);
|
||||
if (alive && token === facetRef.current) setFacets(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
if (alive) setError(err.message);
|
||||
if (alive && token === facetRef.current) setError(err.message);
|
||||
});
|
||||
return () => {
|
||||
alive = false;
|
||||
@@ -253,6 +259,12 @@ export function PaperlessPicker({ context, placement, chapterId = "", chapterTit
|
||||
return params;
|
||||
}
|
||||
|
||||
function invalidate() {
|
||||
searchRef.current += 1;
|
||||
previewRef.current += 1;
|
||||
facetRef.current += 1;
|
||||
}
|
||||
|
||||
async function runSearch(event, page = "") {
|
||||
event?.preventDefault();
|
||||
setError("");
|
||||
@@ -260,12 +272,17 @@ export function PaperlessPicker({ context, placement, chapterId = "", chapterTit
|
||||
setError("Wähle zuerst den Paperless-Zugang.");
|
||||
return;
|
||||
}
|
||||
const token = searchRef.current + 1;
|
||||
searchRef.current = token;
|
||||
const asked = connectorId;
|
||||
try {
|
||||
const data = await api(`/api/v1/sources/paperless/documents?${paramsFor(page)}`);
|
||||
if (token !== searchRef.current) return;
|
||||
setItems(data.items || []);
|
||||
setNextPage(data.next_page || data.continuation || null);
|
||||
if (data.connector_id) setConnectorId(data.connector_id);
|
||||
if (!asked && data.connector_id) setConnectorId(data.connector_id);
|
||||
} catch (err) {
|
||||
if (token !== searchRef.current) return;
|
||||
setError(err.message);
|
||||
}
|
||||
}
|
||||
@@ -291,11 +308,15 @@ export function PaperlessPicker({ context, placement, chapterId = "", chapterTit
|
||||
setError("");
|
||||
if (previewUrl) URL.revokeObjectURL(previewUrl);
|
||||
setPreviewUrl("");
|
||||
const token = previewRef.current + 1;
|
||||
previewRef.current = token;
|
||||
const bound = item.connector_id || connectorId;
|
||||
try {
|
||||
const bound = item.connector_id || connectorId;
|
||||
const blob = await fetchBlob(`/api/v1/sources/paperless/documents/${item.id}/preview?connector_id=${bound}`);
|
||||
if (token !== previewRef.current) return;
|
||||
setPreviewUrl(URL.createObjectURL(blob));
|
||||
} catch (err) {
|
||||
if (token !== previewRef.current) return;
|
||||
setError(err.message);
|
||||
}
|
||||
}
|
||||
@@ -366,7 +387,16 @@ export function PaperlessPicker({ context, placement, chapterId = "", chapterTit
|
||||
{connectors.length > 1 ? (
|
||||
<label>
|
||||
Paperless-Zugang
|
||||
<select value={connectorId} onChange={(event) => { setConnectorId(event.target.value); setItems([]); setNextPage(null); }}>
|
||||
<select value={connectorId} onChange={(event) => {
|
||||
invalidate();
|
||||
if (previewUrl) URL.revokeObjectURL(previewUrl);
|
||||
setPreviewUrl("");
|
||||
setConnectorId(event.target.value);
|
||||
setFilters(EMPTY_FILTERS);
|
||||
setItems([]);
|
||||
setNextPage(null);
|
||||
setFacets({ correspondents: [], document_types: [], tags: [] });
|
||||
}}>
|
||||
<option value="">Zugang wählen</option>
|
||||
{connectors.map((item) => (
|
||||
<option key={item.id} value={item.id}>{item.name}</option>
|
||||
@@ -567,6 +597,7 @@ export function MailPicker({ context, placement, chapterId = "", chapterTitle =
|
||||
const [items, setItems] = useState([]);
|
||||
const [nextBefore, setNextBefore] = useState(null);
|
||||
const [incomplete, setIncomplete] = useState(false);
|
||||
const [contradictory, setContradictory] = useState(false);
|
||||
const [uidValidity, setUidValidity] = useState(null);
|
||||
const [notice, setNotice] = useState("");
|
||||
const [selectedKey, setSelectedKey] = useState("");
|
||||
@@ -587,6 +618,7 @@ export function MailPicker({ context, placement, chapterId = "", chapterTitle =
|
||||
if (token !== requestRef.current) return;
|
||||
setUidValidity(data.uidvalidity ?? null);
|
||||
setIncomplete(Boolean(data.incomplete));
|
||||
setContradictory(Boolean(data.contradictory));
|
||||
setNextBefore(data.next_before ?? data.continuation ?? null);
|
||||
if (data.restarted) {
|
||||
setItems(data.items || []);
|
||||
@@ -644,6 +676,7 @@ export function MailPicker({ context, placement, chapterId = "", chapterTitle =
|
||||
setItems([]);
|
||||
setNextBefore(null);
|
||||
setIncomplete(false);
|
||||
setContradictory(false);
|
||||
setNotice("");
|
||||
setSelectedKey("");
|
||||
setPreview(null);
|
||||
@@ -805,12 +838,14 @@ export function MailPicker({ context, placement, chapterId = "", chapterTitle =
|
||||
{accountId && !loading && !mailbox && !error ? <p className="muted">Dieses Konto hat keine lesbaren Fächer.</p> : null}
|
||||
{loading ? <p className="muted">{loading}</p> : null}
|
||||
{!loading && mailbox && !items.length && !error ? (
|
||||
<p className="muted">
|
||||
{incomplete
|
||||
? "In diesem Abschnitt gibt es keine Treffer. Die Suche ist noch nicht zu Ende."
|
||||
: query
|
||||
? "In diesem Fach gibt es dazu keine Nachricht."
|
||||
: "In diesem Fach gibt es keine Nachricht."}
|
||||
<p className={contradictory ? "notice" : "muted"}>
|
||||
{contradictory
|
||||
? "Das Fach meldet Nachrichten, aber es kam keine Liste an. Das Fach gilt deshalb nicht als leer."
|
||||
: incomplete
|
||||
? "In diesem Abschnitt gibt es keine Treffer. Die Suche ist noch nicht zu Ende."
|
||||
: query
|
||||
? "In diesem Fach gibt es dazu keine Nachricht."
|
||||
: "In diesem Fach gibt es keine Nachricht."}
|
||||
</p>
|
||||
) : null}
|
||||
<div className="mail-list">
|
||||
@@ -847,9 +882,7 @@ export function MailPicker({ context, placement, chapterId = "", chapterTitle =
|
||||
<MailFiles files={preview?.attachments || selected.attachments || []} />
|
||||
{previewError ? <p className="error">{previewError}</p> : null}
|
||||
{selected && !preview && !previewError ? <p className="muted">Vorschau wird geladen …</p> : null}
|
||||
{preview?.text ? <pre className="mail-letter__body">{preview.text}</pre> : null}
|
||||
{preview?.text_truncated ? <p className="muted">Der Text ist gekürzt, weil die Nachricht sehr groß ist.</p> : null}
|
||||
{preview && !preview.text ? <p className="muted">Diese Nachricht hat keinen lesbaren Text.</p> : null}
|
||||
{preview ? <MailBody html={preview.html} text={preview.text} truncated={preview.text_truncated} notices={preview.notices} /> : null}
|
||||
<ErrorNote error={error} />
|
||||
<button type="button" onClick={() => link(selected)} disabled={!selected.uid || adopting}>{adopting ? "Wird übernommen …" : "Übernehmen"}</button>
|
||||
</>
|
||||
|
||||
Reference in new issue
Block a user