move_email
Move an email to a different mailbox by specifying the email ID and target mailbox ID.
Instructions
Move an email to a different mailbox
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| emailId | Yes | ID of the email to move | |
| targetMailboxId | Yes | ID of the target mailbox |
Implementation Reference
- src/index.ts:659-676 (registration)Registration of the 'move_email' tool in the ListTools handler, defining its name, description, and input schema (emailId and targetMailboxId, both required).
{ name: 'move_email', description: 'Move an email to a different mailbox', inputSchema: { type: 'object', properties: { emailId: { type: 'string', description: 'ID of the email to move', }, targetMailboxId: { type: 'string', description: 'ID of the target mailbox', }, }, required: ['emailId', 'targetMailboxId'], }, }, - src/index.ts:1455-1470 (handler)Handler for the 'move_email' tool in the CallToolRequestSchema switch statement. Validates required params, calls JmapClient.moveEmail(), and returns success message.
case 'move_email': { const { emailId, targetMailboxId } = args as any; if (!emailId || !targetMailboxId) { throw new McpError(ErrorCode.InvalidParams, 'emailId and targetMailboxId are required'); } const client = initializeClient(); await client.moveEmail(emailId, targetMailboxId); return { content: [ { type: 'text', text: 'Email moved successfully', }, ], }; } - src/jmap-client.ts:838-882 (helper)Core JMAP implementation of moveEmail. Fetches current mailboxIds, builds a patch to remove the email from all current mailboxes and add it to the target mailbox, then sends an Email/set update.
async moveEmail(emailId: string, targetMailboxId: string): Promise<void> { const session = await this.getSession(); // Fetch current mailboxIds to build a proper JMAP patch const getRequest: JmapRequest = { using: ['urn:ietf:params:jmap:core', 'urn:ietf:params:jmap:mail'], methodCalls: [ ['Email/get', { accountId: session.accountId, ids: [emailId], properties: ['mailboxIds'] }, 'getEmail'] ] }; const getResponse = await this.makeRequest(getRequest); const email = this.getListResult(getResponse, 0)[0]; // Build patch: remove from all current mailboxes, add to target const patch: Record<string, boolean | null> = {}; if (email?.mailboxIds) { for (const mbId of Object.keys(email.mailboxIds)) { patch[`mailboxIds/${mbId}`] = null; } } patch[`mailboxIds/${targetMailboxId}`] = true; const request: JmapRequest = { using: ['urn:ietf:params:jmap:core', 'urn:ietf:params:jmap:mail'], methodCalls: [ ['Email/set', { accountId: session.accountId, update: { [emailId]: patch } }, 'moveEmail'] ] }; const response = await this.makeRequest(request); const result = this.getMethodResult(response, 0); if (result.notUpdated && result.notUpdated[emailId]) { throw new Error('Failed to move email.'); } }