From 9c8ac96aede3385a01c7d60ea8d4b8a085780d68 Mon Sep 17 00:00:00 2001 From: Abin Simon Date: Tue, 6 Feb 2024 22:33:58 +0530 Subject: [PATCH] Skip emails with incorrect email when export ics file (#5190) --- #### Does this PR need a docs update or release note? - [ ] :white_check_mark: Yes, it's included - [ ] :clock1: Yes, but in a later PR - [x] :no_entry: No #### Type of change - [ ] :sunflower: Feature - [x] :bug: Bugfix - [ ] :world_map: Documentation - [ ] :robot: Supportability/Tests - [ ] :computer: CI/Deployment - [ ] :broom: Tech Debt/Cleanup #### Issue(s) * # #### Test Plan - [ ] :muscle: Manual - [x] :zap: Unit test - [ ] :green_heart: E2E --- src/internal/converters/ics/ics.go | 22 +++++++++++++++++++++- src/internal/converters/ics/ics_test.go | 11 +++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/internal/converters/ics/ics.go b/src/internal/converters/ics/ics.go index 291d78bdf..af33ae1ac 100644 --- a/src/internal/converters/ics/ics.go +++ b/src/internal/converters/ics/ics.go @@ -5,6 +5,7 @@ import ( "encoding/base64" "encoding/json" "fmt" + "net/mail" "strings" "time" "unicode" @@ -279,6 +280,12 @@ func isASCII(s string) bool { return true } +// Checks if a given string is a valid email address +func isEmail(em string) bool { + _, err := mail.ParseAddress(em) + return err == nil +} + func updateEventProperties(ctx context.Context, event models.Eventable, iCalEvent *ics.VEvent) error { // CREATED - https://www.rfc-editor.org/rfc/rfc5545#section-3.8.7.1 created := event.GetCreatedDateTime() @@ -481,8 +488,21 @@ func updateEventProperties(ctx context.Context, event models.Eventable, iCalEven } } + // It is possible that we get non email items like the below + // one which is an internal representation of the user in the + // Exchange system. While we can technically output this as an + // attendee, it is not useful plus other downstream tools like + // ones to use PST can choke on this. + // /o=ExchangeLabs/ou=ExchangeAdministrative Group(FY...LT)/cn=Recipients/cn=883...4a-John Doe addr := ptr.Val(attendee.GetEmailAddress().GetAddress()) - iCalEvent.AddAttendee(addr, props...) + if isEmail(addr) { + iCalEvent.AddAttendee(addr, props...) + } else { + logger.Ctx(ctx). + With("attendee_email", addr). + With("attendee_name", name). + Info("skipping non email attendee from ics export") + } } // LOCATION - https://www.rfc-editor.org/rfc/rfc5545#section-3.8.1.7 diff --git a/src/internal/converters/ics/ics_test.go b/src/internal/converters/ics/ics_test.go index 798d2f595..0e2c24a78 100644 --- a/src/internal/converters/ics/ics_test.go +++ b/src/internal/converters/ics/ics_test.go @@ -908,6 +908,17 @@ func (suite *ICSUnitSuite) TestAttendees() { "attendee") }, }, + { + name: "attendee with internal exchange representation for email", + att: [][]string{{ + "/o=ExchangeLabs/ou=ExchangeAdministrative Group(FY...LT)/cn=Recipients/cn=883...4a-John Doe", + "required", + "declined", + }}, + check: func(out string) { + assert.NotContains(t, out, "ATTENDEE") + }, + }, { name: "multiple attendees", att: [][]string{