get_emails_by_date_range
Retrieve iCloud emails from a specific date range by providing start and end dates, with options to filter by mailbox and limit results.
Instructions
Get emails between two dates
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| startDate | Yes | Start date (YYYY-MM-DD) | |
| endDate | Yes | End date (YYYY-MM-DD) | |
| mailbox | No | Mailbox (default INBOX) | |
| limit | No | Max results (default 10) |
Implementation Reference
- lib/imap.js:933-956 (handler)The implementation of get_emails_by_date_range which connects to IMAP, searches by date range, and fetches email details.
export async function getEmailsByDateRange(startDate, endDate, mailbox = 'INBOX', limit = 10, creds = null) { const client = createRateLimitedClient(creds); await client.connect(); await client.mailboxOpen(mailbox); const uids = (await client.search({ since: new Date(startDate), before: new Date(endDate) }, { uid: true })) ?? []; const total = uids.length; const recentUids = uids.slice(-limit).reverse(); const emails = []; for (const uid of recentUids) { const msg = await client.fetchOne(uid, { envelope: true, flags: true }, { uid: true }); if (msg) { emails.push({ uid, subject: msg.envelope.subject, from: msg.envelope.from?.[0]?.address, date: msg.envelope.date, flagged: msg.flags.has('\\Flagged'), seen: msg.flags.has('\\Seen') }); } } await client.logout(); return { total, showing: emails.length, emails }; }