pin_email
Pin or unpin an email to highlight important messages and keep them easily accessible in your inbox.
Instructions
Pin or unpin an email
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| emailId | Yes | ID of the email to pin/unpin | |
| pinned | No | true to pin, false to unpin |
Implementation Reference
- src/jmap-client.ts:776-800 (handler)The `pinEmail` method on JmapClient that executes the actual pin/unpin logic. It sends an Email/set JMAP request setting or removing the '$flagged' keyword on the email.
async pinEmail(emailId: string, pinned: boolean = true): Promise<void> { const session = await this.getSession(); const update: Record<string, any> = {}; update[emailId] = pinned ? { 'keywords/$flagged': true } : { 'keywords/$flagged': null }; const request: JmapRequest = { using: ['urn:ietf:params:jmap:core', 'urn:ietf:params:jmap:mail'], methodCalls: [ ['Email/set', { accountId: session.accountId, update }, 'pinEmail'] ] }; const response = await this.makeRequest(request); const result = this.getMethodResult(response, 0); if (result.notUpdated && result.notUpdated[emailId]) { throw new Error(`Failed to ${pinned ? 'pin' : 'unpin'} email.`); } } - src/index.ts:626-644 (schema)The input schema registration for the 'pin_email' tool in the ListTools handler, defining emailId (required string) and pinned (optional boolean, default true).
{ name: 'pin_email', description: 'Pin or unpin an email', inputSchema: { type: 'object', properties: { emailId: { type: 'string', description: 'ID of the email to pin/unpin', }, pinned: { type: 'boolean', description: 'true to pin, false to unpin', default: true, }, }, required: ['emailId'], }, }, - src/index.ts:1421-1436 (registration)The handler registration for 'pin_email' in the CallToolRequestSchema switch statement. Extracts emailId and pinned from args, calls client.pinEmail(), and returns success message.
case 'pin_email': { const { emailId, pinned = true } = args as any; if (!emailId) { throw new McpError(ErrorCode.InvalidParams, 'emailId is required'); } const client = initializeClient(); await client.pinEmail(emailId, pinned); return { content: [ { type: 'text', text: `Email ${pinned ? 'pinned' : 'unpinned'} successfully`, }, ], }; } - src/jmap-client.ts:1415-1441 (helper)The bulk variant `bulkPinEmails` that pins/unpins multiple emails in a single JMAP Email/set call using the '$flagged' keyword.
async bulkPinEmails(emailIds: string[], pinned: boolean = true): Promise<void> { const session = await this.getSession(); const updates: Record<string, any> = {}; emailIds.forEach(id => { updates[id] = pinned ? { 'keywords/$flagged': true } : { 'keywords/$flagged': null }; }); const request: JmapRequest = { using: ['urn:ietf:params:jmap:core', 'urn:ietf:params:jmap:mail'], methodCalls: [ ['Email/set', { accountId: session.accountId, update: updates }, 'bulkFlag'] ] }; 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 pin/unpin some emails.'); } }