Skip to content

Build the Mail Content Frame in Teams as a Library-Ready Component

  • Deciders: Julian Bäume
  • Date: 2026-09-08

Status

Accepted

Context

Teams renders mail bodies in its own sandboxed iframe (mail-content-frame.vue, mail-document.ts, mail-transforms.ts). Core UI rewrote its mail body rendering in App Suite 8.51 to 8.53 as a Vue component (io.ox/mail/detail/mail-content-frame.vue, see Core UI ADR 0003 and 0004): a static srcdoc shell with a parse-time CSP, DOM injection of the sanitized body, allow-scripts granted only on WebKit because WebKit does not dispatch DOM events to parent listeners otherwise, client-side blocking of external content with an in-place reveal, and a fetch of the unmodified mail (view=raw).

That component cannot be reused as-is:

  • Core UI only exposes .js modules as externals; .vue files are bundled into their importers and have no addressable URL.
  • The component is wired to the Core UI mail app: it expects markup produced by the content.get pipeline, scrapes theme CSS from the host page, fires Backbone extension points and reads settings and device detection from Core UI globals.

A shared Vue component library, living in the Core UI monorepo and published to npm, is agreed on but not built yet. It is the intended home for a mail renderer that Teams, Core UI and other frontends share.

Decision

Teams implements the mail content frame in its own repository now, shaped for the component library from day one, and upstreams it as a merge request once the library exists.

The component boundary is fixed as follows.

The frame owns the browser-level rendering contract, with no imports from Core UI or from Teams stores:

  • the static srcdoc shell, the CSP (script-src 'none' as the script gate, font-src and media-src 'none'), and the sandbox attribute with the WebKit allow-scripts exception behind an injected flag;
  • DOM injection of the body into the loaded shell, so the mail never sits in an attribute and theme changes never rebuild the document;
  • height measurement on the body, the growth-guard stylesheet, re-measure on image load and font readiness, and a ResizeObserver on root and body so the frame can shrink;
  • forwarding of keydown, click and mousemove to the host, the file-drop guard, and in-frame anchor scrolling;
  • baseStyles, lang, dir and root class props, swapped in place.

The host injects every content decision:

  • a sanitize(html, { externalImages }) function returning the sanitized HTML and the blocked/insecure facts; the stash protocol for blocked resources (data-original-* attributes) is documented as part of the interface;
  • a reveal step for blocked content;
  • an onDocument(doc) hook for host enhancements (mailto interception, quote toggles, cid: resolution);
  • all user-visible labels.

Teams-specific behaviour (adaptive dark mode, card inset, CSS-only quote collapse, AI translation) stays in Teams as pre-processing or as onDocument work. The Teams adapter for sanitize delegates to $/io.ox/mail/sanitizer so the Core UI hardening and its test suite are reused instead of duplicated.

This supersedes ADR-0012: Teams no longer carries a DOMPurify sanitizer of its own. The component library will ship a dedicated sanitizer alongside the frame (possibly derived from the Core UI implementation), not a $/io.ox/core/security/sanitize external.

Consequences

Positive

  • Teams closes the gaps found against Core UI now: Safari event dispatch, the credential dialog vector closed by font-src 'none', and in-place image reveal without a refetch.
  • The upstream merge request is a move, not a rewrite: the component already has no host imports, and Core UI can adopt it with a thin adapter over its content pipeline.
  • Teams keeps its own rendering decisions without teaching them to the shared component.

Negative

  • Two frame implementations exist in the organisation until the library ships. The Teams one must track Core UI's mail-content-frame.vue for fixes in the meantime.
  • Shipping the library component to consumers outside App Suite eventually needs a default sanitizer. That work is deferred to the library; the injected interface is the commitment.

Alternatives Considered

Import Core UI's component through a .js re-export wrapper. A one-file change in Core UI would make it addressable. Rejected: the component would still expect Core UI's content pipeline markup and host hooks, and Teams would be building on an internal API with no stability promise.

Wait for the component library. Rejected: the Safari and CSP gaps are live in Teams today, and the library work is not blocked by anything Teams does now.