arran4 / golang-ical

A ICS / ICal parser and serialiser for Golang.
Apache License 2.0
310 stars 73 forks source link

optional/generic serializing #97

Closed masterElmar closed 1 month ago

masterElmar commented 2 months ago

As iam working on a calendar/ics implementation for mozilla thunderbird and google calendar. For the Description field they are using html representation within google calendar:

DESCRIPTION:Test: Hello Link: <a href="https://google.de">Google</a>

And for mozilla thunderbird they using the altrep property:

DESCRIPTION;ALTREP="data:text/html,Profs%3A%20Test.%20Hello%3Cbr%3EGruppen%3A%2021BIKb%3Cbr%3ETyp%3A%20V%3Cbr%3ELink%3A%20%3Ca%
 20href%3D%22https%3A%2F%2Fgoogle.de%2FZU430%22%3EGoogle%3C%2Fa%3E":
 Profs: Hello\nGruppen: 21BIKb\nTyp: V
 \nLink: Google

When iam adding the property

&ics.KeyValues{
        Key:   string(ics.ParameterAltrep),
        Value: []string{altRepUrl},
    }

vEvent.AddProperty(ics.ComponentPropertyDescription, description, altrepParam)

I need the optional functionality to disable the serialize function for the altrep because thunderbird uses its own serializer url/html data:text/html, + url.PathEscape(htmlDescription)

I already tried to "override" the serializer, but this gets really complecated and it would be a nice optional to disable/generic/replace it for a component or property.

If anyone can help me with this problem, I would be very pleased. Many thanks for the great ical library.

arran4 commented 2 months ago

@masterElmar I have a busy couple days I will try dig in over the next 8 days.

masterElmar commented 2 months ago

Anything new about this request?

arran4 commented 1 month ago

Do you think you could provide a small sample of a complete file I can use as a test?

masterElmar commented 1 month ago

This is one Example from Thunderbird:

BEGIN:VCALENDAR
PRODID:-//Mozilla.org/NONSGML Mozilla Calendar V1.1//EN
VERSION:2.0
BEGIN:VTIMEZONE
TZID:Europe/Berlin
X-TZINFO:Europe/Berlin[2024a]
BEGIN:STANDARD
TZOFFSETTO:+010000
TZOFFSETFROM:+005328
TZNAME:Europe/Berlin(STD)
DTSTART:18930401T000000
RDATE:18930401T000000
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
CREATED:20240929T120640Z
LAST-MODIFIED:20240929T120731Z
DTSTAMP:20240929T120731Z
UID:d23cef0d-9e58-43c4-9391-5ad8483ca346
SUMMARY:Test Event
DTSTART;TZID=Europe/Berlin:20240929T144500
DTEND;TZID=Europe/Berlin:20240929T154500
TRANSP:OPAQUE
LOCATION:Github
DESCRIPTION;ALTREP="data:text/html,I%20want%20
 a%20custom%20linkout%20for%20
 Thunderbird.%3Cbr%3EThis%20is%20the%20Github%20
 %3Ca%20href%3D%22https%3A%2F
 %2Fgithub.com%2Farran4%2Fgolang-ical%2Fissues%2F97%22
 %3EIssue%3C%2Fa%3E.":I
  want a custom linkout for Thunderbird.\nThis is the Github Issue.
END:VEVENT
END:VCALENDAR

This is one from Google:

BEGIN:VCALENDAR
PRODID:-//Google Inc//Google Calendar 70.9054//EN
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:PUBLISH
X-WR-CALNAME:Test
X-WR-TIMEZONE:Europe/Berlin
BEGIN:VEVENT
DTSTART:20240929T124500Z
DTEND:20240929T134500Z
DTSTAMP:20240929T121653Z
UID:al23c5kr943d42u3bqoqrkf455@google.com
CREATED:20240929T121642Z
DESCRIPTION:I want a custom linkout for Thunderbird.<br>This is the Github 
 <a href="https://github.com/arran4/golang-ical/issues/97">Issue</a>.
LAST-MODIFIED:20240929T121642Z
LOCATION:GitHub
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:Test Event
TRANSP:OPAQUE
END:VEVENT
END:VCALENDAR

Sorry that these files are Code Sections, but Github dont support ics file type.

Hope that these are examples that you need? If i could support or help you let me know. 😊 Thank you for the time and effort.

arran4 commented 1 month ago

Sorry that these files are Code Sections, but Github dont support ics file type.

All good. I will build tests around these to ensure they serialize and de-serialize. Definitely out of scope is building a html parser in it though.. Although I would like to, but I would need funding. :P

masterElmar commented 1 month ago

All good. I will build tests around these to ensure they serialize and de-serialize. Definitely out of scope is building a html parser in it though.. Although I would like to, but I would need funding. :P

Yeah, that's not the task even if there could be more special encodings in the ALTREP so an optional flag that enables or disables the default serializing or a custom encoder that could be pasted into your current ical decoding library.

BenediktBeigang commented 1 month ago

Fixing this would be very helpful for me🫤

arran4 commented 1 month ago

Okay I took a good look at this...

This looks like a spec error:

https://icalendar.org/iCalendar-RFC-5545/3-2-1-alternate-text-representation.html

Well where it is falling short.

I have attempted to make the first pass of changes for this here:

https://github.com/arran4/golang-ical/pull/106

Please review the PR!!! (By testing it) -- I might need to make some more changes to it.. I had a lot of trouble with the parameter and word wrapping.

Please checkout: cmd/issues/test97_1/main.go Where I was able to generate the output:

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Mozilla.org/NONSGML Mozilla Calendar V1.1//Golang ICS Library
BEGIN:VTIMEZONE
TZID:Europe/Berlin
X-X-:Europe/Berlin[2024a]
BEGIN:STANDARD
TZOFFSETTO:+010000
TZOFFSETFROM:+005328
TZNAME:Europe/Berlin(STD)
DTSTART:18930401T000000
RDATE:18930401T000000
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
UID:d23cef0d-9e58-43c4-9391-5ad8483ca346
CREATED:20240929T120640Z
LAST-MODIFIED:20240929T120731Z
DTSTAMP:20240929T120731Z
SUMMARY:Test Event
DTSTART;TZID=Europe/Berlin:20240929T144500
DTEND;TZID=Europe/Berlin:20240929T154500
TRANSP:OPAQUE
LOCATION:Github
DESCRIPTION;ALTREP="data:text/html,I%20want%20a%20custom%20linkout%20for%20
 Thunderbird.%3Cbr%3EThis%20is%20the%20Github%20%3Ca%20href%3D%22https%3A%2
 F%2Fgithub.com%2Farran4%2Fgolang-ical%2Fissues%2F97%22%3EIssue%3C%2Fa%3E."
 :I want a custom linkout for Thunderbird.\nThis is the Github Issue.
END:VEVENT
END:VCALENDAR

https://github.com/arran4/golang-ical/blob/5274eb179ac84c2e3899b30cc7a43eb3d0e91dec/cmd/issues/test97_1/main.go

I am not sure how:

DESCRIPTION;ALTREP="data:text/html,I%20want%20
 a%20custom%20linkout%20for%20
 Thunderbird.%3Cbr%3EThis%20is%20the%20Github%20
 %3Ca%20href%3D%22https%3A%2F
 %2Fgithub.com%2Farran4%2Fgolang-ical%2Fissues%2F97%22
 %3EIssue%3C%2Fa%3E.":I
  want a custom linkout for Thunderbird.\nThis is the Github Issue.

Is being wrapped...

I get:

DESCRIPTION;ALTREP="data:text/html,I%20want%20a%20custom%20linkout%20for%20
 Thunderbird.%3Cbr%3EThis%20is%20the%20Github%20%3Ca%20href%3D%22https%3A%2
 F%2Fgithub.com%2Farran4%2Fgolang-ical%2Fissues%2F97%22%3EIssue%3C%2Fa%3E."
 :I want a custom linkout for Thunderbird.\nThis is the Github Issue.

I was attempting to add an override for that, however unless it's found in the RFCs it's out of scope.

masterElmar commented 1 month ago

   Example:  The following is an example of this property referencing
      textual contact information:

       CONTACT:Jim Dolittle\, ABC Industries\, +1-919-555-1234

      The following is an example of this property with an alternate
      representation of an LDAP URI to a directory entry containing the
      contact information:

       CONTACT;ALTREP="ldap://example.com:6666/o=ABC%20Industries\,
        c=US???(cn=Jim%20Dolittle)":Jim Dolittle\, ABC Industries\,
        +1-919-555-1234

      The following is an example of this property with an alternate
      representation of a MIME body part containing the contact
      information, such as a vCard [RFC2426] embedded in a text/
      directory media type [RFC2425]:

       CONTACT;ALTREP="CID:part3.msg970930T083000SILVER@example.com":
        Jim Dolittle\, ABC Industries\, +1-919-555-1234

Found this example at https://www.ietf.org/rfc/rfc5545.txt and as far as i tested the other altreps it works.

arran4 commented 1 month ago

Merged!