Skip to main content
Glama
adamzaidi

icloud-mcp

by adamzaidi

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
NameRequiredDescriptionDefault
startDateYesStart date (YYYY-MM-DD)
endDateYesEnd date (YYYY-MM-DD)
mailboxNoMailbox (default INBOX)
limitNoMax results (default 10)

Implementation Reference

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

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