Unterscheide Eingang und Ausgang an der Einbindung und ermoegliche Umbenennen, Archivieren, Loeschen und Verschieben.
Deploy Development / deploy (push) Successful in 26s
Test Suite / pytest-backend (push) Successful in 1m4s
Test Suite / smoke-dev (push) Successful in 0s
Test Suite / frontend-build (push) Successful in 8s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-10-17 18:30:26 +02:00
1 parent 20625b4596
commit ad6240a5da
27 files changed
+1191 -88

No files matched your search

+59 -6
View File
@@ -508,8 +508,8 @@ def _fetch_message(client: imaplib.IMAP4, uid: int, mailbox: str) -> dict:
raw = _literal(fetched)
if status != "OK" or raw is None:
raise unprocessable("Die Nachricht lässt sich nicht lesen.")
if len(raw) > 1_500_000:
raise unprocessable("Die Nachricht ist zu groß für die Vorschau.")
if len(raw) > 8_000_000:
return _oversized_message(client, uid, mailbox)
message = BytesParser().parsebytes(raw)
subject = _decode(message.get("Subject")) or "(ohne Betreff)"
return {
@@ -522,7 +522,8 @@ def _fetch_message(client: imaplib.IMAP4, uid: int, mailbox: str) -> dict:
"direction": _direction(mailbox),
"document_on": _mail_date(message.get("Date")),
"attachments": _message_attachments(message),
"text": _message_text(message),
"text": (_text := _message_text(message))[:200_000],
"text_truncated": len(_text) > 200_000,
}
@@ -532,9 +533,61 @@ _SENT_FOLDER = re.compile(
)
def _direction(mailbox: str) -> str:
_INBOX_FOLDER = re.compile(
r"(^|/)(inbox|posteingang|eingang)($|/)",
re.IGNORECASE,
)
def _direction(mailbox: str) -> str | None:
"""Sent folders are outgoing, an inbox is incoming. Other folder names prove nothing."""
folded = mailbox.casefold().replace("\\", "/")
return "out" if _SENT_FOLDER.search(folded) else "in"
if _SENT_FOLDER.search(folded):
return "out"
if _INBOX_FOLDER.search(folded):
return "in"
return None
def _oversized_message(client: imaplib.IMAP4, uid: int, mailbox: str) -> dict:
header = _fetch_header(client, uid, mailbox) or {}
text = _partial_text(client, uid)
if not header and not text:
raise unprocessable("Die Nachricht lässt sich nicht lesen.")
return {
"uid": uid,
"mailbox": mailbox,
"title": header.get("title") or "(ohne Betreff)",
"message_from": header.get("message_from") or "",
"message_to": header.get("message_to") or "",
"message_cc": header.get("message_cc") or "",
"direction": header.get("direction", _direction(mailbox)),
"document_on": header.get("document_on"),
"attachments": header.get("attachments") or [],
"text": text,
"text_truncated": True,
}
def _partial_text(client: imaplib.IMAP4, uid: int) -> str:
try:
status, fetched = client.uid("FETCH", str(uid), "(BODY.PEEK[TEXT]<0.200000>)")
except imaplib.IMAP4.error:
return ""
if status != "OK":
return ""
raw = _literal(fetched)
if not raw:
return ""
sample = raw[:200_000]
try:
message = BytesParser().parsebytes(b"Subject: x\r\n\r\n" + sample)
text = _message_text(message)
except Exception:
text = ""
if not text:
text = sample.decode("utf-8", errors="replace")
return text.strip()[:200_000]
def _literal(fetched) -> bytes | None:
@@ -598,7 +651,7 @@ def _message_text(message) -> str:
text = "\n".join(chunk for chunk in plain if chunk).strip()
if not text:
text = "\n".join(chunk for chunk in html if chunk).strip()
return text[:8000]
return text
def _part_text(part) -> str: