Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(email): open mailto links in the in-app composer (#5046)
Evan Hutnika65727898bfb
diff --git a/apps/web/src/components/app/Layout.tsx b/apps/web/src/components/app/Layout.tsxindex 686abcc9ae..3aca5714b1 100644--- a/apps/web/src/components/app/Layout.tsx+++ b/apps/web/src/components/app/Layout.tsx@@ -36,6 +36,7 @@ import {GoToHotkeys,type SidebarState,} from '@components/app/app-sidebar/sidebar';+import { mountMailtoInterceptor } from '@components/app/mailto-interceptor';import {isSidebarVisible,SidebarCollapseContext,@@ -348,6 +349,8 @@ function LayoutInner(props: RouteSectionProps) {mountGlobalFocusListener();+ mountMailtoInterceptor();+attachGlobalDOMScope(document.body);return (diff --git a/apps/web/src/components/app/mailto-interceptor.ts b/apps/web/src/components/app/mailto-interceptor.tsnew file mode 100644index 0000000000..8b5c0a461a--- /dev/null+++ b/apps/web/src/components/app/mailto-interceptor.ts@@ -0,0 +1,49 @@+import { globalSplitManager } from '@app/signal/splitLayout';+import { parseMailto } from '@block-email/util/mailto';+import { getOwner, onCleanup, onMount } from 'solid-js';++/**+ * Opens mailto: links in the in-app email composer instead of the OS mail+ * client. Capture-phase listener so links inside email-body shadow roots and+ * editors are caught; composedPath crosses the shadow boundaries.+ */+export function mountMailtoInterceptor() {+ const owner = getOwner();+ if (!owner) {+ console.error(+ 'No owner. mountMailtoInterceptor should be called once - from within the component tree.'+ );+ return;+ }+ onMount(() => {+ const onClick = (e: MouseEvent) => {+ if (e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) {+ return;+ }+ const anchor = e+ .composedPath()+ .find(+ (el): el is HTMLAnchorElement =>+ el instanceof HTMLAnchorElement && el.href.startsWith('mailto:')+ );+ // Links inside editors: let the click place the cursor instead.+ if (!anchor || anchor.isContentEditable) return;+ const parsed = parseMailto(anchor.href);+ if (!parsed) return;+ // Not ready yet — let the OS mail client handle it.+ const manager = globalSplitManager();+ if (!manager) return;+ e.preventDefault();+ manager.openWithSplit({+ type: 'component',+ id: 'email-compose',+ params: parsed.to.length ? { initialTo: parsed.to } : undefined,+ preserveParams: true,+ });+ };+ document.addEventListener('click', onClick, { capture: true });+ onCleanup(() =>+ document.removeEventListener('click', onClick, { capture: true })+ );+ });+}diff --git a/apps/web/src/components/app/split-layout/componentRegistry.tsx b/apps/web/src/components/app/split-layout/componentRegistry.tsxindex f48e2c99f4..1109215b9b 100644--- a/apps/web/src/components/app/split-layout/componentRegistry.tsx+++ b/apps/web/src/components/app/split-layout/componentRegistry.tsx@@ -386,7 +386,15 @@ registerComponent('channel-compose', () => {});registerComponent('email-compose', (params) => {usePageViewTracking('email-compose');- return <EmailCompose draftID={params?.draftID} />;+ // mailto: links land here as `component/[email protected],[email protected]`.+ const toParam = new URLSearchParams(window.location.search).get('to');+ const initialTo =+ params?.initialTo ??+ toParam+ ?.split(',')+ .map((e) => e.trim())+ .filter(Boolean);+ return <EmailCompose draftID={params?.draftID} initialTo={initialTo} />;});registerComponent('task-compose', (params) => {usePageViewTracking('task-compose');diff --git a/apps/web/src/features/block-email/component/compose/Compose.tsx b/apps/web/src/features/block-email/component/compose/Compose.tsxindex f906048bd7..bb797af6d8 100644--- a/apps/web/src/features/block-email/component/compose/Compose.tsx+++ b/apps/web/src/features/block-email/component/compose/Compose.tsx@@ -38,6 +38,8 @@ import { WrapUnlessMobile } from '@core/mobile/WrapUnlessMobile';import { useCombinedRecipients } from '@core/signal/useCombinedRecipient';import {type ContactInfo,+ emailToId,+ recipientEntityMapper,tryMacroId,useDisplayName,type WithCustomUserInput,@@ -75,6 +77,7 @@ import { emailClient } from '@service-email/client';import { debounce } from '@solid-primitives/scheduled';import { Surface } from '@ui';+import * as EmailValidator from 'email-validator';import type { LexicalEditor } from 'lexical';import {createEffect,@@ -109,6 +112,8 @@ let undoComposeSnapshot: UndoComposeSnapshot | null = null;type EmailComposeProps = {draftID?: string;+ /** Prefill for the To field (e.g. from an intercepted mailto: link). Ignored when editing an existing draft. */+ initialTo?: string[];};export function EmailCompose(props: EmailComposeProps) {@@ -211,6 +216,19 @@ export function EmailCompose(props: EmailComposeProps) {undoComposeSnapshot = null;}+ if (!props.draftID && props.initialTo?.length) {+ form.setRecipients(+ 'to',+ props.initialTo.map((email) =>+ recipientEntityMapper('custom')({+ id: emailToId(email),+ email,+ invalid: !EmailValidator.validate(email),+ })+ )+ );+ }+// --- Draft persistence ---function collectDraft() {diff --git a/apps/web/src/features/block-email/util/mailto.test.ts b/apps/web/src/features/block-email/util/mailto.test.tsnew file mode 100644index 0000000000..cdb391b185--- /dev/null+++ b/apps/web/src/features/block-email/util/mailto.test.ts@@ -0,0 +1,46 @@+import { describe, expect, it } from 'vitest';+import { parseMailto } from './mailto';++describe('parseMailto', () => {+ it('parses a single recipient', () => {+ expect(parseMailto('mailto:[email protected]')).toEqual({+ to: ['[email protected]'],+ });+ });++ it('parses comma-separated recipients', () => {+ expect(parseMailto('mailto:[email protected],[email protected]')).toEqual({+ to: ['[email protected]', '[email protected]'],+ });+ });++ it('decodes percent-encoded addresses', () => {+ expect(parseMailto('mailto:alice%40example.com')).toEqual({+ to: ['[email protected]'],+ });+ });++ it('merges the non-standard ?to= param', () => {+ expect(parseMailto('mailto:[email protected][email protected]')).toEqual({+ to: ['[email protected]', '[email protected]'],+ });+ });++ it('handles an empty address (bare mailto:)', () => {+ expect(parseMailto('mailto:')).toEqual({ to: [] });+ });++ it('ignores other query params', () => {+ expect(+ parseMailto('mailto:[email protected]?subject=Hi&body=Hello')+ ).toEqual({ to: ['[email protected]'] });+ });++ it('returns null for non-mailto URLs', () => {+ expect(parseMailto('https://example.com')).toBeNull();+ });++ it('returns null for unparseable input', () => {+ expect(parseMailto('not a url')).toBeNull();+ });+});diff --git a/apps/web/src/features/block-email/util/mailto.ts b/apps/web/src/features/block-email/util/mailto.tsnew file mode 100644index 0000000000..1c7c4c7d5d--- /dev/null+++ b/apps/web/src/features/block-email/util/mailto.ts@@ -0,0 +1,44 @@+/** Recipients extracted from a mailto: URL. */+export type ParsedMailto = {+ to: string[];+};++function safeDecode(value: string): string {+ try {+ return decodeURIComponent(value);+ } catch {+ return value;+ }+}++/**+ * Parses a mailto: URL into its recipients. Returns null for anything that+ * isn't a valid mailto: URL. Addresses come from the path+ * (`mailto:[email protected],[email protected]`) plus the non-standard but common `?to=` param.+ */+export function parseMailto(href: string): ParsedMailto | null {+ let url: URL;+ try {+ url = new URL(href);+ } catch {+ return null;+ }+ if (url.protocol !== 'mailto:') return null;++ const to = url.pathname+ .split(',')+ .map((addr) => safeDecode(addr).trim())+ .filter(Boolean);++ const toParam = url.searchParams.get('to');+ if (toParam) {+ to.push(+ ...toParam+ .split(',')+ .map((addr) => addr.trim())+ .filter(Boolean)+ );+ }++ return { to };+}