From f3301a31d52253e76bc643c7197490f4857e3c40 Mon Sep 17 00:00:00 2001 From: Hermes Date: Sat, 21 Mar 2026 10:16:06 +0000 Subject: [PATCH] fix(email): guard against IndexError when IMAP search returns empty list imap.uid('search') can return data=[] when the mailbox is empty or has no matching messages. Accessing data[0] without checking len first raises IndexError: list index out of range. Fixed at both call sites in gateway/platforms/email.py: - Line 233 (connect): ALL search on startup - Line 298 (fetch): UNSEEN search in the polling loop Closes #2137 --- gateway/platforms/email.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gateway/platforms/email.py b/gateway/platforms/email.py index 04841278..ec44c60e 100644 --- a/gateway/platforms/email.py +++ b/gateway/platforms/email.py @@ -230,7 +230,7 @@ class EmailAdapter(BasePlatformAdapter): # Mark all existing messages as seen so we only process new ones imap.select("INBOX") status, data = imap.uid("search", None, "ALL") - if status == "OK" and data[0]: + if status == "OK" and data and data[0]: for uid in data[0].split(): self._seen_uids.add(uid) imap.logout() @@ -295,7 +295,7 @@ class EmailAdapter(BasePlatformAdapter): imap.select("INBOX") status, data = imap.uid("search", None, "UNSEEN") - if status != "OK" or not data[0]: + if status != "OK" or not data or not data[0]: imap.logout() return results