list_emails
Fetch emails from a mailbox, with optional parameters to specify mailbox ID, limit number of results, and sort by oldest first.
Instructions
List emails from a mailbox
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| mailboxId | No | ID of the mailbox to list emails from (optional, defaults to all) | |
| limit | No | Maximum number of emails to return (default: 20) | |
| ascending | No | Sort oldest first instead of newest first (default: false) |
Implementation Reference
- src/index.ts:146-166 (registration)Registration of the 'list_emails' tool: defines the tool name, description, and input schema (mailboxId, limit, ascending).
name: 'list_emails', description: 'List emails from a mailbox', inputSchema: { type: 'object', properties: { mailboxId: { type: 'string', description: 'ID of the mailbox to list emails from (optional, defaults to all)', }, limit: { type: ['number', 'string'], description: 'Maximum number of emails to return (default: 20)', default: 20, }, ascending: { type: 'boolean', description: 'Sort oldest first instead of newest first (default: false)', }, }, }, }, - src/index.ts:1012-1024 (handler)Handler for 'list_emails': extracts args (mailboxId, limit, ascending), clamps limit between 1-100, and calls client.getEmails().
case 'list_emails': { const { mailboxId, limit, ascending } = args as any; const validLimit = Math.min(Math.max(Number(limit) || 20, 1), 100); const emails = await client.getEmails(mailboxId, validLimit, !!ascending); return { content: [ { type: 'text', text: JSON.stringify(emails, null, 2), }, ], }; } - src/jmap-client.ts:156-180 (helper)The JmapClient.getEmails() method: builds JMAP Email/query and Email/get requests filtering by mailboxId, sorting by receivedAt, respecting limit/ascending, and returning email metadata.
async getEmails(mailboxId?: string, limit: number = 20, ascending: boolean = false): Promise<any[]> { const session = await this.getSession(); const filter = mailboxId ? { inMailbox: mailboxId } : {}; const request: JmapRequest = { using: ['urn:ietf:params:jmap:core', 'urn:ietf:params:jmap:mail'], methodCalls: [ ['Email/query', { accountId: session.accountId, filter, sort: [{ property: 'receivedAt', isAscending: ascending }], limit }, 'query'], ['Email/get', { accountId: session.accountId, '#ids': { resultOf: 'query', name: 'Email/query', path: '/ids' }, properties: ['id', 'subject', 'from', 'to', 'replyTo', 'receivedAt', 'preview', 'hasAttachment'] }, 'emails'] ] }; const response = await this.makeRequest(request); return this.getListResult(response, 1); }