get_recent_emails
Retrieve the most recent emails from your Fastmail inbox or specified mailbox. Control the number of emails returned and sort order to quickly access recent correspondence.
Instructions
Get the most recent emails from inbox (like top-ten)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Number of recent emails to retrieve (default: 10, max: 50) | |
| mailboxName | No | Mailbox to search (default: inbox) | inbox |
| ascending | No | Sort oldest first instead of newest first (default: false) |
Implementation Reference
- src/jmap-client.ts:715-748 (handler)The actual implementation of get_recent_emails in JmapClient class. Calls JMAP API to find the target mailbox by role/name, then queries emails sorted by receivedAt, returning id/subject/from/to/replyTo/receivedAt/preview/hasAttachment/keywords/List-Unsubscribe.
async getRecentEmails(limit: number = 10, mailboxName: string = 'inbox', ascending: boolean = false): Promise<any[]> { const session = await this.getSession(); // Find the specified mailbox (default to inbox) const mailboxes = await this.getMailboxes(); const targetMailbox = mailboxes.find(mb => mb.role === mailboxName.toLowerCase() || mb.name.toLowerCase().includes(mailboxName.toLowerCase()) ); if (!targetMailbox) { throw new Error(`Could not find mailbox: ${mailboxName}`); } const request: JmapRequest = { using: ['urn:ietf:params:jmap:core', 'urn:ietf:params:jmap:mail'], methodCalls: [ ['Email/query', { accountId: session.accountId, filter: { inMailbox: targetMailbox.id }, sort: [{ property: 'receivedAt', isAscending: ascending }], limit: Math.min(limit, 50) }, 'query'], ['Email/get', { accountId: session.accountId, '#ids': { resultOf: 'query', name: 'Email/query', path: '/ids' }, properties: ['id', 'subject', 'from', 'to', 'replyTo', 'receivedAt', 'preview', 'hasAttachment', 'keywords', 'header:List-Unsubscribe:asURLs'] }, 'emails'] ] }; const response = await this.makeRequest(request); return this.getListResult(response, 1); } - src/index.ts:585-605 (schema)Schema definition for the get_recent_emails tool, defining input parameters: limit (number/string, default 10, max 50), mailboxName (string, default 'inbox'), ascending (boolean, default false).
name: 'get_recent_emails', description: 'Get the most recent emails from inbox (like top-ten)', inputSchema: { type: 'object', properties: { limit: { type: ['number', 'string'], description: 'Number of recent emails to retrieve (default: 10, max: 50)', default: 10, }, mailboxName: { type: 'string', description: 'Mailbox to search (default: inbox)', default: 'inbox', }, ascending: { type: 'boolean', description: 'Sort oldest first instead of newest first (default: false)', }, }, }, - src/index.ts:1390-1402 (registration)Registration/handler dispatch for get_recent_emails in the CallToolRequestSchema handler. Extracts args (limit, mailboxName, ascending), calls client.getRecentEmails(), and returns JSON result.
case 'get_recent_emails': { const { limit = 10, mailboxName = 'inbox', ascending } = args as any; const client = initializeClient(); const emails = await client.getRecentEmails(limit, mailboxName, !!ascending); return { content: [ { type: 'text', text: JSON.stringify(emails, null, 2), }, ], }; }