@@ -25,6 +25,7 @@ Despite requesting only 5 emails per page, the internal flow is:
2525```
2626
2727** Pagination only applies AFTER the expensive operations.** This means:
28+
2829- On a mailbox with 10,000 emails: seconds of delay
2930- On a mailbox with 100,000+ emails: minutes or timeout
3031- On enterprise mailboxes: can hang indefinitely
@@ -44,25 +45,30 @@ There's no built-in way to limit results before the search phase.
4445### ✅ Fast Searches
4546
4647#### 1. Date Range (Fastest)
48+
4749``` python
4850# Get last 30 days of emails
4951from datetime import datetime, timedelta
5052since = datetime.now() - timedelta(days = 30 )
5153result = list_emails_metadata(account_name = " Galaxia" , since = since)
5254```
55+
5356** Why:** IMAP servers heavily index by date. Returns only recent emails.
5457
5558#### 2. Text Search (Medium Speed)
59+
5660``` python
5761# Search for specific sender
5862result = list_emails_metadata(
5963 account_name = " Galaxia" ,
6064 from_address = " boss@company.com"
6165)
6266```
67+
6368** Why:** Text searches use server indices, but could match many emails.
6469
6570#### 3. Combined Filters (Fastest & Best)
71+
6672``` python
6773# Search for work emails from last month
6874since = datetime.now() - timedelta(days = 30 )
@@ -73,9 +79,11 @@ result = list_emails_metadata(
7379 since = since
7480)
7581```
82+
7683** Why:** Narrows search space at IMAP level (most efficient).
7784
7885#### 4. Flag-Based Search
86+
7987``` python
8088# Get unread emails from the last 7 days
8189since = datetime.now() - timedelta(days = 7 )
@@ -85,18 +93,19 @@ result = list_emails_metadata(
8593 since = since
8694)
8795```
96+
8897** Why:** Flag searches are fast; combining with date range is best.
8998
9099## Performance Comparison
91100
92- | Query | Mailbox Size | Time |
93- | -------| --------------| ------|
94- | ` SEARCH ALL ` | 10,000 emails | ~ 1 second |
95- | ` SEARCH ALL ` | 100,000 emails | ~ 10+ seconds |
96- | ` SEARCH ALL ` | 1,000,000 emails | ** TIMEOUT** |
97- | ` SEARCH SINCE <date> ` | Any size | ~ 100ms |
98- | ` SEARCH FROM "sender" ` | 100,000 emails | ~ 500ms |
99- | ` SEARCH SINCE + FROM ` | 100,000 emails | ~ 100ms |
101+ | Query | Mailbox Size | Time |
102+ | ---------------------- | ---------------- | ------------ |
103+ | ` SEARCH ALL ` | 10,000 emails | ~ 1 second |
104+ | ` SEARCH ALL ` | 100,000 emails | ~ 10+ seconds |
105+ | ` SEARCH ALL ` | 1,000,000 emails | ** TIMEOUT** |
106+ | ` SEARCH SINCE <date> ` | Any size | ~ 100ms |
107+ | ` SEARCH FROM "sender" ` | 100,000 emails | ~ 500ms |
108+ | ` SEARCH SINCE + FROM ` | 100,000 emails | ~ 100ms |
100109
101110## Error Message Explanation
102111
@@ -110,6 +119,7 @@ Example: since=datetime(2026, 1, 1) or subject='work' + since=datetime(2025, 1,
110119```
111120
112121This error prevents:
122+
113123- Silent performance degradation
114124- Unexplained timeouts
115125- User frustration with "why is this so slow?"
@@ -147,11 +157,13 @@ All filters prevent full mailbox scans:
147157If you were using unfiltered searches before:
148158
149159### Before (Would fail now)
160+
150161``` python
151162result = list_emails_metadata(account_name = " Galaxia" )
152163```
153164
154165### After
166+
155167``` python
156168from datetime import datetime, timedelta
157169
0 commit comments