move mails without Message-ID; log the reason for failed actions
A spam mail matched stefanhacker@gmx.de but "Aktion fehlgeschlagen" every time: it has no Message-ID header, and the safe move refused to proceed because it verifies the copy by Message-ID. So every mail without that header stayed in INBOX forever, and the log didn't say why. Verification now falls back when there is no Message-ID: - COPYUID from the COPY response when the server supports UIDPLUS - otherwise count mails in the target with the same exact size and sender before and after COPY; exactly one more means it arrived The source is still only flagged/expunged after verification, and move_mail now refuses to run without source_folder (the verification selects the target, so STORE could otherwise hit the wrong folder). Checked against a simulated IMAP server for success, rejected COPY, copy not arriving, and missing source folder. IMAPClient.last_error carries the reason (rejected COPY with server text, copy not found incl. how it was checked, missing target folder, no SMTP config, ...); the scheduler appends it to the log message. "Fehlgeschlagene neu einlesen" now also retries failed actions, not only fetch errors. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from sqlalchemy import func, text
|
||||
from sqlalchemy import func, or_, text
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
import logging
|
||||
@@ -92,13 +92,17 @@ def reset_all_processed(db: Session = Depends(get_db)):
|
||||
|
||||
@router.post("/retry-failed")
|
||||
def retry_failed_fetches(account_id: int | None = None, db: Session = Depends(get_db)):
|
||||
"""Löscht ProcessedMail-Einträge für UIDs, für die es einen ERROR-Log
|
||||
mit 'Fehler beim Abrufen' gibt — damit der Scheduler sie beim nächsten
|
||||
Poll neu versucht (z.B. nach einem Codec-Fix)."""
|
||||
"""Löscht ProcessedMail-Einträge für UIDs, bei denen das Abrufen oder eine
|
||||
Aktion (z.B. Verschieben) fehlgeschlagen ist — damit der Scheduler sie beim
|
||||
nächsten Poll neu versucht (z.B. nach einem Fix). Schon verschobene Mails
|
||||
liegen nicht mehr im Quellordner und werden daher nicht doppelt verarbeitet."""
|
||||
try:
|
||||
log_q = db.query(FilterLog.mail_uid, FilterLog.account_id).filter(
|
||||
FilterLog.level == LogLevel.ERROR,
|
||||
FilterLog.message.like("Fehler beim Abrufen%"),
|
||||
or_(
|
||||
FilterLog.message.like("Fehler beim Abrufen%"),
|
||||
FilterLog.message.like("Aktion fehlgeschlagen%"),
|
||||
),
|
||||
FilterLog.mail_uid.isnot(None),
|
||||
)
|
||||
if account_id is not None:
|
||||
|
||||
Reference in New Issue
Block a user