Overview
Search for messages in a specified mailbox with support for multiple filter criteria and efficient cursor-based pagination. Returns lightweight message summaries with optional body snippets.Input Parameters
Account identifier. Must match pattern
^[A-Za-z0-9_-]{1,64}$.Mailbox name to search (e.g.,
INBOX, Sent, Archive). Length must be 1-256 characters. Must not contain ASCII control characters.Opaque pagination cursor from a previous search response. Cannot be combined with any search criteria fields. When provided, resumes pagination from the saved search state.
Search Criteria
All search criteria fields are mutually exclusive with the
cursor parameter. Use either a cursor OR search criteria, not both.Full-text search query matching message body and headers. Length: 1-256 characters. Must not contain ASCII control characters.
Filter by From header. Length: 1-256 characters. Must not contain ASCII control characters.
Filter by To header. Length: 1-256 characters. Must not contain ASCII control characters.
Filter by Subject header. Length: 1-256 characters. Must not contain ASCII control characters.
When
true, returns only unread messages (IMAP UNSEEN flag).Date Filters
Filter to messages from the last N days. Range: 1-365. Cannot be combined with
start_date or end_date.Filter to messages on or after this date. Format:
YYYY-MM-DD. Must be less than or equal to end_date if both are provided.Filter to messages before this date (exclusive). Format:
YYYY-MM-DD. Must be greater than or equal to start_date if both are provided.Pagination and Display
Maximum messages to return per page. Range: 1-50.
When
true, includes a truncated subject preview in each message summary.Maximum snippet length. Range: 50-500. Only valid when
include_snippet=true.Output Data
Operation status:
ok (success), partial (some messages failed), or failed (operation failed).Array of diagnostic issues encountered during the operation.
Suggested next operation to perform.
Account identifier used for this search.
Mailbox name that was searched.
Total number of messages matching the search criteria.
Number of messages for which metadata fetch was attempted.
Number of messages successfully returned in this page.
Number of messages that failed to fetch metadata.
Array of message summaries (up to
limit messages).Opaque cursor for retrieving the next page. Present only when
has_more=true. Pass this value as the cursor parameter to retrieve the next page.Whether additional pages are available. When
true, use next_cursor to fetch the next page.Search Limits
The server enforces a maximum of 20,000 messages per search to prevent performance issues and excessive memory usage. If your search returns this error, refine your criteria using:- Date range filters (
start_date,end_date, orlast_days) - More specific text filters (
query,from,to,subject) - Smaller mailboxes or mailbox subfolders
Cursor Pagination
Cursor-based pagination provides efficient navigation through large result sets:- Initial Search: Call
imap_search_messageswith search criteria andlimit - Check
has_more: Iftrue, the response includes anext_cursor - Next Page: Call
imap_search_messageswith thecursorvalue (omit all search criteria) - Repeat: Continue using the new
next_cursoruntilhas_more=false
Cursor Behavior
- Cursors expire after a configured TTL (typically 5-15 minutes)
- Cursor store has a maximum entry limit (oldest cursors evicted first)
- Cursors are invalidated if mailbox UIDVALIDITY changes (returns
conflicterror) - Each cursor captures the search criteria and current page offset
Example: Search Recent Unread Messages
Example: Paginate with Cursor
Initial Request:Example: Search by Sender and Date Range
Validation Errors
Cursor with Search Criteria
Date Range Conflict
Too Many Results
Expired Cursor
UIDVALIDITY Mismatch
Related Tools
- imap_get_message - Retrieve full message details
- imap_list_mailboxes - List available mailboxes
- imap_get_message_raw - Get raw RFC822 source