get_unread_senders
Identify top senders of unread emails in iCloud Mail to prioritize inbox management and focus on important messages.
Instructions
Get top senders of unread emails
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| mailbox | No | Mailbox to analyze (default INBOX) | |
| sampleSize | No | Number of emails to sample (default 500) | |
| maxResults | No | Max number of senders to return (default 20) |
Implementation Reference
- lib/imap.js:804-824 (handler)Implementation of the `get_unread_senders` tool handler, which connects to the mailbox, searches for unread emails, and calculates the top senders from those unread emails.
export async function getUnreadSenders(mailbox = 'INBOX', sampleSize = 500, maxResults = 20, creds = null) { const client = createRateLimitedClient(creds); await client.connect(); await client.mailboxOpen(mailbox); const uids = (await client.search({ seen: false }, { uid: true })) ?? []; const recentUids = uids.reverse().slice(0, sampleSize); const senderCounts = {}; if (recentUids.length === 0) { await client.logout(); return []; } for await (const msg of client.fetch(recentUids, { envelope: true }, { uid: true })) { const address = msg.envelope.from?.[0]?.address; if (address) senderCounts[address] = (senderCounts[address] || 0) + 1; } await client.logout(); return Object.entries(senderCounts).sort((a, b) => b[1] - a[1]).slice(0, maxResults).map(([address, count]) => ({ address, count })); }