bulk_move
Move multiple emails to a specified mailbox using their IDs and the target mailbox ID.
Instructions
Move multiple emails to a mailbox
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| emailIds | Yes | Array of email IDs to move | |
| targetMailboxId | Yes | ID of target mailbox |
Implementation Reference
- src/index.ts:885-901 (schema)Schema registration for the 'bulk_move' tool. Defines input parameters: emailIds (array of strings, required) and targetMailboxId (string, required).
name: 'bulk_move', description: 'Move multiple emails to a mailbox', inputSchema: { type: 'object', properties: { emailIds: { type: 'array', items: { type: 'string' }, description: 'Array of email IDs to move', }, targetMailboxId: { type: 'string', description: 'ID of target mailbox', }, }, required: ['emailIds', 'targetMailboxId'], }, - src/index.ts:1670-1688 (handler)Handler for the 'bulk_move' tool call. Validates arguments (emailIds array and targetMailboxId), then delegates to client.bulkMove(). Returns success message with count of moved emails.
case 'bulk_move': { const { emailIds, targetMailboxId } = args as any; if (!emailIds || !Array.isArray(emailIds) || emailIds.length === 0) { throw new McpError(ErrorCode.InvalidParams, 'emailIds array is required and must not be empty'); } if (!targetMailboxId) { throw new McpError(ErrorCode.InvalidParams, 'targetMailboxId is required'); } const client = initializeClient(); await client.bulkMove(emailIds, targetMailboxId); return { content: [ { type: 'text', text: `${emailIds.length} emails moved successfully`, }, ], }; } - src/jmap-client.ts:1443-1489 (handler)Core implementation of bulkMove() in JmapClient. Fetches current mailboxIds for all emails, builds JMAP patches to remove from current mailboxes and add to target, and sends a single Email/set JMAP request.
async bulkMove(emailIds: string[], targetMailboxId: string): Promise<void> { const session = await this.getSession(); // Fetch current mailboxIds for all emails to build proper JMAP patches const getRequest: JmapRequest = { using: ['urn:ietf:params:jmap:core', 'urn:ietf:params:jmap:mail'], methodCalls: [ ['Email/get', { accountId: session.accountId, ids: emailIds, properties: ['id', 'mailboxIds'] }, 'getEmails'] ] }; const getResponse = await this.makeRequest(getRequest); const emails: any[] = this.getListResult(getResponse, 0); const mailboxMap: Record<string, Record<string, boolean>> = {}; emails.forEach((e: any) => { mailboxMap[e.id] = e.mailboxIds || {}; }); // Build patch per email: remove all current mailboxes, add target const updates: Record<string, any> = {}; emailIds.forEach(id => { const patch: Record<string, boolean | null> = {}; for (const mbId of Object.keys(mailboxMap[id] || {})) { patch[`mailboxIds/${mbId}`] = null; } patch[`mailboxIds/${targetMailboxId}`] = true; updates[id] = patch; }); const request: JmapRequest = { using: ['urn:ietf:params:jmap:core', 'urn:ietf:params:jmap:mail'], methodCalls: [ ['Email/set', { accountId: session.accountId, update: updates }, 'bulkMove'] ] }; const response = await this.makeRequest(request); const result = this.getMethodResult(response, 0); if (result.notUpdated && Object.keys(result.notUpdated).length > 0) { throw new Error('Failed to move some emails.'); } }