get_mailbox_stats
Retrieve mailbox statistics including unread count and total emails for a specific mailbox or all mailboxes.
Instructions
Get statistics for a mailbox (unread count, total emails, etc.)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| mailboxId | No | ID of the mailbox (optional, defaults to all mailboxes) |
Implementation Reference
- src/index.ts:826-838 (registration)Tool registration for 'get_mailbox_stats' in the ListToolsRequestSchema handler, defining the name, description, and input schema (optional mailboxId parameter).
{ name: 'get_mailbox_stats', description: 'Get statistics for a mailbox (unread count, total emails, etc.)', inputSchema: { type: 'object', properties: { mailboxId: { type: 'string', description: 'ID of the mailbox (optional, defaults to all mailboxes)', }, }, }, }, - src/index.ts:1612-1624 (handler)Handler for the 'get_mailbox_stats' tool in the CallToolRequestSchema switch. Extracts mailboxId from args, calls client.getMailboxStats(mailboxId), and returns the result JSON.
case 'get_mailbox_stats': { const { mailboxId } = args as any; const client = initializeClient(); const stats = await client.getMailboxStats(mailboxId); return { content: [ { type: 'text', text: JSON.stringify(stats, null, 2), }, ], }; } - src/jmap-client.ts:1326-1357 (helper)The actual business logic implementation in JmapClient.getMailboxStats(). If mailboxId is provided, calls Mailbox/get with specific properties (totalEmails, unreadEmails, totalThreads, unreadThreads). Otherwise, gets all mailboxes via getMailboxes() and maps to the stats structure.
async getMailboxStats(mailboxId?: string): Promise<any> { const session = await this.getSession(); if (mailboxId) { // Get stats for specific mailbox const request: JmapRequest = { using: ['urn:ietf:params:jmap:core', 'urn:ietf:params:jmap:mail'], methodCalls: [ ['Mailbox/get', { accountId: session.accountId, ids: [mailboxId], properties: ['id', 'name', 'role', 'totalEmails', 'unreadEmails', 'totalThreads', 'unreadThreads'] }, 'mailbox'] ] }; const response = await this.makeRequest(request); return this.getListResult(response, 0)[0]; } else { // Get stats for all mailboxes const mailboxes = await this.getMailboxes(); return mailboxes.map(mb => ({ id: mb.id, name: mb.name, role: mb.role, totalEmails: mb.totalEmails || 0, unreadEmails: mb.unreadEmails || 0, totalThreads: mb.totalThreads || 0, unreadThreads: mb.unreadThreads || 0 })); } }