ical.net icon indicating copy to clipboard operation
ical.net copied to clipboard

CalendarProperty isn't properly serialized

Open rianjs opened this issue 8 years ago • 4 comments

[Test]
[Ignore("Calendar properties aren't being properly serialized")]
public void PropertySerialization_Tests()
{
    const string formatted =
@"FMTTYPE=text/html:<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 3.2//EN"">\n<HTML>\n<HEAD>\n<META NAME=""Generator"" CONTENT=""MS Exchange Server version rmj.rmm.rup.rpr"">\n<TITLE></TITLE>\n</HEAD>\n<BODY>\n<!-- Converted from text/rtf format -->\n\n<P DIR=LTR><SPAN LANG=""en-us""><FONT FACE=""Calibri"">This is some</FONT></SPAN><SPAN LANG=""en-us""><B> <FONT FACE=""Calibri"">HTML</FONT></B></SPAN><SPAN LANG=""en-us""><FONT FACE=""Calibri""></FONT></SPAN><SPAN LANG=""en-us""><U> <FONT FACE=""Calibri"">formatted</FONT></U></SPAN><SPAN LANG=""en-us""><FONT FACE=""Calibri""></FONT></SPAN><SPAN LANG=""en-us""><I> <FONT FACE=""Calibri"">text</FONT></I></SPAN><SPAN LANG=""en-us""><FONT FACE=""Calibri"">.</FONT></SPAN><SPAN LANG=""en-us""></SPAN></P>\n\n</BODY>\n</HTML>";

    var start = DateTime.Now;
    var end = start.AddHours(1);
    var @event = new Event
    {
        Start = new CalDateTime(start),
        End = new CalDateTime(end),
        Description = "This is a description",
    };
    var property = new CalendarProperty("X-ALT-DESC", formatted);
    @event.AddProperty(property);
    var calendar = new Calendar();
    calendar.Events.Add(@event);

    var serialized = new CalendarSerializer().SerializeToString(calendar);
    Assert.IsTrue(serialized.Contains("X-ALT-DESC;"));
}

Test case from http://stackoverflow.com/questions/41304898/how-do-i-create-an-html-formatted-ics-message-body-using-ical-net

rianjs avatar Dec 23 '16 19:12 rianjs

(Don't forget to delete the [Ignore] attribute when the bug is fixed!)

rianjs avatar Dec 23 '16 19:12 rianjs

Im unsure if this bug still exists, since you have a typo in the assert (should be colon instead of semi-colon).

Assert.IsTrue(serialized.Contains("X-ALT-DESC;"));

should be

Assert.IsTrue(serialized.Contains("X-ALT-DESC:"));

If you change the typo, the test passes.

fosterbuster avatar Aug 23 '17 08:08 fosterbuster

I just stumbled over this while trying to find out how to set the X-ALT-DESC property for a HTML description. In my implementation I set the name of the property to include the type of the payload:

var property = new CalendarProperty("X-ALT-DESC;FMTTYPE=text/html", "<!DOCTYPE HTML PUBLIC ""-//W3..." );

This gives the expected result and should fix our test, since the original assertion is correct.

alex3683 avatar May 14 '18 12:05 alex3683

The above workaround worked for me in Outlook to get formatted HTML in the calendar event. I'm astounded that it still in 2023 doesn't just accept HTML in the event description as any sane calendar service should.

However, the HTML boilerplate does not seem necessary. In my testing, Outlook was quite happy with a bare minimum HTML document:

<html>
<body>
<h1>Title</h1>
<b>Bold text</b>
</body>
</html>

angularsen avatar Jan 31 '23 08:01 angularsen