moveEmail
Transfer emails between folders in Mail MCP Tool by specifying source and target locations with unique identifiers.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| uid | Yes | ||
| sourceFolder | Yes | ||
| targetFolder | Yes |
Implementation Reference
- src/tools/mail.ts:885-918 (registration)Registration of the 'moveEmail' MCP tool including schema definition and handler function that validates input and delegates to MailService.moveMail, returning success/failure messages.this.server.tool( "moveEmail", { uid: z.number(), sourceFolder: z.string(), targetFolder: z.string() }, async ({ uid, sourceFolder, targetFolder }) => { try { const numericUid = Number(uid); const success = await this.mailService.moveMail(numericUid, sourceFolder, targetFolder); if (success) { return { content: [ { type: "text", text: `邮件(UID: ${numericUid})已成功从"${sourceFolder}"移动到"${targetFolder}"文件夹` } ] }; } else { return { content: [ { type: "text", text: `移动邮件(UID: ${numericUid})失败` } ] }; } } catch (error) { return { content: [ { type: "text", text: `移动邮件时发生错误: ${error instanceof Error ? error.message : String(error)}` } ] }; } } );
- src/tools/mail.ts:888-890 (schema)Zod input schema for moveEmail tool: uid (number), sourceFolder (string), targetFolder (string).uid: z.number(), sourceFolder: z.string(), targetFolder: z.string()
- src/tools/mail.ts:892-917 (handler)Handler function for moveEmail tool that executes the move operation via mailService and formats the response.async ({ uid, sourceFolder, targetFolder }) => { try { const numericUid = Number(uid); const success = await this.mailService.moveMail(numericUid, sourceFolder, targetFolder); if (success) { return { content: [ { type: "text", text: `邮件(UID: ${numericUid})已成功从"${sourceFolder}"移动到"${targetFolder}"文件夹` } ] }; } else { return { content: [ { type: "text", text: `移动邮件(UID: ${numericUid})失败` } ] }; } } catch (error) { return { content: [ { type: "text", text: `移动邮件时发生错误: ${error instanceof Error ? error.message : String(error)}` } ] }; } }
- src/tools/mail-service.ts:606-628 (helper)Core implementation of email moving logic in MailService using IMAP client: opens source folder and calls imapClient.move(uid, targetFolder).async moveMail(uid: number | string, sourceFolder: string, targetFolder: string): Promise<boolean> { await this.connectImap(); // 确保 uid 为数字类型 const numericUid = typeof uid === 'string' ? parseInt(uid, 10) : uid; return new Promise((resolve, reject) => { this.imapClient.openBox(sourceFolder, false, (err) => { if (err) { reject(err); return; } this.imapClient.move(numericUid, targetFolder, (err) => { if (err) { reject(err); return; } resolve(true); }); }); }); }