get_email_raw
Retrieve raw email data in RFC 2822 format with full headers and MIME body as base64-encoded content for debugging or export purposes.
Instructions
Get the raw RFC 2822 source of an email (full headers + MIME body) as base64-encoded data. Useful for debugging or export. Capped at 1 MB.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| uid | Yes | Email UID | |
| mailbox | No | Mailbox name (default INBOX) |
Implementation Reference
- lib/imap.js:1419-1437 (handler)Implementation of get_email_raw tool, which fetches the raw source of an email given its UID.
export async function getEmailRaw(uid, mailbox = 'INBOX', creds = null) { const MAX_RAW_BYTES = 1 * 1024 * 1024; // 1 MB cap const client = createRateLimitedClient(creds); await client.connect(); await client.mailboxOpen(mailbox); const msg = await client.fetchOne(uid, { source: true }, { uid: true }); await client.logout(); if (!msg || !msg.source) throw new Error(`Email UID ${uid} not found`); const source = msg.source; const truncated = source.length > MAX_RAW_BYTES; const slice = truncated ? source.slice(0, MAX_RAW_BYTES) : source; return { uid, size: source.length, truncated, data: slice.toString('base64'), dataEncoding: 'base64' }; }