Skip to main content
Glama
adamzaidi

icloud-mcp

by adamzaidi

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
NameRequiredDescriptionDefault
mailboxNoMailbox to analyze (default INBOX)
sampleSizeNoNumber of emails to sample (default 500)
maxResultsNoMax number of senders to return (default 20)

Implementation Reference

  • 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 }));
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/adamzaidi/icloud-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server