caldav: parse iCal data

This commit is contained in:
Simon Ser 2020-02-05 18:05:48 +01:00
parent 4eb8396edb
commit baf63fb1b7
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
4 changed files with 23 additions and 3 deletions

View File

@ -5,6 +5,8 @@ package caldav
import (
"time"
"github.com/luxifer/ical"
)
type Calendar struct {
@ -39,5 +41,5 @@ type CalendarObject struct {
Path string
ModTime time.Time
ETag string
Data []byte
Data *ical.Calendar
}

View File

@ -1,12 +1,14 @@
package caldav
import (
"bytes"
"fmt"
"net/http"
"time"
"github.com/emersion/go-webdav"
"github.com/emersion/go-webdav/internal"
"github.com/luxifer/ical"
)
// Client provides access to a remote CardDAV server.
@ -178,11 +180,22 @@ func decodeCalendarObjectList(ms *internal.Multistatus) ([]CalendarObject, error
return nil, err
}
// Normalize line endings
// TODO: make the ical package less strict
b := calData.Data
b = bytes.ReplaceAll(b, []byte{'\r', '\n'}, []byte{'\n'})
b = bytes.ReplaceAll(b, []byte{'\n'}, []byte{'\r', '\n'})
data, err := ical.Parse(bytes.NewReader(b), nil)
if err != nil {
return nil, err
}
addrs = append(addrs, CalendarObject{
Path: path,
ModTime: time.Time(getLastMod.LastModified),
ETag: string(getETag.ETag),
Data: calData.Data,
Data: data,
})
}

5
go.mod
View File

@ -2,4 +2,7 @@ module github.com/emersion/go-webdav
go 1.13
require github.com/emersion/go-vcard v0.0.0-20191221110513-5f81fa0d3cc7
require (
github.com/emersion/go-vcard v0.0.0-20191221110513-5f81fa0d3cc7
github.com/luxifer/ical v0.0.0-20191105105432-84b768eb6395
)

2
go.sum
View File

@ -1,2 +1,4 @@
github.com/emersion/go-vcard v0.0.0-20191221110513-5f81fa0d3cc7 h1:SE+tcd+0kn0cT4MqTo66gmkjqWHF1Z+Yha5/rhLs/H8=
github.com/emersion/go-vcard v0.0.0-20191221110513-5f81fa0d3cc7/go.mod h1:HMJKR5wlh/ziNp+sHEDV2ltblO4JD2+IdDOWtGcQBTM=
github.com/luxifer/ical v0.0.0-20191105105432-84b768eb6395 h1:H7Rbug09BDCzr6k/PASDjSMjbJGzXswwqesaDiBNJz8=
github.com/luxifer/ical v0.0.0-20191105105432-84b768eb6395/go.mod h1:TGCe94U3u9fXQl4yHJ8W87z1czj057aVLxYnFYTDC08=