fix(email): don't probe IMAP for send-only (SMTP-only) accounts (#4830)

An account configured with SMTP only (no imap_host) has no inbox, but the
inbox list path still called _imap_connect, which handed an empty host to
imaplib. imaplib.IMAP4("", 993) silently dials localhost:993 and fails with
"[Errno 111] Connection refused", so the email panel's poll logged a
"Failed to list emails" ERROR every ~60s and surfaced a scary error in the UI.

_imap_connect now fails fast with a typed EmailNotConfiguredError (subclass of
RuntimeError, so existing broad handlers keep working) when no imap_host is set,
and the inbox list returns an empty result for that case instead of an error.
SMTP send is unaffected.
This commit is contained in:
Ricardo
2026-06-27 22:52:26 +02:00
committed by GitHub
parent 20cf323ca4
commit 3b4187e25d
3 changed files with 99 additions and 0 deletions
+6
View File
@@ -46,6 +46,7 @@ from routes.email_helpers import (
_send_smtp_message, _smtp_security_mode,
_IMAP_TIMEOUT_SECONDS, _open_imap_connection,
make_oauth_state, verify_oauth_state,
EmailNotConfiguredError,
_imap_connect, _imap, _decode_header, _detect_sent_folder, _detect_drafts_folder,
_extract_attachment_text, _list_attachments_from_msg, _has_visible_attachments, _is_likely_signature_image_attachment,
_extract_attachment_to_disk, _extract_html, _extract_text,
@@ -1029,6 +1030,11 @@ def setup_email_routes():
logger.debug(f"Bulk summary attach skipped: {_summary_err}")
return {"emails": emails, "total": total, "folder": folder, "offset": offset}
except EmailNotConfiguredError:
# Send-only (SMTP-only) account: there is no inbox to read, so the
# poll returns an empty list instead of a per-minute error. SMTP
# send is unaffected.
return {"emails": [], "total": 0, "folder": folder, "offset": offset}
except Exception as e:
logger.error(f"Failed to list emails: {e}")
detail = str(e).strip()