Skip to content

Commit c2ad716

Browse files
committed
feat: add support for more props on CalDAV MKCOL and PROPFIND on calendars
1 parent 25f1014 commit c2ad716

File tree

6 files changed

+361
-25
lines changed

6 files changed

+361
-25
lines changed

caldav/caldav.go

+2
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ type Calendar struct {
6767
Path string
6868
Name string
6969
Description string
70+
Color string
7071
MaxResourceSize int64
7172
SupportedComponentSet []string
73+
Timezone string
7274
}
7375

7476
type CalendarCompRequest struct {

caldav/elements.go

+27-6
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,16 @@ var (
2121
calendarQueryName = xml.Name{namespace, "calendar-query"}
2222
calendarMultigetName = xml.Name{namespace, "calendar-multiget"}
2323

24-
calendarName = xml.Name{namespace, "calendar"}
25-
calendarDataName = xml.Name{namespace, "calendar-data"}
24+
calendarName = xml.Name{namespace, "calendar"}
25+
calendarDataName = xml.Name{namespace, "calendar-data"}
26+
calendarColorName = xml.Name{
27+
Space: "http://apple.com/ns/ical/",
28+
Local: "calendar-color",
29+
}
30+
calendarTimezoneName = xml.Name{
31+
Space: namespace,
32+
Local: "calendar-timezone",
33+
}
2634
)
2735

2836
// https://tools.ietf.org/html/rfc4791#section-6.2.1
@@ -41,6 +49,16 @@ type calendarDescription struct {
4149
Description string `xml:",chardata"`
4250
}
4351

52+
type calendarColor struct {
53+
XMLName xml.Name `xml:"http://apple.com/ns/ical/ calendar-color"`
54+
Color string `xml:",chardata"`
55+
}
56+
57+
type calendarTimezone struct {
58+
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:caldav calendar-timezone"`
59+
Timezone string `xml:",chardata"`
60+
}
61+
4462
// https://tools.ietf.org/html/rfc4791#section-5.2.4
4563
type supportedCalendarData struct {
4664
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:caldav supported-calendar-data"`
@@ -230,8 +248,11 @@ func (r *reportReq) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
230248
}
231249

232250
type mkcolReq struct {
233-
XMLName xml.Name `xml:"DAV: mkcol"`
234-
ResourceType internal.ResourceType `xml:"set>prop>resourcetype"`
235-
DisplayName string `xml:"set>prop>displayname"`
236-
// TODO this could theoretically contain all addressbook properties?
251+
XMLName xml.Name `xml:"DAV: mkcol"`
252+
ResourceType internal.ResourceType `xml:"set>prop>resourcetype"`
253+
DisplayName string `xml:"set>prop>displayname"`
254+
Description string `xml:"set>prop>calendar-description"`
255+
CalendarColor string `xml:"set>prop>calendar-color"`
256+
CalemdarTimeZone string `xml:"set>prop>calendar-timezone"`
257+
SupportedCalendarComponentSet supportedCalendarComponentSet `xml:"set>prop>supported-calendar-component-set"`
237258
}

caldav/server.go

+22-1
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,20 @@ func (b *backend) propFindCalendar(ctx context.Context, propfind *internal.PropF
568568
return &calendarDescription{Description: cal.Description}, nil
569569
}
570570
}
571+
if cal.Color != "" {
572+
props[calendarColorName] = func(*internal.RawXMLValue) (interface{}, error) {
573+
return &calendarColor{
574+
Color: cal.Color,
575+
}, nil
576+
}
577+
}
578+
if cal.Timezone != "" {
579+
props[calendarTimezoneName] = func(*internal.RawXMLValue) (interface{}, error) {
580+
return &calendarTimezone{
581+
Timezone: cal.Timezone,
582+
}, nil
583+
}
584+
}
571585
if cal.MaxResourceSize > 0 {
572586
props[maxResourceSizeName] = func(*internal.RawXMLValue) (interface{}, error) {
573587
return &maxResourceSize{Size: cal.MaxResourceSize}, nil
@@ -724,7 +738,14 @@ func (b *backend) Mkcol(r *http.Request) error {
724738
return internal.HTTPErrorf(http.StatusBadRequest, "carddav: unexpected resource type")
725739
}
726740
cal.Name = m.DisplayName
727-
// TODO ...
741+
cal.Description = m.Description
742+
cal.Color = strings.TrimSpace(m.CalendarColor)
743+
cal.Timezone = strings.TrimSpace(m.CalemdarTimeZone)
744+
745+
cal.SupportedComponentSet = make([]string, len(m.SupportedCalendarComponentSet.Comp))
746+
for i, v := range m.SupportedCalendarComponentSet.Comp {
747+
cal.SupportedComponentSet[i] = v.Name
748+
}
728749
}
729750

730751
return b.Backend.CreateCalendar(r.Context(), &cal)

0 commit comments

Comments
 (0)