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): block sending an Outlook draft the provider rejected (#8781)

teo66ea25096d70
diff --git a/apps/web/src/features/email-compose/primitives/provider-rejected-draft.test.ts b/apps/web/src/features/email-compose/primitives/provider-rejected-draft.test.ts
new file mode 100644
index 0000000000..27cf18d4a7
--- /dev/null
+++ b/apps/web/src/features/email-compose/primitives/provider-rejected-draft.test.ts
@@ -0,0 +1,90 @@
+import { createSignal } from 'solid-js';
+import { afterEach, beforeEach, expect, it, vi } from 'vitest';
+import type { MessageOperation } from '../../email-message/core/message-operation';
+import { message } from '../../email-message/tests/messages';
+import { createComposeContext } from '../tests/capabilities';
+import { mountEmailComposer } from '../tests/composer';
+import { mountReplyComposer } from '../tests/reply';
+
+beforeEach(() => vi.useFakeTimers({ now: new Date('2026-09-01T12:00:00Z') }));
+afterEach(() => vi.useRealTimers());
+
+function mountDraft(
+ kind: 'compose' | 'reply',
+ seeded: MessageOperation | null
+) {
+ const context = createComposeContext();
+ const [operation, setOperation] = createSignal(seeded);
+ context.operations = () => ({ operation, resolve: vi.fn() });
+ context.setDraftLifecycle({
+ type: 'editing',
+ draftId: 'draft',
+ threadId: 'thread',
+ inboxId: 'inbox',
+ observedAt: Date.now(),
+ });
+ const draft = message('draft', { is_draft: true, operation: seeded });
+ const compose =
+ kind === 'compose'
+ ? mountEmailComposer(context, undefined, { draft })
+ : undefined;
+ const reply =
+ kind === 'reply'
+ ? mountReplyComposer(context, undefined, { draft })
+ : undefined;
+ return {
+ context,
+ setOperation,
+ edit: (text: string) => (compose ?? reply)?.edit(text),
+ async send() {
+ const sent = compose
+ ? compose.state.context.onSend()
+ : reply?.sendEmail();
+ await vi.advanceTimersByTimeAsync(0);
+ await sent;
+ },
+ dispose() {
+ compose?.dispose();
+ reply?.dispose();
+ },
+ };
+}
+
+it.each(['compose', 'reply'] as const)(
+ 'holds a %s draft the provider rejected until it accepts an edit',
+ async (kind) => {
+ const draft = mountDraft(kind, {
+ state: 'FAILED',
+ issue: 'INVALID_CONTENT',
+ revision: '3',
+ });
+ try {
+ draft.edit('Correct the rejected draft');
+ await vi.advanceTimersByTimeAsync(600);
+ expect(draft.context.drafts.saveDraft).toHaveBeenCalled();
+ await draft.send();
+ expect(draft.context.delivery.sendMessage).not.toHaveBeenCalled();
+ draft.setOperation({ state: 'SYNCHRONIZED', revision: '4' });
+ await draft.send();
+ expect(draft.context.delivery.sendMessage).toHaveBeenCalled();
+ } finally {
+ draft.dispose();
+ }
+ }
+);
+
+it.each([
+ ['compose', 'a Gmail draft without a mailbox operation', null],
+ ['reply', 'a Gmail draft without a mailbox operation', null],
+ ['compose', 'a synchronized Outlook draft', { state: 'SYNCHRONIZED' }],
+ ['reply', 'a synchronized Outlook draft', { state: 'SYNCHRONIZED' }],
+] as const)('sends from %s for %s', async (kind, _label, seeded) => {
+ const draft = mountDraft(kind, seeded && { ...seeded, revision: '3' });
+ try {
+ draft.edit('Ready to deliver');
+ await draft.send();
+ expect(draft.context.delivery.sendMessage).toHaveBeenCalled();
+ } finally {
+ draft.dispose();
+ }
+});
diff --git a/apps/web/src/features/email-message/core/message-operation.ts b/apps/web/src/features/email-message/core/message-operation.ts
index 6b96118267..2c2dfeac2d 100644
--- a/apps/web/src/features/email-message/core/message-operation.ts
+++ b/apps/web/src/features/email-message/core/message-operation.ts
@@ -127,11 +127,13 @@ export function operationSettled(operation: MessageOperation): boolean {
return operation.state === 'SENT' || operation.state === 'DELETED';
}
-/** A move may remain editable while the original copy still prevents delivery. */
+/** Moves and provider-rejected content stay editable but cannot deliver until resolved. */
export function operationBlocksSending(
operation?: MessageOperation | null
): boolean {
return (
- operationBlocksEditing(operation) || !!operation?.issue?.startsWith('MOVE_')
+ operationBlocksEditing(operation) ||
+ !!operation?.issue?.startsWith('MOVE_') ||
+ operation?.issue === 'INVALID_CONTENT'
);
}