plugins/carddav: check supported vCard versions

This commit is contained in:
Simon Ser 2020-02-27 12:56:06 +01:00
parent 89149b38c8
commit ea0626d806
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
3 changed files with 12 additions and 6 deletions

2
go.mod
View file

@ -14,7 +14,7 @@ require (
github.com/emersion/go-sasl v0.0.0-20191210011802-430746ea8b9b
github.com/emersion/go-smtp v0.12.1
github.com/emersion/go-vcard v0.0.0-20191221110513-5f81fa0d3cc7
github.com/emersion/go-webdav v0.2.1-0.20200224201645-514296664cee
github.com/emersion/go-webdav v0.2.1-0.20200227113614-abadf534f49a
github.com/google/uuid v1.1.1
github.com/gorilla/css v1.0.0 // indirect
github.com/labstack/echo/v4 v4.1.15-0.20200203180927-504f39abaf32

4
go.sum
View file

@ -33,8 +33,8 @@ github.com/emersion/go-textwrapper v0.0.0-20160606182133-d0e65e56babe h1:40SWqY0
github.com/emersion/go-textwrapper v0.0.0-20160606182133-d0e65e56babe/go.mod h1:aqO8z8wPrjkscevZJFVE1wXJrLpC5LtJG7fqLOsPb2U=
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/emersion/go-webdav v0.2.1-0.20200224201645-514296664cee h1:yLluRVLxWJpWN00N+vMNkMUq3KCEU+jdBTXvOh7wXAQ=
github.com/emersion/go-webdav v0.2.1-0.20200224201645-514296664cee/go.mod h1:uSM1VveeKtogBVWaYccTksToczooJ0rrVGNsgnDsr4Q=
github.com/emersion/go-webdav v0.2.1-0.20200227113614-abadf534f49a h1:2AEvZeJdBiMRbcoI4hAtkoymn/7MypOQSKRZV7K0VgE=
github.com/emersion/go-webdav v0.2.1-0.20200227113614-abadf534f49a/go.mod h1:uSM1VveeKtogBVWaYccTksToczooJ0rrVGNsgnDsr4Q=
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY=

View file

@ -151,10 +151,16 @@ func registerRoutes(p *plugin) {
fn := ctx.FormValue("fn")
emails := strings.Split(ctx.FormValue("emails"), ",")
// Some CardDAV servers (e.g. Google) don't support vCard 4.0
// TODO: get supported formats from server, use highest version
if _, ok := card[vcard.FieldVersion]; !ok {
card.SetValue(vcard.FieldVersion, "3.0")
// Some CardDAV servers (e.g. Google) don't support vCard 4.0
var version = "4.0"
if !addressBook.SupportsAddressData(vcard.MIMEType, version) {
version = "3.0"
}
if !addressBook.SupportsAddressData(vcard.MIMEType, version) {
return fmt.Errorf("upstream CardDAV server doesn't support vCard %v", version)
}
card.SetValue(vcard.FieldVersion, version)
}
if field := card.Preferred(vcard.FieldFormattedName); field != nil {