Files
legal-shield/shield/paperless.py
T
mmintelandClaude Opus 5.5 81c8633f73 MCP aufgeteilt: post, mail, paperless als eigene Server (butler/); Legal Shield gibt mit letter_release frei
- butler/briefpost.py: LetterXpress, PDF-Prüfung (A4, Schriften, Anschrift aus dem Fensterfeld), Protokoll –
  ohne Fallbezug. shield/post.py behält nur die Freigabe (sperren) und nutzt diese Schicht.
- butler/post_server.py: post_check / post_send (confirm = PDF-Hash) / post_status; nur PDFs aus $POST_OUTBOX,
  höchstens $POST_MAX_AGE_HOURS alt; eigenes Protokoll nach PDF-Hash sperrt Doppelversand.
- butler/mail_server.py, butler/paperless_server.py: nur lesend (Community-Server haben Schreib-/Löschwerkzeuge).
- legal-shield: send_*, mail_*, paperless_* entfernt; letter_release (CLI: release) legt nur ein freies
  Schreiben in den Postausgang, zieht bei Sperre frühere Freigaben zurück und sperrt nach Versand über post.
- brief.py: PDF reproduzierbar (kein Zufalls-ID/Datum) – sonst passt der Prüfcode von send --confirm nie.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 11:28:27 +02:00

39 lines
1.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Paperless-ngx: OCR-Texte der im Fall referenzierten Dokumente in den lokalen Cache holen."""
from __future__ import annotations
import urllib.request
from pathlib import Path
from butler.paperless import _env, _get, fetch_content, suchen # noqa: F401 (Legal Shield nutzt dieselben Zugriffe)
def fetch_all(doc_ids: set[int], cache_dir: Path, force: bool = False) -> list[int]:
cache_dir.mkdir(parents=True, exist_ok=True)
fetched = []
for doc_id in sorted(doc_ids):
path = cache_dir / f"{doc_id}.txt"
if path.exists() and not force:
continue
path.write_text(fetch_content(doc_id), encoding="utf-8")
fetched.append(doc_id)
return fetched
def fetch_pdfs(doc_ids: set[int], cache_dir: Path, force: bool = False) -> list[int]:
"""Archivfassung (PDF mit OCR-Textebene) für die Beweismappe – Seiten werden daraus kopiert und markiert."""
cache_dir.mkdir(parents=True, exist_ok=True)
fetched = []
for doc_id in sorted(doc_ids):
path = cache_dir / f"{doc_id}.pdf"
if path.exists() and not force:
continue
url = f"{_env('PAPERLESS_URL').rstrip('/')}/api/documents/{doc_id}/download/"
req = urllib.request.Request(url, headers={"Authorization": f"Token {_env('PAPERLESS_TOKEN')}"})
with urllib.request.urlopen(req, timeout=300) as resp:
daten = resp.read()
if not daten.startswith(b"%PDF"):
raise SystemExit(f"Paperless #{doc_id}: Download ist kein PDF")
path.write_bytes(daten)
fetched.append(doc_id)
return fetched