Email and ZIP archives
Show EML and Outlook MSG emails with attachments, and browse ZIP archives, in React. Attachments and archive entries open in a nested viewer.
Email (EML and MSG)
Our own MIME parser handles multipart messages, base64 and quoted-printable, RFC 2047 and 2231 encoded headers and names, and character sets. Outlook .msg files are read with our MS-OXMSG and compound-file readers.
- The HTML body shows in a sandboxed, sanitised frame. Remote images are blocked until the reader asks for them, so opening a message does not tell the sender.
- Inline
cid:images are shown in place. - Attachments open in a nested viewer with all its features, including other emails and archives.
ZIP archives
A folder tree of the archive, ZIP64 and UTF-8 names included. Any file inside opens in a nested viewer. Entries are decompressed only when opened, and never past their declared size, which guards against zip bombs.
Controller
The message or archive is drawn inside the surface, with each attachment or entry in its own nested viewer. The nested viewers have their own toolbars and are not part of your controller.
| State | For email (EML, MSG) | For ZIP |
|---|---|---|
detection.kind | 'email' | 'zip' |
page, pageCount | No pages. | No pages. |
zoom | Not supported (can.zoom false); nested viewers zoom on their own. | Same. |
search.count | Matches in the header fields and attachment names. The body is in a sandboxed frame, so its text is not searched from outside. | Matches in the entry open in the preview (file names in the tree are not searched). |
print() | Prints the message: header fields, then the body. | Prints the entry open in the preview (the file tree is left out). |
download() | The original .eml / .msg. | The original archive. |
can | search, print, download. | search, print, download. |
Headless
A wrapper that labels the file and offers search, print and download; the message or archive itself stays inside the surface:
'use client';
// Emails and ZIP archives: the message (headers, body, attachments) or the archive's file tree
// is drawn inside the surface, and each attachment or entry opens in a nested viewer there.
// The controller adds what wraps them: status, file name, search, print (email) and download.
import { DocumentSurface, useDocViewer, type DocSource } from '@openpreview/react';
import '@openpreview/react/styles.css';
export default function MessageViewer({ source }: { source: DocSource }) {
const viewer = useDocViewer({ source });
const kind = viewer.detection?.kind;
return (
<div className="flex h-full flex-col text-sm">
<header className="flex items-center gap-3 border-b p-2">
<strong>{viewer.fileName}</strong>
<span className="opacity-70">{kind === 'email' ? 'Email' : kind === 'zip' ? 'Archive' : kind}</span>
{viewer.can.search && <button onClick={() => viewer.setSearchOpen(true)}>Search</button>}
{kind === 'email' && <button onClick={() => void viewer.print()}>Print message</button>}
<button className="ml-auto" onClick={viewer.download}>
Download {kind === 'zip' ? 'archive' : 'original'}
</button>
</header>
<DocumentSurface viewer={viewer} className="min-h-0 flex-1" />
</div>
);
}