Repository navigation
Conversation
…from the File menu Internet messages (.eml, Apple Mail's .emlx) and Outlook items (.msg, .oft templates) open as a read-only document, like Visio drawings and iWork files: the worker reads the message and builds a DOCX of it. - src/core/mail: a MIME reader (encoded words, RFC 2231 parameters, nested multiparts, charsets, format=flowed, forwarded messages), an Outlook item reader on the existing compound file reader (MAPI properties, recipients, attachments, attached items), compressed RTF (LZFu / MELA) and the HTML or text Outlook wraps in RTF; native RTF bodies go through the RTF converter with the header around them - the document: subject, item kind and importance, a From / Sent / To / Cc / Bcc / Attachments table, the body (HTML with tables, cell colors and the pictures the message carries; plain text with links), attached messages - pictures an HTML body loads from the web are never fetched, and the document says so - parasToDocx writes tables, raster pictures, list levels and rules - File menu: an Attachments section saves each attachment; core API: `info.mail` and `mail.attachment`; the header's words follow the viewer's strings (`strings.mail`, German included) and locale Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PRD: e-mail messages in the viewer — phase 1, single messages
Summary
.eml(also Apple Mail's.emlx) and Outlook.msg/.oftfiles open read-only inDocViewer, the same way Visio drawings and iWork files do. The worker reads the message and builds a DOCX of it, so pages, zoom, find, print, PDF and Download as Word all work without new view code. Attachments are listed in the message and can be saved from the File menu. Nothing is fetched from the network.This PR is phase 1 of a larger mail track. Archives (
.pst,.ost,.olm,.mbox) need a view of their own and are planned as later phases (see Phasing).Problem
People keep messages as files: Outlook's Save as writes
.msg, other mail clients and exports write.eml, and both are common attachments in tickets, legal and compliance work, and document management systems. Today the engine refuses them:.msgis a compound file without a Word, Excel or PowerPoint stream ("Not a Word, Excel or PowerPoint file").emlopens as plain text, showing its raw MIME source, base64 and allHosts that embed the viewer have no way to show these files without a server or a second library.
Goals
.eml,.emlx,.msgand.oftread-only, with the subject, sender, recipients, date, body and attachments shown as a mail client shows them.Non-goals (phase 1)
.pst,.ost,.olm,.mbox.eml/.msg(saving gives.docx, as for Visio)winmail.dat(TNEF) unpacking, opening attachments inside the viewerUsers and use cases
.msg/.emland read it without Outlooksrcfor every file type: no special handling for mail, and the core API for attachmentsRequirements
.eml/.emlx: headers with encoded words (RFC 2047) and RFC 2231 parameters, 8-bit UTF-8 headers, nested multiparts (alternative,related,mixed,signed,report), base64 / quoted-printable, any charsetTextDecoderknows,format=flowed.msg/.oft: MAPI properties (MS-OXMSG): sender (SMTP, Exchange-only senders by name), To / Cc / Bcc from recipient storages (falling back to transport headers, then display strings), sent / received time, importance, message classPR_HTML, else the HTML or text Outlook wraps in compressed RTF (MS-OXRTFCP LZFu / MELA, MS-OXRTFEX\fromhtml1/\fromtext), else the RTF itself through the existing RTF converter, elsePR_BODYcid:anddata:, PNG / JPEG / GIF / BMP / WebP)message/rfc822, attached Outlook items) shown after the message, recursively (depth-limited)mail.attachment)EML/MSGbadge, no Edit button even witheditable; Download as Word, PDF, web page, text and print workmessage/rfc822, or (no extension) its headers. Browser-saved MHTML is not mistaken for mail. A.msgthat is MIME text opens as.eml, and one that is neither says sostrings.mail, German included in thedetable), dates in the viewer's locale.eml,.emlx,.msg,.oftNon-functional requirements
https://request and asserts none happens.safeHref(nojavascript:), and the HTML is never put into the page.dist/index.jsanddist/core.jsdon't include them; the React side imports only the extension table.UX
The document reads top to bottom:
mailto:links)File menu: an Attachments section lists each attachment with its size; choosing one saves it.
Technical design
openMail(). The DOCX it builds opens like any converted file, withfrom: 'eml' | 'msg'(which already makes the viewer read-only). The engine keeps the attachments formail.attachment.parasToDocx(shared): the body loop moved into aBodyWriterthat also writes tables (grid from spans,gridSpan/vMerge, borders, cell fill), raster pictures and list levels, plus a rule under a paragraph. Existing output (SVG diagrams asmedia/diagramN.svg) is unchanged.htmlToParas(shared): rich mode also gives a table'sborderand a cell'sfill. These fields are new and the clipboard path ignores them.rtfToDocx(bytes, wrap?)puts body XML before and after the document's own, for the header of an Outlook rich-text message. Withoutwrapnothing changes.API changes (additive)
OpenResult.fromgains'eml' | 'msg'. NewOpenResult.mail: { subject, attachments: [{ name, type, size }] }.'mail.attachment'(index): Blob.mail?: { texts?: Partial<MailTexts>; locale?: string }(the viewer passes its strings).Stringsgainsfrom.eml,from.msg,mail.*andfile.attachments. Hosts with their own full table get the English defaults for the new keys through the usual merge.Testing
test/mail.test.ts(23 tests): headers, addresses, parameters, flowed text, MIME structures (alternative, related, mixed, signed, forwarded, cut short, encrypted),.emlx,.msg(recipients, Exchange senders, display-string fallback, message classes, attachment order, attached items), LZFu (literals, dictionary references, MELA, damaged input), RTF de-encapsulation (\fromhtml1,\fromtext, native RTF wrapped by the converter), the built document (header table, pictures, links, cell shading, localized header, remote pictures, script links), detection (no name,message/rfc822, MHTML, a.msgthat is MIME), picture sizes.e2e/mail.spec.ts(3 tests, Chromium):.emland.msgrender read-only with their pictures and tables, no network request, attachments and Download as Word save, File → Open takes a mail file, the header in German.security,plain,docx-table,viewer,legacyandfile-menue2e specs.bun test: everything passes except 7 code-page tests (Windows-1258 CSV, BIFF5, RTF\ansicpg/\mac). These fail the same way onmainon this machine, so they are not caused by this PR.bun scripts/mail-samples.tswritesplayground/public/samples/sample.emlandsample.msgfromtest/mail-builder.ts. Both are in the playground's sample list.Phasing
.eml,.emlx,.msg,.oft.mboxmailview kind: folder tree, virtualized message list, reading pane. The archive is scanned in one pass to index where messages start, using the same ranged reads as large CSVs.Engine.openneeds a branch that is not an OPC package.pst,.ost,.olmwinmail.dat(TNEF),.ics/.vcf, meeting and contact fields, opening attachments in the viewer, searchRisks and open questions
<style>rules are not applied. Is that acceptable for a view-only reader, or should nested tables be written as nested DOCX tables before phase 2?\*\mhtmltag: both thecid:tag and the original tag are kept. The non-cid:picture is then left out because it isn't adata:URL. This is harmless in practice, but untested against a wide corpus.Success measures
.eml/.msgopened throughsrcor File → Open show a readable message instead of an error or raw MIME.🤖 Generated with Claude Code