forked from mhewedy/ews
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdelete_item.go
62 lines (49 loc) · 1.59 KB
/
delete_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
package ews
import (
"encoding/xml"
"errors"
)
type DeleteItemRequest struct {
XMLName struct{} `xml:"m:DeleteItem"`
DeleteType string `xml:"DeleteType,attr"`
Items []DeleteItemMessage `xml:"m:ItemIds"`
}
type DeleteItemMessage struct {
ItemId ItemId `xml:"t:ItemId"`
}
type deleteItemResponseEnvelop struct {
XMLName struct{} `xml:"Envelope"`
Body deleteItemResponseBody `xml:"Body"`
}
type deleteItemResponseBody struct {
DeleteItemResponse DeleteItemResponse `xml:"DeleteItemResponse"`
}
type DeleteItemResponse struct {
DeleteItemResponseMessages DeleteItemResponseMessages `xml:"ResponseMessages"`
}
type DeleteItemResponseMessages struct {
DeleteItemResponseMessage DeleteItemResponseMessage `xml:"DeleteItemResponseMessage"`
}
type DeleteItemResponseMessage struct {
Response
}
// https://docs.microsoft.com/en-us/exchange/client-developer/web-service-reference/deleteitem-operation
func DeleteItem(c Client, r *DeleteItemRequest) (*DeleteItemResponse, 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 deleteItemResponseEnvelop
err = xml.Unmarshal(bb, &soapResp)
if err != nil {
return nil, err
}
if soapResp.Body.DeleteItemResponse.DeleteItemResponseMessages.DeleteItemResponseMessage.ResponseClass != ResponseClassSuccess {
return nil, errors.New(soapResp.Body.DeleteItemResponse.DeleteItemResponseMessages.DeleteItemResponseMessage.MessageText)
}
return &soapResp.Body.DeleteItemResponse, nil
}