The primary method for parsing RFC822 formatted emails is PostalMime.parse(). It accepts various input types including string, ArrayBuffer/Uint8Array, Blob, Node.js Buffer, or a ReadableStream.
Configuration Options
You can pass an optional PostalMimeOptions object to control parsing behavior:
rfc822Attachments (boolean, default: false): Treat message/rfc822 attachments without a Content-Disposition as attachments.forceRfc822Attachments (boolean, default: false): Treat all message/rfc822 parts as attachments.attachmentEncoding (string, default: "arraybuffer"): Determines how attachment content is decoded. Options: "base64", "utf8", or "arraybuffer" (returns raw ArrayBuffer).maxNestingDepth (number, default: 256): Maximum allowed MIME part nesting depth. Throws an error if exceeded.maxHeadersSize (number, default: 2097152): Maximum allowed total header size in bytes (default 2MB). Throws an error if exceeded.
Returned Email Object
The method returns a Promise<Email> which resolves to an object containing:
headers: Array of { key: string, value: string } objects.from, sender: Processed Address objects (can be a Mailbox or an address group).to, cc, bcc, replyTo: Arrays of Address objects.subject: String.date: ISO 8601 formatted string.html: HTML content string.text: Plain text content string.attachments: Array of Attachment objects containing filename, mimeType, disposition, content, etc.
// Basic usage
const email = await PostalMime.parse(rawEmail);
// With options
const options = {
attachmentEncoding: 'base64',
maxNestingDepth: 100
};
const email = await PostalMime.parse(rawEmail, options);