Skip to content

Commit 67d38f3

Browse files
committed
fix: Mails are sent to the organizer twice
The `ics` package doesn't support setting the `SCHEDULE-AGENT` parameter, there is a PR (adamgibbons/ics#248), but it is not merged. This is a workaround that relies on the fact that the `ics` package does not properly escape the `name` field of the organizer. In a perfect world, they would merge the PR and create a new release, but this is unfortunately not the world we live in. The `SCHEDULE-AGENT` tells the CalDav server that the invitation has been sent by the client (which is cal in this case), preventing the CalDav server to not send invitations itself. refs calcom#9485
1 parent 2faf24f commit 67d38f3

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

packages/lib/CalendarService.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,13 @@ const getDuration = (start: string, end: string): DurationObject => ({
9696
});
9797

9898
const mapAttendees = (attendees: Person[]): Attendee[] =>
99-
attendees.map(({ email, name }) => ({ name, email, partstat: "NEEDS-ACTION" }));
99+
// TODO Use `scheduleAgent` once https://github.com/adamgibbons/ics/pull/248 is merged rather
100+
// than forcing the value into the partstat string.
101+
attendees.map(({ email, name }) => ({
102+
name,
103+
email,
104+
partstat: "NEEDS-ACTION;SCHEDULE-AGENT=CLIENT" as any,
105+
}));
100106

101107
export default abstract class BaseCalendarService implements Calendar {
102108
private url = "";
@@ -152,7 +158,10 @@ export default abstract class BaseCalendarService implements Calendar {
152158
title: event.title,
153159
description: getRichDescription(event),
154160
location: getLocation(event),
155-
organizer: { email: event.organizer.email, name: event.organizer.name },
161+
// TODO Use `name`, `email`, and `scheduleAgent` once https://github.com/adamgibbons/ics/pull/248 is merged
162+
organizer: {
163+
name: `${event.organizer.name}:MAILTO:${event.organizer.email}:SCHEDULE-AGENT=CLIENT`,
164+
},
156165
attendees: this.getAttendees(event),
157166
/** according to https://datatracker.ietf.org/doc/html/rfc2446#section-3.2.1, in a published iCalendar component.
158167
* "Attendees" MUST NOT be present
@@ -228,7 +237,10 @@ export default abstract class BaseCalendarService implements Calendar {
228237
title: event.title,
229238
description: getRichDescription(event),
230239
location: getLocation(event),
231-
organizer: { email: event.organizer.email, name: event.organizer.name },
240+
// TODO Use `name`, `email`, and `scheduleAgent` once https://github.com/adamgibbons/ics/pull/248 is merged
241+
organizer: {
242+
name: `${event.organizer.name}:MAILTO:${event.organizer.email}:SCHEDULE-AGENT=CLIENT`,
243+
},
232244
attendees: this.getAttendees(event),
233245
});
234246

0 commit comments

Comments
 (0)