fix(emails): customReplyToEmail no longer dropped when hideOrganizerEmail is true (#29940)
* fix: respect customReplyToEmail when hideOrganizerEmail is enabled * test: get custom reply to in headers
This commit is contained in:
@@ -8,11 +8,12 @@ import { getReplyToHeader } from "./getReplyToHeader";
|
||||
* Spec: https://datatracker.ietf.org/doc/html/rfc5322#section-3.6.2
|
||||
*/
|
||||
|
||||
vi.mock("./getReplyToEmail", () => ({
|
||||
getReplyToEmail: vi.fn((calEvent, excludeOrganizerEmail) => {
|
||||
if (excludeOrganizerEmail) return null;
|
||||
return calEvent.organizer?.email || null;
|
||||
}),
|
||||
vi.mock("./getReplyToEmail", () => ({
|
||||
getReplyToEmail: vi.fn((calEvent, excludeOrganizerEmail) => {
|
||||
if (calEvent.customReplyToEmail) return calEvent.customReplyToEmail;
|
||||
if (excludeOrganizerEmail) return null;
|
||||
return calEvent.organizer?.email || null;
|
||||
}),
|
||||
}));
|
||||
|
||||
const createMockCalEvent = (organizerEmail: string) => ({
|
||||
@@ -89,4 +90,16 @@ describe("getReplyToHeader", () => {
|
||||
expect(result.replyTo).not.toContain("]");
|
||||
});
|
||||
});
|
||||
|
||||
describe("with hideOrganizerEmail and customReplyToEmail", () => {
|
||||
it("uses customReplyToEmail even when hideOrganizerEmail is true", () => {
|
||||
const calEvent = {
|
||||
organizer: { email: "org@test.com" },
|
||||
hideOrganizerEmail: true,
|
||||
customReplyToEmail: "custom@test.com",
|
||||
};
|
||||
const result = getReplyToHeader(calEvent as any, undefined, true);
|
||||
expect(result).toEqual({ replyTo: "custom@test.com" });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,32 +2,22 @@ import type { CalendarEvent } from "@calcom/types/Calendar";
|
||||
|
||||
import { getReplyToEmail } from "./getReplyToEmail";
|
||||
|
||||
export function getReplyToHeader(
|
||||
calEvent: CalendarEvent,
|
||||
additionalEmails?: string | string[],
|
||||
excludeOrganizerEmail?: boolean
|
||||
) {
|
||||
if (calEvent.hideOrganizerEmail) return {};
|
||||
|
||||
const replyToEmail = getReplyToEmail(calEvent, excludeOrganizerEmail);
|
||||
const emailArray: string[] = [];
|
||||
|
||||
if (additionalEmails) {
|
||||
if (Array.isArray(additionalEmails)) {
|
||||
emailArray.push(...additionalEmails);
|
||||
} else {
|
||||
emailArray.push(additionalEmails);
|
||||
}
|
||||
}
|
||||
|
||||
if (replyToEmail) {
|
||||
emailArray.push(replyToEmail);
|
||||
}
|
||||
|
||||
if (emailArray.length === 0) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const replyTo = emailArray.join(", ");
|
||||
return { replyTo };
|
||||
export function getReplyToHeader(
|
||||
calEvent: CalendarEvent,
|
||||
additionalEmails?: string | string[],
|
||||
excludeOrganizerEmail?: boolean
|
||||
) {
|
||||
const shouldExcludeOrganizer = excludeOrganizerEmail || calEvent.hideOrganizerEmail;
|
||||
const replyToEmail = getReplyToEmail(calEvent, shouldExcludeOrganizer);
|
||||
|
||||
const emailArray: string[] = [];
|
||||
if (additionalEmails) {
|
||||
Array.isArray(additionalEmails) ? emailArray.push(...additionalEmails) : emailArray.push(additionalEmails);
|
||||
}
|
||||
if (replyToEmail) {
|
||||
emailArray.push(replyToEmail);
|
||||
}
|
||||
if (emailArray.length === 0) return {};
|
||||
|
||||
return { replyTo: emailArray.join(", ") };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user