archive_older_than
Move emails older than a specified number of days from a source mailbox to an archive folder using a safe copy-verify-delete process. Preview changes with dry run mode.
Instructions
Safely move emails older than N days from a source mailbox to an archive folder. Uses the same safe copy-verify-delete pipeline as bulk_move. Use dryRun: true to preview.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| days | Yes | Archive emails older than this many days | |
| targetMailbox | Yes | Destination archive folder (e.g. Archive) | |
| sourceMailbox | No | Source mailbox (default INBOX) | |
| dryRun | No | If true, preview what would be moved without moving |
Implementation Reference
- lib/imap.js:1063-1077 (handler)The handler function that implements the "archive_older_than" tool. It searches for emails older than a given number of days and moves them to a target mailbox.
export async function archiveOlderThan(days, targetMailbox, sourceMailbox = 'INBOX', dryRun = false, creds = null) { const client = createRateLimitedClient(creds); await client.connect(); await client.mailboxOpen(sourceMailbox); const date = new Date(); date.setDate(date.getDate() - days); const raw = await client.search({ before: date }, { uid: true }); const uids = Array.isArray(raw) ? raw : []; await client.logout(); if (dryRun) return { dryRun: true, wouldMove: uids.length, olderThan: date.toISOString(), sourceMailbox, targetMailbox }; if (uids.length === 0) return { moved: 0, olderThan: date.toISOString(), sourceMailbox, targetMailbox }; await ensureMailbox(targetMailbox, creds); const result = await safeMoveEmails(uids, sourceMailbox, targetMailbox, creds); return { ...result, olderThan: date.toISOString(), sourceMailbox, targetMailbox }; }