Skip to main content
Glama
adamzaidi

icloud-mcp

by adamzaidi

empty_trash

Permanently delete all emails in the trash folder. Use dryRun to preview deletions first.

Instructions

Permanently delete all emails in the trash (Deleted Messages or Trash folder). Use dryRun: true to preview first.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dryRunNoIf true, preview how many emails would be deleted without deleting

Implementation Reference

  • The `emptyTrash` function searches common trash folders (e.g., "Deleted Messages", "Trash") and deletes all emails found within them. It supports a `dryRun` mode for testing.
    export async function emptyTrash(dryRun = false, creds = null) {
      const t0 = Date.now();
      // iCloud uses 'Deleted Messages'; Gmail uses '[Gmail]/Trash'; standard IMAP uses 'Trash'
      const trashFolders = ['Deleted Messages', '[Gmail]/Trash', 'Trash'];
      const client = createRateLimitedClient(creds);
      await client.connect();
    
      let mailbox = null;
      for (const folder of trashFolders) {
        try {
          await client.mailboxOpen(folder);
          mailbox = folder;
          break;
        } catch (err) {
          if (!err.message.includes('Mailbox does not exist') && !err.message.includes('NONEXISTENT') && !err.message.includes('does not exist')) {
            await safeClose(client);
            throw err;
          }
        }
      }
    
      if (!mailbox) {
        await safeClose(client);
        throw new Error('No trash folder found — tried: ' + trashFolders.join(', '));
      }
    
      const raw = await client.search({ all: true }, { uid: true });
      const uids = Array.isArray(raw) ? raw : [];
    
      if (dryRun) {
        await safeClose(client);
        return { dryRun: true, wouldDelete: uids.length, mailbox };
      }
    
      if (uids.length === 0) {
        await safeClose(client);
        return { deleted: 0, mailbox, timeTaken: ((Date.now() - t0) / 1000).toFixed(1) + 's' };
      }
    
      let deleted = 0;
      for (let i = 0; i < uids.length; i += CHUNK_SIZE) {
        const chunk = uids.slice(i, i + CHUNK_SIZE);
        await client.messageDelete(chunk, { uid: true });
        deleted += chunk.length;
      }
      await safeClose(client);
      return { deleted, mailbox, timeTaken: ((Date.now() - t0) / 1000).toFixed(1) + 's' };
    }

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