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 192 forks source link

Error "Incorrect ics/ical URL" syncing an outlook calendar #388

Closed konraddecker closed 9 months ago

konraddecker commented 9 months ago

The problem

Unfortunately the sync stopped working for me recently. The following error is displayed in the console (see Screenshot) 2023-12-11 08_40_32-

I have already recreated the Outlook calendar share and generated new links. Unfortunately it does not work.

is this bug known? Is there a fix for this?

Version of GAS-ICS-Sync

5.7

Additional information & file uploads

No response

irqnet commented 9 months ago

Same here, seems that fetching the ics url timed out, which leads into removal of all existing calendar entries.

Would it be possible to check whether the content is empty to give it a retry? Putting that URL into a browser to download the ics manually take a while, so I assume it's just a timeout issue.

https://github.com/derekantrican/GAS-ICS-Sync/blob/9990d1b037bbc3e2d72f130f8a815c0f71bd3bcd/Helpers.gs#L74

Kucladell commented 9 months ago

I was experiencing the same issue separately, and was able to analyze the problem and come up with a solution. Please refer to the information below.

The underlying issue

Microsoft Outlook/365's calendar share is outputting ICS files that are incompliant to ICS standards. The specific issues that affect GAS-ICS-Sync are as follows:

How to fix

This issue can be resolved by fixing the ICS file to comply to ICS standards before parsing. Add the following changes in the Helpers.gs file:

Final thoughts

The code above is a very crude attempt to fix this issue; this does solve the sync issue, but please add a comment below if you have a more elegant solution.

It is unclear as to why this issue suddenly appeared. Did Microsoft Outlook/365 suddenly began writing ICS file incorrectly? Is there something wrong on the parser side? I would appreciate any details and discussions below.

Kucladell commented 9 months ago

Same here, seems that fetching the ics url timed out, which leads into removal of all existing calendar entries.

Would it be possible to check whether the content is empty to give it a retry? Putting that URL into a browser to download the ics manually take a while, so I assume it's just a timeout issue.

https://github.com/derekantrican/GAS-ICS-Sync/blob/9990d1b037bbc3e2d72f130f8a815c0f71bd3bcd/Helpers.gs#L74

As for the issue of all existing calendar entries being removed, you may want to implement some changes in the code to prevent this from happenig. The issue below provides a solution you can use. https://github.com/derekantrican/GAS-ICS-Sync/issues/343

konraddecker commented 9 months ago

thanks, the fix worked.

Is this an Office365 error? Some calendars take longer to download the ics file?

jonas0b1011001 commented 9 months ago

Is this an Office365 error

Yes, this is a bug in the latest Outlook version. See #386 for more.

@Kucladell Thanks for your solution, I have not had time to thoroughly test this, just 2 quick inputs:

  1. Your code will leave the last VEVENT component unfixed as it always fixes the component above the one you are currently looking at.
  2. END:VCALENDAR is added at the wrong position, splice basically adds the items before the index you provide. You have to either use lines.splice(lines.length , 0, 'END:VCALENDAR'); or just use lines.push('END:VCALENDAR');
Kucladell commented 9 months ago

@konraddecker Glad to be able to help! Thank you as well for confirming that the fix indeed works.

@jonas0b1011001 Thank you for the detailed input! I am not well versed in Javascript (and programming in general) so I deeply appreciate your feedback. As for the points you raised:

  1. You are correct that the last VEVENT component will remain unfixed. I initially took this approach since Microsoft's flawed output file has a 'END:VEVENT' at the last VEVENT component. ~I will attempt to come up with a more thorough code that doesn't rely on a specific type of error.~
  2. This is due to my incompetence; I initially used lines.push() but this ended up with a blank line before the last line, so I ended up with this botch. The current fix above works only because the parser reads from BEGIN:VCALENDAER to END:VCALENDAR and ignores anything that comes after. ~I will have another go at this.~

(Edit: A better solution is proposed, so removed comments on improving my code.)

Kucladell commented 9 months ago

@jonas0b1011001 I see that you proposed a more elegant solution at https://github.com/derekantrican/GAS-ICS-Sync/pull/386 . I suggest you go ahead with this!

arcegabriel commented 9 months ago

Just logged in to say thanks for @Kucladell for the fix. It was driving me crazy

Kucladell commented 9 months ago

@arcegabriel Thank you for the kind words! A more elegant solution is coming up soon by @jonas0b1011001, but glad to be able to help in the meantime. This is the first time I shared my code to someone else so this means a lot to me.

derekantrican commented 9 months ago

Closing via #386 . Release with the fix coming shortly

brenthaag commented 9 months ago

My syncing started doing this sometime before I got up for the day, but by mid-morning it started working again! Not sure what microsoft is doing, but I'm very glad there may be a solution I should implement when it happens again.

Thank you!