Overview
Theimap_search_messages tool provides powerful search capabilities with cursor-based pagination for efficient retrieval of messages from large mailboxes.
Basic Search
Search Filters
Combine multiple filters to narrow your search:Text Search Filters
Search by query
Search by query
Full-text search across message content:
Filter by sender
Filter by sender
Search messages from specific senders:
Filter by recipient
Filter by recipient
Search messages sent to specific addresses:
Filter by subject
Filter by subject
Search by subject line:
Date Filters
Last N days
Last N days
Search messages from the last N days:
Date range
Date range
Search messages within a specific date range:
Dates must be in
YYYY-MM-DD format. start_date is inclusive, end_date is exclusive (before the date).Flag Filters
Unread messages only
Unread messages only
Filter to show only unread messages:
Combining Filters
Filters can be combined for precise searches:Message Snippets
Include message body snippets in search results for quick preview:Cursor-Based Pagination
For large result sets, use cursor pagination to retrieve messages in chunks:Search Result Structure
Each search returns consistent metadata and a list of message summaries:Field Descriptions
total- Total messages matching search criteriaattempted- Messages the server tried to fetch details forreturned- Messages successfully included in responsefailed- Messages that failed to fetch (seeissuesarray)next_cursor- Opaque cursor token for next pagehas_more- Boolean indicating more results available
Search Limits and Constraints
Maximum results per page
Maximum results per page
The
limit parameter accepts values from 1 to 50. Default is 10.Maximum total results
Maximum total results
Searches matching more than 20,000 messages will be rejected:Solution: Add more specific filters:
- Reduce
last_daysvalue - Add
from,to, orsubjectfilters - Use date ranges instead of
last_days
Cursor expiration
Cursor expiration
Cursors expire after the configured TTL (default: 300 seconds).Solution: Restart the search without a cursor.
Mailbox changes during pagination
Mailbox changes during pagination
If the mailbox UIDVALIDITY changes mid-pagination, you’ll receive a conflict error:Solution: Start a new search without a cursor. The mailbox was modified (messages deleted, mailbox rebuilt, etc.).
Common Search Patterns
Today's unread messages
Today's unread messages
All messages from a sender
All messages from a sender
Messages in date range with preview
Messages in date range with preview
Search all messages (paginated)
Search all messages (paginated)
Without filters, results are returned in reverse chronological order (newest first).
Performance Tips
Next Steps
Error Handling
Learn how to handle search errors and edge cases
API Reference
View complete search tool documentation