Fix email fetch reliability for large emails with attachments

- Add 120s IMAP socket timeout (was unlimited, could hang on large emails)
- Increase Paperless upload timeout from 60s to 300s for large attachments
- Increase manual poll UI timeout from 60s to 300s
- Show error count in UI when emails fail to process
- Log warning when attachment payload is empty/corrupted

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
SysAdmin Agent
2026-03-11 21:21:17 +00:00
parent 2a7c9d8529
commit 83cf2798b1
2 changed files with 20 additions and 7 deletions

View File

@@ -137,7 +137,7 @@ def _upload_to_paperless(content: bytes, filename: str, destinataer=None, betref
headers=headers,
data=form_data,
files=files,
timeout=60,
timeout=300, # 5 Minuten für große Anhänge
)
response.raise_for_status()
# Paperless gibt die neue Dokument-ID zurück (als Integer oder UUID-String)
@@ -196,11 +196,12 @@ def poll_destinataer_emails(self, search_all_recent_days=0):
errors = 0
try:
# IMAP-Verbindung aufbauen
# IMAP-Verbindung aufbauen (mit Socket-Timeout für große E-Mails)
imap_timeout = 120 # Sekunden genug für große Anhänge
if imap_use_ssl:
mail = imaplib.IMAP4_SSL(imap_host, imap_port)
mail = imaplib.IMAP4_SSL(imap_host, imap_port, timeout=imap_timeout)
else:
mail = imaplib.IMAP4(imap_host, imap_port)
mail = imaplib.IMAP4(imap_host, imap_port, timeout=imap_timeout)
mail.login(imap_user, imap_password)
mail.select(imap_folder)
@@ -279,6 +280,10 @@ def poll_destinataer_emails(self, search_all_recent_days=0):
filename = _decode_header_value(part.get_filename() or "")
content = part.get_payload(decode=True)
if not content:
logger.warning(
"Anhang '%s' hat keinen Inhalt (möglicherweise zu groß oder beschädigt) wird übersprungen.",
filename,
)
continue
doc_id = _upload_to_paperless(