2020-01-21 21:01:18 +01:00
|
|
|
// Package carddav provides a client and server CardDAV implementation.
|
|
|
|
//
|
|
|
|
// CardDAV is defined in RFC 6352.
|
2020-01-14 22:19:54 +01:00
|
|
|
package carddav
|
|
|
|
|
2020-01-14 23:13:23 +01:00
|
|
|
import (
|
2020-01-22 15:35:36 +01:00
|
|
|
"time"
|
|
|
|
|
2020-01-14 23:44:21 +01:00
|
|
|
"github.com/emersion/go-vcard"
|
2022-03-21 09:16:50 +01:00
|
|
|
"github.com/emersion/go-webdav"
|
|
|
|
"github.com/emersion/go-webdav/internal"
|
2020-01-14 23:13:23 +01:00
|
|
|
)
|
|
|
|
|
2022-12-01 14:43:04 +01:00
|
|
|
var CapabilityAddressBook = webdav.Capability("addressbook")
|
|
|
|
|
2022-03-21 09:16:50 +01:00
|
|
|
func NewAddressBookHomeSet(path string) webdav.BackendSuppliedHomeSet {
|
|
|
|
return &addressbookHomeSet{Href: internal.Href{Path: path}}
|
|
|
|
}
|
|
|
|
|
2020-02-27 12:36:14 +01:00
|
|
|
type AddressDataType struct {
|
|
|
|
ContentType string
|
|
|
|
Version string
|
|
|
|
}
|
|
|
|
|
2020-01-14 23:13:23 +01:00
|
|
|
type AddressBook struct {
|
2020-02-27 12:36:14 +01:00
|
|
|
Path string
|
|
|
|
Name string
|
|
|
|
Description string
|
|
|
|
MaxResourceSize int64
|
|
|
|
SupportedAddressData []AddressDataType
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ab *AddressBook) SupportsAddressData(contentType, version string) bool {
|
|
|
|
if len(ab.SupportedAddressData) == 0 {
|
|
|
|
return contentType == "text/vcard" && version == "3.0"
|
|
|
|
}
|
|
|
|
for _, t := range ab.SupportedAddressData {
|
|
|
|
if t.ContentType == contentType && t.Version == version {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
2020-01-14 23:13:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type AddressBookQuery struct {
|
2020-01-27 10:30:19 +01:00
|
|
|
DataRequest AddressDataRequest
|
2020-01-23 10:35:06 +01:00
|
|
|
|
2020-01-24 11:25:58 +01:00
|
|
|
PropFilters []PropFilter
|
|
|
|
FilterTest FilterTest // defaults to FilterAnyOf
|
|
|
|
|
2020-01-23 10:35:06 +01:00
|
|
|
Limit int // <= 0 means unlimited
|
2020-01-14 23:44:21 +01:00
|
|
|
}
|
|
|
|
|
2020-01-27 10:30:19 +01:00
|
|
|
type AddressDataRequest struct {
|
|
|
|
Props []string
|
|
|
|
AllProp bool
|
|
|
|
}
|
|
|
|
|
2020-01-24 11:25:58 +01:00
|
|
|
type PropFilter struct {
|
|
|
|
Name string
|
2020-01-24 12:24:35 +01:00
|
|
|
Test FilterTest // defaults to FilterAnyOf
|
2020-01-24 11:25:58 +01:00
|
|
|
|
|
|
|
// if IsNotDefined is set, TextMatches and Params need to be unset
|
|
|
|
IsNotDefined bool
|
|
|
|
TextMatches []TextMatch
|
|
|
|
Params []ParamFilter
|
|
|
|
}
|
|
|
|
|
|
|
|
type ParamFilter struct {
|
|
|
|
Name string
|
|
|
|
|
|
|
|
// if IsNotDefined is set, TextMatch needs to be unset
|
|
|
|
IsNotDefined bool
|
|
|
|
TextMatch *TextMatch
|
|
|
|
}
|
|
|
|
|
|
|
|
type TextMatch struct {
|
|
|
|
Text string
|
|
|
|
NegateCondition bool
|
|
|
|
MatchType MatchType // defaults to MatchContains
|
|
|
|
}
|
|
|
|
|
|
|
|
type FilterTest string
|
|
|
|
|
|
|
|
const (
|
|
|
|
FilterAnyOf FilterTest = "anyof"
|
|
|
|
FilterAllOf FilterTest = "allof"
|
|
|
|
)
|
|
|
|
|
|
|
|
type MatchType string
|
|
|
|
|
|
|
|
const (
|
|
|
|
MatchEquals MatchType = "equals"
|
|
|
|
MatchContains MatchType = "contains"
|
|
|
|
MatchStartsWith MatchType = "starts-with"
|
|
|
|
MatchEndsWith MatchType = "ends-with"
|
|
|
|
)
|
|
|
|
|
2020-01-15 12:09:42 +01:00
|
|
|
type AddressBookMultiGet struct {
|
2020-01-30 13:18:05 +01:00
|
|
|
Paths []string
|
2020-01-27 10:30:19 +01:00
|
|
|
DataRequest AddressDataRequest
|
2020-01-15 12:09:42 +01:00
|
|
|
}
|
|
|
|
|
2020-01-17 16:20:05 +01:00
|
|
|
type AddressObject struct {
|
2022-05-17 15:12:12 +02:00
|
|
|
Path string
|
|
|
|
ModTime time.Time
|
|
|
|
ContentLength int64
|
|
|
|
ETag string
|
|
|
|
Card vcard.Card
|
2020-01-14 23:13:23 +01:00
|
|
|
}
|
2020-03-29 15:08:48 +03:00
|
|
|
|
2022-08-31 13:42:38 +02:00
|
|
|
// SyncQuery is the query struct represents a sync-collection request
|
2020-03-29 15:08:48 +03:00
|
|
|
type SyncQuery struct {
|
|
|
|
DataRequest AddressDataRequest
|
|
|
|
SyncToken string
|
|
|
|
Limit int // <= 0 means unlimited
|
|
|
|
}
|
|
|
|
|
2022-08-31 13:42:38 +02:00
|
|
|
// SyncResponse contains the returned sync-token for next time
|
2020-03-29 15:08:48 +03:00
|
|
|
type SyncResponse struct {
|
|
|
|
SyncToken string
|
|
|
|
Updated []AddressObject
|
|
|
|
Deleted []string
|
|
|
|
}
|