Skip to main content
Glama
adamzaidi

icloud-mcp

by adamzaidi

get_top_senders

Analyze email patterns by identifying the most frequent senders in your iCloud inbox using configurable sampling and result limits.

Instructions

Get the top senders by email count from a sample of the inbox

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
mailboxNoMailbox to analyze (default INBOX)
sampleSizeNoNumber of emails to sample (default 500)
maxResultsNoMax number of senders/domains to return (default 20)

Implementation Reference

  • The implementation of the get_top_senders tool, which fetches recent emails from a mailbox, aggregates senders and domains by frequency, and returns the top results.
    export async function getTopSenders(mailbox = 'INBOX', sampleSize = 500, maxResults = 20, creds = null) {
      const client = createRateLimitedClient(creds);
      await client.connect();
      const mb = await client.mailboxOpen(mailbox);
      const total = mb.exists;
      const senderCounts = {};
      const senderDomains = {};
    
      const end = total;
      const start = Math.max(1, total - sampleSize + 1);
      const range = `${start}:${end}`;
      let count = 0;
    
      for await (const msg of client.fetch(range, { envelope: true })) {
        const address = msg.envelope.from?.[0]?.address;
        if (address) {
          senderCounts[address] = (senderCounts[address] || 0) + 1;
          const domain = address.split('@')[1];
          if (domain) senderDomains[domain] = (senderDomains[domain] || 0) + 1;
        }
        count++;
      }
    
      await client.logout();
      const topAddresses = Object.entries(senderCounts).sort((a, b) => b[1] - a[1]).slice(0, maxResults).map(([address, count]) => ({ address, count }));
      const topDomains = Object.entries(senderDomains).sort((a, b) => b[1] - a[1]).slice(0, maxResults).map(([domain, count]) => ({ domain, count }));
      return { sampledEmails: count, topAddresses, topDomains };
    }

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