forked from pauldemarco/caldav-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
email.go
86 lines (71 loc) · 1.73 KB
/
email.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package values
import (
"strings"
"github.com/LeonidKrn/caldav-go/icalendar/properties"
)
const (
preferredTypeValue = "pref"
)
type Email struct {
Mail string
Types []string
Label string
IsPreferred bool
}
func NewEmail(mail string, preferred bool, types ...string) *Email {
return &Email{
Mail: mail,
IsPreferred: preferred,
Types: types,
}
}
func (e *Email) ValidateICalValue() error {
return nil
}
func (e *Email) EncodeICalParams() (properties.Params, error) {
params := make(properties.Params, len(e.Types))
for i, str := range e.Types {
params[i] = properties.Param{
Name: properties.ParameterType,
Value: str,
}
}
if e.IsPreferred {
params = append(params, properties.Param{
Name: properties.ParameterType,
Value: preferredTypeValue,
})
}
return params, nil
}
func (e *Email) DecodeICalParams(params properties.Params) error {
for _, param := range params {
if strings.EqualFold(string(param.Name), properties.ParameterType) {
if param.Value == preferredTypeValue {
e.IsPreferred = true
} else {
e.Types = append(e.Types, param.Value)
}
} else if strings.EqualFold(string(param.Name), properties.ABLabel) {
e.Label = param.Value
}
}
return nil
}
func (e *Email) EncodeICalValue() (string, error) {
return e.Mail, nil
}
func (e *Email) DecodeICalValue(value string) error {
e.Mail = value
return nil
}
func (e *Email) EncodeICalName() (properties.PropertyName, error) {
return properties.EmailPropertyName, nil
}
func (e *Email) EncodeAdditionalICalProperties() ([]*properties.Property, error) {
var props []*properties.Property
if e.Label != "" {
props = append(props, properties.NewProperty("X-ABLabel", e.Label))
}
return props, nil
}