Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function getRecipients(
cc: email?.cc || [],
bcc: email?.bcc || [],
from: email?.from || [],
to: [],
to: email?.to || [],
};
} else {
const {
Expand Down
50 changes: 49 additions & 1 deletion test/email.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -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'];
Expand Down
Loading