Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(email-compose): flag Outlook subjects over 255 characters (#8796)

teo53f98d978618
diff --git a/apps/web/src/features/email-compose/core/constants.ts b/apps/web/src/features/email-compose/core/constants.ts
index f687853805..743e0e6cb7 100644
--- a/apps/web/src/features/email-compose/core/constants.ts
+++ b/apps/web/src/features/email-compose/core/constants.ts
@@ -1,3 +1,5 @@
+import { match } from 'ts-pattern';
+
export const MACRO_EMAIL_SIGNATURE = '-- Sent with Macro';
export const MAX_ATTACHMENTS_BYTES_SIZE = 18_000_000;
@@ -9,6 +11,17 @@ export function attachmentLimitBytes(provider?: 'GMAIL' | 'OUTLOOK'): number {
return provider === 'OUTLOOK' ? 25_000_000 : MAX_ATTACHMENTS_BYTES_SIZE;
}
+// Exchange stores at most 255 characters of a subject. Gmail has no documented
+// subject limit short of its message size cap.
+export function subjectLimitChars(
+ provider?: 'GMAIL' | 'OUTLOOK'
+): number | undefined {
+ return match(provider)
+ .with('OUTLOOK', () => 255)
+ .with('GMAIL', undefined, () => undefined)
+ .exhaustive();
+}
+
// Stable id for the compose "To" input so the create gesture can focus it
// synchronously on iOS (the virtual keyboard only opens within a user gesture).
export const EMAIL_COMPOSE_TO_INPUT_ID = 'email-compose-to-input';
diff --git a/apps/web/src/features/email-compose/core/email-sender.ts b/apps/web/src/features/email-compose/core/email-sender.ts
index e16af045de..ec8299d921 100644
--- a/apps/web/src/features/email-compose/core/email-sender.ts
+++ b/apps/web/src/features/email-compose/core/email-sender.ts
@@ -10,6 +10,7 @@ export type SenderInbox = {
email_address: string;
displayName?: string;
photo_url?: string | null;
+ provider?: 'GMAIL' | 'OUTLOOK';
/** null means this inbox's provider lookup failed; undefined is not loaded. */
sendAs?: readonly EmailSenderAddress[] | null;
};
@@ -18,6 +19,7 @@ export type FromInboxOption = EmailSenderAddress & {
id: string;
inboxId: string;
photo_url?: string | null;
+ provider?: 'GMAIL' | 'OUTLOOK';
isAlias: boolean;
};
@@ -43,6 +45,7 @@ export function fromInboxOptions(
email_address: inbox.email_address,
displayName: inbox.displayName,
photo_url: inbox.photo_url,
+ provider: inbox.provider,
isAlias: false,
},
...aliases.map((alias) => ({
@@ -50,6 +53,7 @@ export function fromInboxOptions(
id: `${inbox.id}:${alias.email_address.toLowerCase()}`,
inboxId: inbox.id,
photo_url: inbox.photo_url,
+ provider: inbox.provider,
isAlias: true,
})),
];
diff --git a/apps/web/src/features/email-compose/core/subject-limit.ts b/apps/web/src/features/email-compose/core/subject-limit.ts
new file mode 100644
index 0000000000..889dd69be6
--- /dev/null
+++ b/apps/web/src/features/email-compose/core/subject-limit.ts
@@ -0,0 +1,10 @@
+import { subjectLimitChars } from './constants';
+
+export function subjectLimitHint(
+ subject: string,
+ provider?: 'GMAIL' | 'OUTLOOK'
+): string | undefined {
+ const limit = subjectLimitChars(provider);
+ if (limit === undefined || subject.length <= limit) return undefined;
+ return `Subject is ${subject.length} characters. Outlook allows ${limit}.`;
+}
diff --git a/apps/web/src/features/email-compose/views/compose-subject.test.tsx b/apps/web/src/features/email-compose/views/compose-subject.test.tsx
new file mode 100644
index 0000000000..ace4c87f18
--- /dev/null
+++ b/apps/web/src/features/email-compose/views/compose-subject.test.tsx
@@ -0,0 +1,130 @@
+import {
+ cleanup,
+ fireEvent,
+ render,
+ screen,
+ waitFor,
+} from '@solidjs/testing-library';
+import { afterEach, describe, expect, it, vi } from 'vitest';
+import { ComposeProvider } from '../context/compose-context';
+import { createComposeContext } from '../tests/capabilities';
+import { mountEmailComposer } from '../tests/composer';
+import { ComposeSubject } from './compose-subject';
+
+vi.mock('@ui', async () => ({
+ cn: (await import('@ui/utils/classname')).cn,
+}));
+
+afterEach(cleanup);
+
+function renderSubject(initialInboxId: 'gmail' | 'outlook', mobile = false) {
+ const context = createComposeContext();
+ context.accounts.inboxes = () => [
+ {
+ id: 'gmail',
+ email_address: '[email protected]',
+ provider: 'GMAIL',
+ settings: {},
+ },
+ {
+ id: 'outlook',
+ email_address: '[email protected]',
+ provider: 'OUTLOOK',
+ settings: {},
+ },
+ ];
+ const root = mountEmailComposer(context, undefined, { initialInboxId });
+ render(() => (
+ <ComposeProvider
+ value={{
+ ...root.state.context,
+ bodyActions: {
+ recipientAdded: vi.fn(),
+ readDroppedFiles: vi.fn(),
+ insertFiles: vi.fn(),
+ },
+ isMobile: () => mobile,
+ scheduleEnabled: true,
+ }}
+ >
+ <ComposeSubject />
+ </ComposeProvider>
+ ));
+ return root;
+}
+
+function subjectField() {
+ return screen.getByRole('textbox') as HTMLInputElement | HTMLTextAreaElement;
+}
+
+function typeSubject(value: string) {
+ const field = subjectField();
+ field.focus();
+ fireEvent.input(field, { target: { value } });
+ return field;
+}
+
+function describedHint(element: HTMLElement) {
+ const id = element.getAttribute('aria-describedby');
+ return id ? document.getElementById(id)?.textContent?.trim() : undefined;
+}
+
+function overLimitHint(field: HTMLElement) {
+ return field.getAttribute('aria-invalid') === 'true'
+ ? describedHint(field)
+ : undefined;
+}
+
+describe('ComposeSubject provider subject limit', () => {
+ it('flags an Outlook subject over 255 characters until it is trimmed, without cutting it', () => {
+ const root = renderSubject('outlook');
+ try {
+ const subject = 'a'.repeat(300);
+ const field = typeSubject(subject);
+ expect(overLimitHint(field)).toBeTruthy();
+ expect(field.value).toBe(subject);
+ expect(root.state.context.subject()).toBe(subject);
+
+ typeSubject('a'.repeat(255));
+ expect(overLimitHint(subjectField())).toBeUndefined();
+ } finally {
+ root.dispose();
+ }
+ });
+
+ it('flags a long Outlook subject typed on mobile, also after the field collapses', () => {
+ const root = renderSubject('outlook', true);
+ try {
+ const field = typeSubject('a'.repeat(300));
+ expect(overLimitHint(field)).toBeTruthy();
+
+ field.blur();
+ expect(describedHint(screen.getByRole('button'))).toBeTruthy();
+ } finally {
+ root.dispose();
+ }
+ });
+
+ it('leaves a long Gmail subject alone', () => {
+ const root = renderSubject('gmail');
+ try {
+ expect(overLimitHint(typeSubject('a'.repeat(300)))).toBeUndefined();
+ } finally {
+ root.dispose();
+ }
+ });
+
+ it('flags a long subject once the sender switches from Gmail to Outlook', async () => {
+ const root = renderSubject('gmail');
+ try {
+ typeSubject('a'.repeat(300));
+ root.state.context.onSelectInbox?.('outlook');
+ await waitFor(() =>
+ expect(root.state.context.selectedInboxId?.()).toBe('outlook')
+ );
+ expect(overLimitHint(subjectField())).toBeTruthy();
+ } finally {
+ root.dispose();
+ }
+ });
+});
diff --git a/apps/web/src/features/email-compose/views/compose-subject.tsx b/apps/web/src/features/email-compose/views/compose-subject.tsx
index 81ab977fa2..c176e75d30 100644
--- a/apps/web/src/features/email-compose/views/compose-subject.tsx
+++ b/apps/web/src/features/email-compose/views/compose-subject.tsx
@@ -1,6 +1,7 @@
import { cn } from '@ui';
-import { createSignal, Show } from 'solid-js';
+import { createSignal, createUniqueId, Show } from 'solid-js';
import { useCompose } from '../context/compose-context';
+import { subjectLimitHint } from '../core/subject-limit';
function autosize(el: HTMLTextAreaElement) {
el.style.height = 'auto';
@@ -20,6 +21,15 @@ export function ComposeSubject(props: {
const showSummary = () =>
ctx.isMobile() && !editing() && ctx.subject().length > 0;
+ const limitHintId = createUniqueId();
+ const limitHint = () => {
+ const inboxId = ctx.selectedInboxId?.();
+ const sender = ctx
+ .fromInboxes?.()
+ .find((option) => option.inboxId === inboxId);
+ return subjectLimitHint(ctx.subject(), sender?.provider);
+ };
+
const blurOnEscape = (
e: KeyboardEvent & { currentTarget: HTMLInputElement }
) => {
@@ -56,6 +66,8 @@ export function ComposeSubject(props: {
onInput={(e) => ctx.setSubject(e.currentTarget.value)}
onKeyDown={blurOnEscape}
disabled={ctx.disabled()}
+ aria-invalid={limitHint() ? true : undefined}
+ aria-describedby={limitHint() ? limitHintId : undefined}
/>
}
>
@@ -69,6 +81,7 @@ export function ComposeSubject(props: {
setEditing(true);
requestAnimationFrame(() => textareaRef?.focus());
}}
+ aria-describedby={limitHint() ? limitHintId : undefined}
>
<span class="truncate">{ctx.subject()}</span>
</button>
@@ -101,9 +114,18 @@ export function ComposeSubject(props: {
}
}}
disabled={ctx.disabled()}
+ aria-invalid={limitHint() ? true : undefined}
+ aria-describedby={limitHint() ? limitHintId : undefined}
/>
</Show>
</Show>
+ <Show when={limitHint()}>
+ {(hint) => (
+ <div id={limitHintId} class="text-failure-ink text-sm mt-1">
+ {hint()}
+ </div>
+ )}
+ </Show>
</div>
<Show when={ctx.validationError('no_subject')}>
{(err) => (
diff --git a/apps/web/src/features/email-compose/views/reply-envelope.test.tsx b/apps/web/src/features/email-compose/views/reply-envelope.test.tsx
new file mode 100644
index 0000000000..04990e2cbb
--- /dev/null
+++ b/apps/web/src/features/email-compose/views/reply-envelope.test.tsx
@@ -0,0 +1,128 @@
+import { cleanup, fireEvent, render, screen } from '@solidjs/testing-library';
+import { type ComponentProps, createRoot, createSignal } from 'solid-js';
+import { afterEach, describe, expect, it, vi } from 'vitest';
+import type { EmailInbox } from '../context/compose-capabilities';
+import type { EmailFormRecipients } from '../core/email-recipient';
+import { createReplyRecipientFields } from '../primitives/reply-recipient-fields';
+import { ReplyEnvelope } from './reply-envelope';
+
+vi.mock('@ui', async () => ({
+ cn: (await import('@ui/utils/classname')).cn,
+ Button: (props: ComponentProps<'button'>) => <button {...props} />,
+}));
+vi.mock('@core/component/RecipientSelector', () => ({
+ RecipientSelector: () => null,
+}));
+vi.mock('../components/from-inbox-selector', () => ({
+ FromInboxSelector: () => null,
+}));
+
+const inboxes: EmailInbox[] = [
+ {
+ id: 'gmail',
+ email_address: '[email protected]',
+ provider: 'GMAIL',
+ settings: {},
+ },
+ {
+ id: 'outlook',
+ email_address: '[email protected]',
+ provider: 'OUTLOOK',
+ settings: {},
+ },
+];
+
+const disposers: (() => void)[] = [];
+afterEach(() => {
+ cleanup();
+ disposers.splice(0).forEach((dispose) => dispose());
+});
+
+function renderEnvelope(inboxId: 'gmail' | 'outlook', mobile: boolean) {
+ const state = createRoot((dispose) => {
+ disposers.push(dispose);
+ const [values, setValues] = createSignal<EmailFormRecipients>({
+ to: [],
+ cc: [],
+ bcc: [],
+ });
+ const [subject, setSubject] = createSignal('');
+ const [activeInboxId, setActiveInboxId] = createSignal(inboxId);
+ return {
+ values,
+ subject,
+ setSubject,
+ activeInboxId,
+ setActiveInboxId,
+ fields: createReplyRecipientFields({
+ values,
+ container: () => undefined,
+ disabled: () => false,
+ onChange: () => {},
+ setValues: (field, recipients) =>
+ setValues((prev) => ({ ...prev, [field]: recipients })),
+ }),
+ };
+ });
+ render(() => (
+ <ReplyEnvelope
+ fields={state.fields}
+ values={state.values}
+ options={() => []}
+ inboxes={() => inboxes}
+ activeInboxId={state.activeInboxId}
+ senderEmail={() => undefined}
+ onSenderChange={() => {}}
+ subject={state.subject}
+ onSubjectChange={state.setSubject}
+ showSubject
+ mobile={() => mobile}
+ portalScope={() => undefined}
+ replyType={() => 'forward'}
+ disabled={() => false}
+ />
+ ));
+ const input = screen.getByPlaceholderText(
+ mobile ? 'Subject:' : 'Subject'
+ ) as HTMLInputElement;
+ return {
+ ...state,
+ input,
+ type(value: string) {
+ input.focus();
+ fireEvent.input(input, { target: { value } });
+ },
+ };
+}
+
+function overLimitHint(input: HTMLInputElement) {
+ if (input.getAttribute('aria-invalid') !== 'true') return undefined;
+ const id = input.getAttribute('aria-describedby');
+ return id ? document.getElementById(id)?.textContent?.trim() : undefined;
+}
+
+describe.each([false, true])(
+ 'ReplyEnvelope subject limit (mobile=%s)',
+ (mobile) => {
+ it('flags an Outlook subject over 255 characters until it is trimmed, without cutting it', () => {
+ const envelope = renderEnvelope('outlook', mobile);
+ const subject = 'a'.repeat(300);
+ envelope.type(subject);
+ expect(overLimitHint(envelope.input)).toBeTruthy();
+ expect(envelope.input.value).toBe(subject);
+ expect(envelope.subject()).toBe(subject);
+
+ envelope.type('a'.repeat(255));
+ expect(overLimitHint(envelope.input)).toBeUndefined();
+ });
+
+ it('flags a long Gmail subject only after switching to Outlook', () => {
+ const envelope = renderEnvelope('gmail', mobile);
+ envelope.type('a'.repeat(300));
+ expect(overLimitHint(envelope.input)).toBeUndefined();
+
+ envelope.setActiveInboxId('outlook');
+ expect(overLimitHint(envelope.input)).toBeTruthy();
+ });
+ }
+);
diff --git a/apps/web/src/features/email-compose/views/reply-envelope.tsx b/apps/web/src/features/email-compose/views/reply-envelope.tsx
index e04b214f02..c22fd6f400 100644
--- a/apps/web/src/features/email-compose/views/reply-envelope.tsx
+++ b/apps/web/src/features/email-compose/views/reply-envelope.tsx
@@ -3,7 +3,7 @@ import ChevronDown from '@phosphor/caret-down.svg';
import CaretRight from '@phosphor/caret-right.svg';
import { Button, cn } from '@ui';
import type { Accessor } from 'solid-js';
-import { Show } from 'solid-js';
+import { createUniqueId, Show } from 'solid-js';
import { FromInboxSelector } from '../components/from-inbox-selector';
import { RecipientDropRow } from '../components/recipient-drop-row';
import type { EmailInbox } from '../context/compose-capabilities';
@@ -11,6 +11,7 @@ import type { EmailRecipient, RecipientFieldId } from '../core/email-recipient';
import { getRecipientDisplayName } from '../core/email-recipient';
import { fromInboxOptions } from '../core/email-sender';
import type { ReplyType } from '../core/reply-type';
+import { subjectLimitHint } from '../core/subject-limit';
import type { EmailFormRecipients } from '../primitives/email-form-state';
import type { createReplyRecipientFields } from '../primitives/reply-recipient-fields';
@@ -62,6 +63,24 @@ export function ReplyEnvelope(props: ReplyEnvelopeProps) {
const suffix = recipients.length > 1 ? ` + ${recipients.length - 1}` : '';
return `${action} ${getRecipientDisplayName(first)}${suffix}`;
};
+ const limitHintId = createUniqueId();
+ const limitHint = () => {
+ const inboxId = props.activeInboxId();
+ const inbox = props.inboxes().find((inbox) => inbox.id === inboxId);
+ return subjectLimitHint(props.subject(), inbox?.provider);
+ };
+ const LimitHint = (hint: { class: string }) => (
+ <Show when={limitHint()}>
+ {(text) => (
+ <div
+ id={limitHintId}
+ class={cn('w-full text-failure-ink text-sm', hint.class)}
+ >
+ {text()}
+ </div>
+ )}
+ </Show>
+ );
const RecipientInput = (field: {
field: RecipientFieldId;
mobile?: boolean;
@@ -215,7 +234,7 @@ export function ReplyEnvelope(props: ReplyEnvelopeProps) {
</div>
<div
class={cn(
- 'flex-row items-center',
+ 'flex-row flex-wrap items-center',
props.showSubject ? 'flex' : 'hidden'
)}
>
@@ -234,7 +253,10 @@ export function ReplyEnvelope(props: ReplyEnvelopeProps) {
}}
placeholder="Subject"
disabled={props.disabled()}
+ aria-invalid={limitHint() ? true : undefined}
+ aria-describedby={limitHint() ? limitHintId : undefined}
/>
+ <LimitHint class="pl-4 pt-1" />
</div>
</>
}
@@ -315,7 +337,7 @@ export function ReplyEnvelope(props: ReplyEnvelopeProps) {
/>
</div>
- <div class="min-h-14 border-b border-edge-muted/70 flex items-center">
+ <div class="min-h-14 border-b border-edge-muted/70 flex flex-wrap items-center">
<input
type="text"
class="w-full bg-transparent outline-none border-0 text-[17px] leading-6 text-ink placeholder:text-ink-placeholder"
@@ -330,7 +352,10 @@ export function ReplyEnvelope(props: ReplyEnvelopeProps) {
}}
placeholder="Subject:"
disabled={props.disabled()}
+ aria-invalid={limitHint() ? true : undefined}
+ aria-describedby={limitHint() ? limitHintId : undefined}
/>
+ <LimitHint class="pb-2" />
</div>
</div>
</Show>
diff --git a/docs/agent-guide/email.md b/docs/agent-guide/email.md
index c24f24691c..443d6113af 100644
--- a/docs/agent-guide/email.md
+++ b/docs/agent-guide/email.md
@@ -474,6 +474,10 @@ view-only links instead. Confirming inserts one link per file at the end of the
written message, above a reply's quoted thread, and the draft autosaves; Cancel
adds nothing. Files that fit still attach, and the same check covers files
dropped onto the body.
+With an Outlook From, a subject over Exchange's 255-character limit stays as
+typed, the field is marked invalid, and a hint under it gives the length. Switching
+From to Outlook flags an existing long subject; Gmail senders show no hint. The
+hint does not block saving or Send.
To forward from another inbox, open Forward, expand the forwarding envelope on
desktop, and select a different account in From (already visible on mobile).
Forwarded files must remain attached after switching to an owned or delegated