mailosaur_files_get_email
Download an email message as an EML file encoded in base64 for offline access or raw content analysis.
Instructions
Download a message as an EML file. Returns base64 content.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| messageId | Yes |
Implementation Reference
- src/index.ts:337-352 (registration)Registration of the 'mailosaur_files_get_email' tool via server.tool(), which defines its name, description, schema, and handler.
server.tool( "mailosaur_files_get_email", "Download a message as an EML file. Returns base64 content.", { messageId: z.string() }, async ({ messageId }) => { const file = await mailosaur.files.getEmail(messageId); return response({ messageId, contentType: "message/rfc822", encoding: "base64", content: await toBase64(file) }); } ); - src/index.ts:340-342 (schema)Input schema for the tool: requires a single 'messageId' field (z.string()).
{ messageId: z.string() }, - src/index.ts:343-351 (handler)Handler function that calls mailosaur.files.getEmail(messageId) and returns the result as base64 content with contentType 'message/rfc822'.
async ({ messageId }) => { const file = await mailosaur.files.getEmail(messageId); return response({ messageId, contentType: "message/rfc822", encoding: "base64", content: await toBase64(file) }); } - src/index.ts:79-88 (helper)The 'response()' helper used to format the tool's return value as JSON text content.
function response(value: unknown) { return { content: [ { type: "text" as const, text: JSON.stringify(value, null, 2) } ] }; } - src/index.ts:100-115 (helper)The 'toBase64()' helper that converts a Readable stream, Buffer, Uint8Array, or string to a base64 string.
async function toBase64(file: unknown) { if (file instanceof Readable) { const chunks: Buffer[] = []; for await (const chunk of file) { chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk)); } return Buffer.concat(chunks).toString("base64"); } if (Buffer.isBuffer(file)) return file.toString("base64"); if (file instanceof Uint8Array) return Buffer.from(file).toString("base64"); if (typeof file === "string") return Buffer.from(file).toString("base64"); if (file && typeof file === "object" && "content" in file) { const content = (file as { content: unknown }).content; if (Buffer.isBuffer(content)) return content.toString("base64"); if (content instanceof Uint8Array) return Buffer.from(content).toString("base64"); if (typeof content === "string") return Buffer.from(content).toString("base64");