delete_older_than
Remove emails older than a specified number of days from iCloud Mail to manage storage and organize your inbox by automatically clearing outdated messages.
Instructions
Delete all emails older than a certain number of days
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| days | Yes | Delete emails older than this many days | |
| mailbox | No | Mailbox (default INBOX) |
Implementation Reference
- lib/imap.js:915-931 (handler)Handler function for deleting emails older than a specified number of days in a given mailbox.
export async function deleteOlderThan(days, mailbox = 'INBOX', creds = null) { const client = createRateLimitedClient(creds); await client.connect(); await client.mailboxOpen(mailbox); const date = new Date(); date.setDate(date.getDate() - days); const uids = (await client.search({ before: date }, { uid: true })) ?? []; if (uids.length === 0) { await client.logout(); return { deleted: 0 }; } 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 client.logout(); return { deleted, olderThan: date.toISOString() }; }