Skip to content

Commit

Permalink
fix: Mails are sent to the organizer twice
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dasJ committed Oct 10, 2023
1 parent 2faf24f commit 1cf788d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/lib/CalendarService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ const getDuration = (start: string, end: string): DurationObject => ({
});

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

export default abstract class BaseCalendarService implements Calendar {
private url = "";
Expand Down Expand Up @@ -152,7 +154,10 @@ export default abstract class BaseCalendarService implements Calendar {
title: event.title,
description: getRichDescription(event),
location: getLocation(event),
organizer: { email: event.organizer.email, name: event.organizer.name },
// TODO Use `name`, `email`, and `scheduleAgent` once https://github.com/adamgibbons/ics/pull/248 is merged
organizer: {
name: `${event.organizer.name}:MAILTO:${event.organizer.email}:SCHEDULE-AGENT=CLIENT`,
},
attendees: this.getAttendees(event),
/** according to https://datatracker.ietf.org/doc/html/rfc2446#section-3.2.1, in a published iCalendar component.
* "Attendees" MUST NOT be present
Expand Down Expand Up @@ -228,7 +233,10 @@ export default abstract class BaseCalendarService implements Calendar {
title: event.title,
description: getRichDescription(event),
location: getLocation(event),
organizer: { email: event.organizer.email, name: event.organizer.name },
// TODO Use `name`, `email`, and `scheduleAgent` once https://github.com/adamgibbons/ics/pull/248 is merged
organizer: {
name: `${event.organizer.name}:MAILTO:${event.organizer.email}:SCHEDULE-AGENT=CLIENT`,
},
attendees: this.getAttendees(event),
});

Expand Down

0 comments on commit 1cf788d

Please sign in to comment.