From 620da97cddc90c3b2bfc28290a287c8163b0bf10 Mon Sep 17 00:00:00 2001 From: Corey <128890849+limehawk@users.noreply.github.com> Date: Mon, 10 Aug 2026 10:20:01 -0400 Subject: [PATCH] fix: include incoming email To recipients in reply CC The incoming branch of getRecipients hardcoded 'to: []'. The step that copies extra To recipients into the reply CC always received an empty array. Recipients the sender addressed in To, rather than CC, fell off the thread on reply. Pass the email's actual To list. The existing filters still remove the inbox address, the forward-to address, and the contact. --- src/email.ts | 2 +- test/email.test.ts | 50 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/email.ts b/src/email.ts index 15e2238..7186c94 100644 --- a/src/email.ts +++ b/src/email.ts @@ -41,7 +41,7 @@ export function getRecipients( cc: email?.cc || [], bcc: email?.bcc || [], from: email?.from || [], - to: [], + to: email?.to || [], }; } else { const { diff --git a/test/email.test.ts b/test/email.test.ts index c5861dc..f44e13b 100644 --- a/test/email.test.ts +++ b/test/email.test.ts @@ -9,15 +9,17 @@ const createIncomingEmail = ({ from = [], cc = [], bcc = [], + to = [], }: { from?: string[]; cc?: string[]; bcc?: string[]; + to?: string[]; }) => { return { message_type: MessageType.INCOMING, content_attributes: { - email: { from, cc, bcc }, + email: { from, cc, bcc, to }, }, } as IncomingEmailMessage; }; @@ -157,6 +159,52 @@ describe('getRecipients', () => { }); }); + describe('To Recipients', () => { + test('should add extra emails in the "to" field to the "cc" array', () => { + const lastEmail = createIncomingEmail({ + from: ['sender@example.com'], + to: [inboxEmail, 'colleague@example.com'], + }); + const result = getRecipients( + lastEmail, + conversationContact, + inboxEmail, + forwardToEmail + ); + expect(result.cc).toContain('colleague@example.com'); + expect(result.cc).not.toContain(inboxEmail); + }); + + test('should keep "to" recipients alongside existing "cc" recipients', () => { + const lastEmail = createIncomingEmail({ + from: ['sender@example.com'], + to: [inboxEmail, 'colleague@example.com'], + cc: ['cc1@example.com'], + }); + const result = getRecipients( + lastEmail, + conversationContact, + inboxEmail, + forwardToEmail + ); + expect(result.cc).toEqual( + expect.arrayContaining(['cc1@example.com', 'colleague@example.com']) + ); + }); + + test('should not error when to is null', () => { + // @ts-ignore + const lastEmail = createIncomingEmail({ from: ['a@b.com'], to: null }); + const result = getRecipients( + lastEmail, + conversationContact, + inboxEmail, + forwardToEmail + ); + expect(result.to).toEqual(['a@b.com']); + }); + }); + describe('BCC Recipients', () => { test('should add emails in the "bcc" field to the "bcc" array', () => { const bccEmails = ['bcc1@example.com', 'bcc2@example.com'];