Enough-Software / enough_icalendar

iCalendar library to parse, generate and respond to iCal / ics invites. Fully compliant with RFC 5545 (iCalendar) and RFC 5546 (iTIP).
Mozilla Public License 2.0
9 stars 9 forks source link

Support Apple version of iCalendar #6

Closed martingeorgiu closed 2 years ago

martingeorgiu commented 2 years ago

To be honest, I'm really not sure, whether this should be merged as it might violate the standard on which this library is based. However, without these changes, I was not able to parse generated iCalendar from Apple Calendar. The better way might be to have some bool when parsing the String, whether to support Apple taste of iCalendar. Then people that need to support Apple Calendar can parse it without any issues, and everyone else will be happily using the standard.

martingeorgiu commented 2 years ago

Sorry for a bit messy PR, because it is based on the previous PR https://github.com/Enough-Software/enough_icalendar/pull/5

However, I didn't want to make a final solution as I wanted to know your take on this before.

robert-virkus commented 2 years ago

Hi Martin, removing validity checks may indeed not the best way to handle this. Is there a way how to recognize Apple Calendar formats apart from not being fully standards compliant? Maybe we could detect that and that adjust the checking automatically? Of course, the user of the lib should be able to override this behavior, e.g. with setting a FormatChecking enum (strict, loose). What do you think?

Maybe it helps if you could share some typical Apple formats here - or send them to me via robert-at-enough-dot-de.

Thanks, Robert

martingeorgiu commented 2 years ago

Yeah totally agree! I've created a new Apple calendar with which you can reproduce the bug. In fact, there are two issues with the final result. One is the incorrect timezones, but the other is that X-APPLE-STRUCTURED-LOCATION parameter, is breaking the parsing as well. I'm using this workaround for now, but when you would be adding some loose check, this should I believe be also included:

VComponent _getAppleVComponentFromString(String data) {
  final containsStandardCompliantLineBreaks = data.contains('\r\n');
  final foldedLines = containsStandardCompliantLineBreaks
      ? data.split('\r\n')
      : data.split('\n');
  final lines = VComponent.unfold(
    foldedLines,
    containsStandardCompliantLineBreaks: containsStandardCompliantLineBreaks,
  ).where((e) => !e.startsWith('X-')).toList();
  return VComponent.parseLines(lines);
}

test-apple-calendar.ics.zip

robert-virkus commented 2 years ago

Hey Martin, thanks for the example. Can you test parsing with the latest git version of enough_icalendar? I think the package can now parse your invitation correctly.

martingeorgiu commented 2 years ago

Yay, it works now! Thanks a lot Robert!

robert-virkus commented 2 years ago

Thanks for confirming, I have now released v0.12.0 with your changes!

martingeorgiu commented 2 years ago

Hi Robert, I'm so sorry for misinforming you, however on most of my test Apple calendars, it now works flawlessly. But when I've run it on my main calendar, there are still two issues.

The first is there is an empty line in the middle of the .ics. This in fact was the original goal to fix with this PR. The second issue is still with the X-APPLE-STRUCTURED-LOCATION. I've cherry-picked both of the issues, and I'm sending you a new .ics file to test things out. Hopefully, there won't be needed any other changes. The way I'm parsing the calendars for now without any issues is using martingeorgiu:feat/allowEmptyLines and _getAppleVComponentFromString() method I've mentioned here https://github.com/Enough-Software/enough_icalendar/pull/6#issuecomment-1259252625

test-apple-calendar.ics.zip

robert-virkus commented 2 years ago

Thanks Martin, I have integrated your changes, added some improvements and released v0.13.0. Please check, if you still run into problems. Specificially, there should be no need to ignore any properties for Apple-originating invites, so please test without your custom _getAppleVComponentFromString method.

martingeorgiu commented 2 years ago

Cool, version 0.13.0 now works even with the main calendar I have used daily for many years. Thanks a lot, @robert-virkus for such great work!

robert-virkus commented 2 years ago

Glad that it works now, thanks for your report and support!