-
Notifications
You must be signed in to change notification settings - Fork 0
/
zaccount.go
93 lines (76 loc) · 2.07 KB
/
zaccount.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
87
88
89
90
91
92
93
package zsoap
import (
"log"
"strings"
"time"
)
type ZAccount struct {
Client *Client
ID string
Name string
Used int
Limit int
ZimbraMailHost string
ZimbraMailTransport string
ZimbraCOSId string
ZimbraMailStatus string
ZimbraMailQuota string
ZimbraAccountStatus string
ZimbraFeatureMobileSyncEnabled bool
ZimbraFeatureMAPIConnectorEnabled bool
ZimbraLastLogonTimestamp string
ZimbraPrefMailForwardingAddress []string
ZimbraMailForwardingAddress []string
ZimbraPrefMailLocalDeliveryDisabled bool
}
func (a *ZAccount) LastLogon() (time.Time, error) {
return time.Parse("20060102150405Z", a.ZimbraLastLogonTimestamp)
}
func (a *ZAccount) Modify(attrs map[string]string) error {
req, soapAction := NewModifyAccountRequest(a.ID, attrs)
resp := ModifyAccountResponse{}
if err := a.Client.Call(soapAction, req, &resp); err != nil {
log.Println(err)
return err
}
return nil
}
func (a *ZAccount) DomainName() string {
return strings.Split(a.Name, "@")[1]
}
func NewAccount(resp GenericResponse, client *Client) *ZAccount {
account := &ZAccount{
Client: client,
ID: resp.ID,
Name: resp.Name,
}
setResponseAttrs(resp.Attrs, &account)
return account
}
func NewAccountQuota(resp QuotaResponse, client *Client) *ZAccount {
account := &ZAccount{
Client: client,
ID: resp.ID,
Name: resp.Name,
Used: resp.Used,
Limit: resp.Limit,
}
return account
}
func NewModifyAccountRequest(id string, attrs map[string]string) (*ModifyAccountRequest, string) {
a := make([]AttrResponse, 0)
for key, value := range attrs {
a = append(a, AttrResponse{
Key: key,
Value: value,
})
}
r := &ModifyAccountRequest{
Content: ModifyAccountRequestContent{
Urn: urnAdmin,
ID: id,
Attrs: a,
},
}
return r, "urn:zimbraAdmin/ModifyAccount"
}