forked from mhewedy/ews
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfind_item.go
115 lines (93 loc) · 3.11 KB
/
find_item.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package ews
import (
"encoding/xml"
"errors"
)
type FindItemRequest struct {
XMLName struct{} `xml:"m:FindItem"`
Traversal string `xml:"Traversal,attr"`
ItemShape ItemShape `xml:"m:ItemShape"`
IndexedPageItemView IndexedPageItemView `xml:"m:IndexedPageItemView"`
ParentFolderIds ParentFolderIds `xml:"m:ParentFolderIds"`
Restriction Restriction `xml:"m:Restriction"`
}
type ItemShape struct {
BaseShape BaseShape `xml:"t:BaseShape"`
AdditionalProperties AdditionalProperties `xml:"t:AdditionalProperties"`
}
type ParentFolderIds struct {
DistinguishedFolderId DistinguishedFolderId `xml:"t:DistinguishedFolderId"`
}
type Restriction struct {
IsEqualTo *IsEqualTo `xml:"t:IsEqualTo"`
Contains *Contains `xml:"t:Contains"`
}
type IsEqualTo struct {
BaseFiltering
FieldURIOrConstant FieldURIOrConstant `xml:"t:FieldURIOrConstant"`
}
type Contains struct {
BaseFiltering
Constant []Constant `xml:"t:Constant,omitempty"`
ContainmentMode string `xml:"ContainmentMode,attr"`
ContainmentComparison string `xml:"ContainmentComparison,attr"`
}
type BaseFiltering struct {
AdditionalProperties `xml:"t:FieldURI"`
}
type FieldURIOrConstant struct {
Constant []Constant `xml:"t:Constant,omitempty"`
}
type Constant struct {
Value string `xml:"Value,attr,omitempty"`
}
type findItemResponseEnvelop struct {
XMLName struct{} `xml:"Envelope"`
Body findItemResponseBody `xml:"Body"`
}
type findItemResponseBody struct {
FindItemResponse FindItemResponse `xml:"FindItemResponse"`
}
type FindItemResponse struct {
FindItemResponseMessages FindItemResponseMessages `xml:"ResponseMessages"`
}
type FindItemResponseMessages struct {
FindItemResponseMessage FindItemResponseMessage `xml:"FindItemResponseMessage"`
}
type FindItemResponseMessage struct {
Response
RootFolder *RootFolder `xml:"RootFolder"`
}
type RootFolder struct {
Items FindItems `xml:"Items"`
IndexedPagingOffset int `xml:"IndexedPagingOffset,attr"`
TotalItemsInView int `xml:"TotalItemsInView,attr"`
IncludesLastItemInRange bool `xml:"IncludesLastItemInRange,attr"`
}
type FindItems struct {
Message []FindItemMessage `xml:"Message"`
}
type FindItemMessage struct {
ItemId ItemId `xml:"ItemId"`
Subject string `xml:"Subject"`
}
// https://docs.microsoft.com/en-us/exchange/client-developer/web-service-reference/finditem-operation
func FindItem(c Client, r *FindItemRequest) (*FindItemResponse, error) {
xmlBytes, err := xml.MarshalIndent(r, "", " ")
if err != nil {
return nil, err
}
bb, err := c.SendAndReceive(xmlBytes)
if err != nil {
return nil, err
}
var soapResp findItemResponseEnvelop
err = xml.Unmarshal(bb, &soapResp)
if err != nil {
return nil, err
}
if soapResp.Body.FindItemResponse.FindItemResponseMessages.FindItemResponseMessage.ResponseClass != ResponseClassSuccess {
return nil, errors.New(soapResp.Body.FindItemResponse.FindItemResponseMessages.FindItemResponseMessage.MessageText)
}
return &soapResp.Body.FindItemResponse, nil
}