@php
// Used by the Lead emails relation manager to render stored `body_html`
// inside a view modal. Important note: the prior docblock
// claimed "inbound emails go through the IMAP connector which already
// strips dangerous headers" — that is INCORRECT. webklex/php-imap
// parses MIME headers, it does NOT sanitize the HTML body of an
// inbound email. An external attacker can email a tenant's
// IMAP-connected mailbox with `` and when the tenant admin opens
// the conversation thread the script executes in the Filament admin
// context — full session takeover. Applies the same 4-layer regex
// sanitizer used in landing/sections/html and public/static-page
// (earlier hardening) so inbound + outbound HTML both render defanged.
//
// After sanitization we ALSO add the existing target="_blank" +
// rel="noopener noreferrer" rewrite so external links don't reverse-
// tabnab the admin tab. Order matters: sanitize FIRST, then rewrite
// links (so the rewrite operates on already-cleaned markup).
$html = $getState();
if (is_string($html) && $html !== '') {
// Layer 1: strip #is', '', $html);
$html = preg_replace('#