From e5d94e74a2c4907b63a67249d57f59f6623f0d5f Mon Sep 17 00:00:00 2001 From: nicolas Date: Wed, 21 Jul 2021 14:01:48 +0200 Subject: [PATCH 1/6] No HTMl in rich event description --- lib/CalEventParser.ts | 9 +++++++++ lib/calendarClient.ts | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/CalEventParser.ts b/lib/CalEventParser.ts index 69724ccc..ef1ff315 100644 --- a/lib/CalEventParser.ts +++ b/lib/CalEventParser.ts @@ -86,4 +86,13 @@ export default class CalEventParser { eventCopy.description = this.getRichDescriptionHtml(); return eventCopy; } + + /** + * Returns a calendar event with rich description as plain text. + */ + public asRichEventPlain(): CalendarEvent { + const eventCopy: CalendarEvent = { ...this.calEvent }; + eventCopy.description = this.getRichDescription(); + return eventCopy; + } } diff --git a/lib/calendarClient.ts b/lib/calendarClient.ts index 3891feab..b64e0bf8 100644 --- a/lib/calendarClient.ts +++ b/lib/calendarClient.ts @@ -508,7 +508,7 @@ const listCalendars = (withCredentials) => const createEvent = async (credential: Credential, calEvent: CalendarEvent): Promise => { const parser: CalEventParser = new CalEventParser(calEvent); const uid: string = parser.getUid(); - const richEvent: CalendarEvent = parser.asRichEvent(); + const richEvent: CalendarEvent = parser.asRichEventPlain(); const creationResult = credential ? await calendars([credential])[0].createEvent(richEvent) : null; @@ -555,7 +555,7 @@ const updateEvent = async ( ): Promise => { const parser: CalEventParser = new CalEventParser(calEvent); const newUid: string = parser.getUid(); - const richEvent: CalendarEvent = parser.asRichEvent(); + const richEvent: CalendarEvent = parser.asRichEventPlain(); const updateResult = credential ? await calendars([credential])[0].updateEvent(uidToUpdate, richEvent) From 39f16d95cb777998241fb382ac780fd29451c8c7 Mon Sep 17 00:00:00 2001 From: nicolas Date: Wed, 21 Jul 2021 14:25:28 +0200 Subject: [PATCH 2/6] Properly replace a link tags --- lib/emails/helpers.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/emails/helpers.ts b/lib/emails/helpers.ts index e5218a0a..929a0556 100644 --- a/lib/emails/helpers.ts +++ b/lib/emails/helpers.ts @@ -25,5 +25,9 @@ export function getFormattedMeetingId(videoCallData: VideoCallData): string { } export function stripHtml(html: string): string { - return html.replace("
", "\n").replace(/<[^>]+>/g, ""); + const aLinkRegExp = /"]*)"[\s\w="_:#;]*>([^<>]*)<\/a>/g; + return html + .replace("
", "\n") + .replace(aLinkRegExp, "$2: $1") + .replace(/<[^>]+>/g, ""); } From 13a6b9b54934b94f9d03c3f480167611209502af Mon Sep 17 00:00:00 2001 From: nicolas Date: Wed, 21 Jul 2021 18:20:08 +0200 Subject: [PATCH 3/6] Use regex to remove br tag --- lib/emails/helpers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/emails/helpers.ts b/lib/emails/helpers.ts index 929a0556..7c778ce4 100644 --- a/lib/emails/helpers.ts +++ b/lib/emails/helpers.ts @@ -27,7 +27,7 @@ export function getFormattedMeetingId(videoCallData: VideoCallData): string { export function stripHtml(html: string): string { const aLinkRegExp = /"]*)"[\s\w="_:#;]*>([^<>]*)<\/a>/g; return html - .replace("
", "\n") + .replace(//g, "\n") .replace(aLinkRegExp, "$2: $1") .replace(/<[^>]+>/g, ""); } From 0a60a62910e1d05be4183eb7109a32a322f72737 Mon Sep 17 00:00:00 2001 From: nicolas Date: Thu, 22 Jul 2021 00:46:31 +0200 Subject: [PATCH 4/6] Conditionally use HTML --- lib/calendarClient.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/calendarClient.ts b/lib/calendarClient.ts index b64e0bf8..662b02e6 100644 --- a/lib/calendarClient.ts +++ b/lib/calendarClient.ts @@ -508,7 +508,13 @@ const listCalendars = (withCredentials) => const createEvent = async (credential: Credential, calEvent: CalendarEvent): Promise => { const parser: CalEventParser = new CalEventParser(calEvent); const uid: string = parser.getUid(); - const richEvent: CalendarEvent = parser.asRichEventPlain(); + /* + * Matching the credential type is a workaround because the office calendar simply strips away newlines (\n and \r). + * We need HTML there. Google Calendar understands newlines and Apple Calendar cannot show HTML, so no HTML should + * be used for Google and Apple Calendar. + */ + const richEvent: CalendarEvent = + credential.type === "office365_calendar" ? parser.asRichEvent() : parser.asRichEventPlain(); const creationResult = credential ? await calendars([credential])[0].createEvent(richEvent) : null; From 936338db3ec4adae08905025a8314fe86ca7d936 Mon Sep 17 00:00:00 2001 From: nicolas Date: Thu, 22 Jul 2021 01:11:25 +0200 Subject: [PATCH 5/6] Added condition when updating event --- lib/calendarClient.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/calendarClient.ts b/lib/calendarClient.ts index 662b02e6..711cfc14 100644 --- a/lib/calendarClient.ts +++ b/lib/calendarClient.ts @@ -561,7 +561,8 @@ const updateEvent = async ( ): Promise => { const parser: CalEventParser = new CalEventParser(calEvent); const newUid: string = parser.getUid(); - const richEvent: CalendarEvent = parser.asRichEventPlain(); + const richEvent: CalendarEvent = + credential.type === "office365_calendar" ? parser.asRichEvent() : parser.asRichEventPlain(); const updateResult = credential ? await calendars([credential])[0].updateEvent(uidToUpdate, richEvent) From 749693b6bfc372cfd5901ca5c4e25679d6182575 Mon Sep 17 00:00:00 2001 From: nicolas Date: Sat, 24 Jul 2021 21:23:15 +0200 Subject: [PATCH 6/6] Always use plain text event descriptions for now --- lib/calendarClient.ts | 6 ++---- lib/emails/helpers.ts | 2 ++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/calendarClient.ts b/lib/calendarClient.ts index 711cfc14..7eb37632 100644 --- a/lib/calendarClient.ts +++ b/lib/calendarClient.ts @@ -513,8 +513,7 @@ const createEvent = async (credential: Credential, calEvent: CalendarEvent): Pro * We need HTML there. Google Calendar understands newlines and Apple Calendar cannot show HTML, so no HTML should * be used for Google and Apple Calendar. */ - const richEvent: CalendarEvent = - credential.type === "office365_calendar" ? parser.asRichEvent() : parser.asRichEventPlain(); + const richEvent: CalendarEvent = parser.asRichEventPlain(); const creationResult = credential ? await calendars([credential])[0].createEvent(richEvent) : null; @@ -561,8 +560,7 @@ const updateEvent = async ( ): Promise => { const parser: CalEventParser = new CalEventParser(calEvent); const newUid: string = parser.getUid(); - const richEvent: CalendarEvent = - credential.type === "office365_calendar" ? parser.asRichEvent() : parser.asRichEventPlain(); + const richEvent: CalendarEvent = parser.asRichEventPlain(); const updateResult = credential ? await calendars([credential])[0].updateEvent(uidToUpdate, richEvent) diff --git a/lib/emails/helpers.ts b/lib/emails/helpers.ts index 7c778ce4..5c07dbbe 100644 --- a/lib/emails/helpers.ts +++ b/lib/emails/helpers.ts @@ -25,9 +25,11 @@ export function getFormattedMeetingId(videoCallData: VideoCallData): string { } export function stripHtml(html: string): string { + const aMailToRegExp = /"]*)"[\s\w="_:#;]*>([^<>]*)<\/a>/g; const aLinkRegExp = /"]*)"[\s\w="_:#;]*>([^<>]*)<\/a>/g; return html .replace(//g, "\n") + .replace(aMailToRegExp, "$1") .replace(aLinkRegExp, "$2: $1") .replace(/<[^>]+>/g, ""); }