Zeige den Bezug zwischen Schreiben und lies eine E-Mail vor dem Uebernehmen.
Die Liste behaelt die Schreiben dazwischen. Richtung, Absender, Empfaenger und Anhaenge bleiben an der Nachricht erkennbar. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
97bffc6175
commit
f27df3ff35
19 files changed
+1049
-49
No files matched your search
@@ -19,6 +19,7 @@ from app.sources import (
|
||||
delete_connector,
|
||||
imap_mailboxes,
|
||||
imap_messages,
|
||||
imap_preview,
|
||||
list_connectors,
|
||||
paperless_content,
|
||||
paperless_documents,
|
||||
@@ -70,7 +71,7 @@ def view_paperless(
|
||||
(element_id,),
|
||||
).fetchone()
|
||||
if ref is None or ref["source"] != "paperless":
|
||||
raise unprocessable("Nur ein Paperless-Dokument lässt sich hier ansehen.")
|
||||
raise unprocessable("Nur ein Paperless-Dokument lässt sich hier als Datei ansehen.")
|
||||
data, media_type, filename = paperless_content(conn, principal.account_id, ref["external_id"])
|
||||
safe_name = (filename or f"paperless-{ref['external_id']}.pdf").replace('"', "")
|
||||
return Response(
|
||||
@@ -84,6 +85,35 @@ def view_paperless(
|
||||
)
|
||||
|
||||
|
||||
@router.get("/api/v1/external-refs/{element_id}/mail")
|
||||
def view_mail(
|
||||
element_id: UUID,
|
||||
context_kind: str | None = None,
|
||||
context_id: str | None = None,
|
||||
principal: Principal = Depends(get_principal),
|
||||
conn: Connection = Depends(get_conn),
|
||||
):
|
||||
element = get_element(conn, element_id)
|
||||
if element is None or element["kind"] != "external_ref":
|
||||
raise not_found()
|
||||
rights = element_rights(conn, principal.account_id, element, parse_query_context(context_kind, context_id))
|
||||
if not rights.read:
|
||||
raise not_found()
|
||||
ref = conn.execute(
|
||||
"SELECT source, detail FROM external_references WHERE element_id = %s",
|
||||
(element_id,),
|
||||
).fetchone()
|
||||
detail = (ref or {}).get("detail") or {}
|
||||
if ref is None or ref["source"] != "imap":
|
||||
raise unprocessable("Das ist keine E-Mail.")
|
||||
connector_id = detail.get("connector_id")
|
||||
mailbox = detail.get("mailbox") or ""
|
||||
uid = detail.get("uid")
|
||||
if not connector_id or not mailbox or not uid:
|
||||
raise unprocessable("Für diese E-Mail ist keine Postfach-Vorschau hinterlegt.")
|
||||
return imap_preview(conn, principal.account_id, UUID(str(connector_id)), str(mailbox), int(uid))
|
||||
|
||||
|
||||
@router.get("/api/v1/sources/paperless/documents")
|
||||
def search_paperless(q: str = "", principal: Principal = Depends(get_principal), conn: Connection = Depends(get_conn)):
|
||||
return {"items": paperless_documents(conn, principal.account_id, q.strip())}
|
||||
@@ -112,6 +142,19 @@ def search_mail(
|
||||
return imap_messages(conn, principal.account_id, connector_id, q.strip(), mailbox.strip(), before)
|
||||
|
||||
|
||||
@router.get("/api/v1/sources/imap/message")
|
||||
def read_mail(
|
||||
connector_id: UUID,
|
||||
mailbox: str,
|
||||
uid: int,
|
||||
principal: Principal = Depends(get_principal),
|
||||
conn: Connection = Depends(get_conn),
|
||||
):
|
||||
if uid < 1:
|
||||
raise unprocessable("Die Nachricht ist ungültig.")
|
||||
return imap_preview(conn, principal.account_id, connector_id, mailbox.strip(), uid)
|
||||
|
||||
|
||||
@router.post("/api/v1/sources/link", status_code=201)
|
||||
def link_source(body: ExternalIn, principal: Principal = Depends(get_principal), conn: Connection = Depends(get_conn)):
|
||||
if body.source not in {"paperless", "imap"}:
|
||||
|
||||
Reference in new issue
Block a user