derekantrican / GAS-ICS-Sync

A Google Apps Script for syncing ICS/ICAL files faster than the current Google Calendar speed
GNU General Public License v3.0
1.5k stars 191 forks source link

Script stops execution of events if iCal has a color unknown to Google Calendar #308

Closed obbardc closed 9 months ago

obbardc commented 1 year ago

Hi! I am really loving this script, thanks for supporting it.

It seems that there are two issues I want to create here:

1) (a side note) If an event fails to be added to the calander, it stops executing all other events. If this happens early in the list, then the script effectively ignores all the other events to process. Would it be worth having a try/catch around each event in the for loop?

      vevents.forEach(function(e){
        processEvent(e, calendarTz);
      });

2) iCal events with an unsupported color (e.g. khaki) cause the Google API to return an error and this error is just thrown and then the script just exits (see point 1 above). We should sanitise the colorId and make sure that the Google API supports that colour. For now, I have simply commented these three lines out since my events don't need colours.

  if (event.hasProperty('color')){
    newEvent.colorId = event.getFirstPropertyValue('color').toString();
  }
obbardc commented 1 year ago

An example ical event (see COLOR:khaki):

BEGIN:VEVENT
UID:ID
DTSTAMP:20221108T125544Z
DTSTART;TZID=Europe/London:20221111T100000
DTEND;TZID=Europe/London:20221111T103000
SEQUENCE:3
SUMMARY:summary
LOCATION:location
TRANSP:OPAQUE
CLASS:PUBLIC
CREATED:20221109T105640Z
LAST-MODIFIED:20221109T105657Z
COLOR:khaki
ATTENDEE;ROLE=REQ-PARTICIPANT;RSVP=TRUE;PARTSTAT=NEEDS-ACTION;CN=Name;CUTYPE=INDIVIDUAL:mailto:email@example.com
ORGANIZER:mailto:email@example.com
END:VEVENT
derekantrican commented 1 year ago

May be a dupe of #93

simonegiusti commented 12 months ago

Hello, I have a problem with COLOR: tag ...

This works:

BEGIN:VCALENDAR
PRODID:rockjob calendar2
VERSION:2.0
METHOD:REQUEST
X-WR-CALNAME:rockjob calendar2
X-WR - TimeZone: UTC
BEGIN:VEVENT
UID:260
DTSTAMP:20230923T174352Z
CREATED:20230923T174352Z
LOCATION:Sala Prove - RHO
SEQUENCE:20230923174352
STATUS:CONFIRMED
LAST-MODIFIED:20230923T174352Z
DESCRIPTION:
SUMMARY:PP, RHO - Sala Prove
DTSTART:20231023
DTEND:20231023
X-FUNAMBOL-ALLDAY:TRUE
X-MICROSOFT-CDO-ALLDAYEVENT:TRUE
TRANSP:OPAQUE
END:VEVENT

This does not:

BEGIN:VCALENDAR PRODID:rockjob calendar2 VERSION:2.0 METHOD:REQUEST X-WR-CALNAME:rockjob calendar2 X-WR - TimeZone: UTC BEGIN:VEVENT UID:260 DTSTAMP:20230923T174352Z CREATED:20230923T174352Z COLOR:RED LOCATION:Sala Prove - RHO SEQUENCE:20230923174352 STATUS:CONFIRMED LAST-MODIFIED:20230923T174352Z DESCRIPTION: SUMMARY:PP, RHO - Sala Prove DTSTART:20231023 DTEND:20231023 X-FUNAMBOL-ALLDAY:TRUE X-MICROSOFT-CDO-ALLDAYEVENT:TRUE TRANSP:OPAQUE END:VEVENT

this is the error: image

Any suggestion appreciated ..

obbardc commented 12 months ago

I think we need to ignore the colour tag if it's not able to be mapped to a gcal colour.

jonas0b1011001 commented 12 months ago

@simonegiusti Please test the following change:

Replace Helpers.gs lines 475-477

  if (event.hasProperty('color')){
    newEvent.colorId = event.getFirstPropertyValue('color').toString();
  }

with:

  if (event.hasProperty('color')){
    let colorID = event.getFirstPropertyValue('color').toString();
    if (Object.keys(CalendarApp.EventColor).includes(colorID)){
      newEvent.colorId = CalendarApp.EventColor[colorID];
    }else if(Object.values(CalendarApp.EventColor).includes(colorID)){
      newEvent.colorId = colorID;
    }; //else unsupported value
  }
simonegiusti commented 12 months ago

@simonegiusti Please test the following change:

Replace Helpers.gs lines 475-477

  if (event.hasProperty('color')){
    newEvent.colorId = event.getFirstPropertyValue('color').toString();
  }

with:

  if (event.hasProperty('color')){
    let colorID = event.getFirstPropertyValue('color').toString();
    if (Object.keys(CalendarApp.EventColor).includes(colorID)){
      newEvent.colorId = CalendarApp.EventColor[colorID];
    }else if(Object.values(CalendarApp.EventColor).includes(colorID)){
      newEvent.colorId = colorID;
    }; //else unsupported value
  }

Now it works perfectly !! Many thanks ...

obbardc commented 11 months ago

This should be open until it's merged right ?

jonas0b1011001 commented 11 months ago

@obbardc Does this fix your 2. issue aswell?

obbardc commented 11 months ago

@jonas0b1011001 yeah, it just doesn't set the colour as expected :-) Can you open a PR, please ?

jonas0b1011001 commented 11 months ago

@jonas0b1011001 yeah, it just doesn't set the colour as expected :-) Can you open a PR, please ?

Well we are limited to the colors google offers us. We have discussed manually matching colors a while ago but i have no idea how to do that.

obbardc commented 11 months ago

@jonas0b1011001 yeah, it just doesn't set the colour as expected :-) Can you open a PR, please ?

Well we are limited to the colors google offers us. We have discussed manually matching colors a while ago but i have no idea how to do that.

No, I mean with this patch it is fine. If the ics has a colour which google doesn't understand, it sets it to default. Which is good for me.

I don't care about colours in the destination calendar anyway ;-).