fix(email): guard against IndexError when IMAP search returns empty list - #2289
Closed
Mibayy wants to merge 1 commit into
Closed
fix(email): guard against IndexError when IMAP search returns empty list#2289Mibayy wants to merge 1 commit into
Mibayy wants to merge 1 commit into
Conversation
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 NousResearch#2137
Contributor
|
Merged via PR #2466 — cherry-picked with authorship preserved. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
imap.uid('search')returnsdata=[]when the mailbox is empty or has no matching messages. Both call sites accesseddata[0]without checking whether the list was non-empty first, causingIndexError: list index out of range.Changes
gateway/platforms/email.py:connectmethod, ALL search):if status == "OK" and data[0]:→if status == "OK" and data and data[0]:_fetch_messagesmethod, UNSEEN search):if status != "OK" or not data[0]:→if status != "OK" or not data or not data[0]:Why
The IMAP spec allows
searchto succeed (status == "OK") with an empty result set (data == []). A fresh inbox or an inbox with no unread messages hits this path every time.Closes #2137