forked from mhewedy/ews
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathget_item.go
120 lines (99 loc) · 3.47 KB
/
get_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
116
117
118
119
120
package ews
import (
"encoding/xml"
"errors"
)
type GetItemMessage struct {
ItemId ItemId `xml:"t:ItemId"`
}
type GetItemRequest struct {
XMLName struct{} `xml:"m:GetItem"`
ItemShape GetItemShape `xml:"m:ItemShape"`
Items []GetItemMessage `xml:"m:ItemIds"`
}
type GetItemShape struct {
BaseShape BaseShape `xml:"t:BaseShape"`
IncludeMimeContent BooleanType `xml:"t:IncludeMimeContent"`
}
type getItemResponseEnvelop struct {
XMLName struct{} `xml:"Envelope"`
Body getItemResponseBody `xml:"Body"`
}
type getItemResponseBody struct {
GetItemResponse GetItemResponse `xml:"GetItemResponse"`
}
type GetItemResponse struct {
GetItemResponseMessages GetItemResponseMessages `xml:"ResponseMessages"`
}
type GetItemResponseMessages struct {
GetItemResponseMessage GetItemResponseMessage `xml:"GetItemResponseMessage"`
}
type GetItemResponseMessage struct {
Response
Items GetItems `xml:"Items"`
}
type GetItems struct {
Message []ItemMessage `xml:"Message"`
}
type ItemMessage struct {
ItemId ItemId `xml:"ItemId"`
Subject string `xml:"Subject"`
MimeContent MimeContent `xml:"MimeContent"`
Sensitivity string `xml:"Sensitivity"`
Body EmailBody `xml:"Body"`
Attachments Attachments `xml:"Attachments"`
Size uint64 `xml:"Size"`
DateTimeSent Time `xml:"DateTimeSent"`
DateTimeCreated Time `xml:"DateTimeCreated"`
HasAttachments BooleanType `xml:"HasAttachments"`
IsAssociated BooleanType `xml:"IsAssociated"`
ToRecipients From `xml:"ToRecipients"`
IsReadReceiptRequested BooleanType `xml:"IsReadReceiptRequested"`
IsDeliveryReceiptRequested BooleanType `xml:"IsDeliveryReceiptRequested"`
From From `xml:"From"`
IsRead BooleanType `xml:"IsRead"`
}
type GetItemEmailAddress struct {
Name string `xml:"Name"`
EmailAddress string `xml:"EmailAddress"`
RoutingType string `xml:"RoutingType"`
MailboxType string `xml:"MailboxType"`
}
type From struct {
Mailbox []GetItemEmailAddress `xml:"Mailbox"`
}
type Attachments struct {
FileAttachment []FileAttachment `xml:"FileAttachment"`
}
type FileAttachment struct {
AttachmentId AttachmentId `xml:"AttachmentId"`
Name string `xml:"Name"`
ContentType string `xml:"ContentType"`
Size uint64 `xml:"Size"`
LastModifiedTime Time `xml:"LastModifiedTime"`
IsInline bool `xml:"IsInline"`
IsContactPhoto bool `xml:"IsContactPhoto"`
}
type AttachmentId struct {
Id string `xml:"Id,attr"`
}
// https://docs.microsoft.com/en-us/exchange/client-developer/web-service-reference/getitem-operation-email-message
func GetItem(c Client, r *GetItemRequest) (*GetItemResponse, 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 getItemResponseEnvelop
err = xml.Unmarshal(bb, &soapResp)
if err != nil {
return nil, err
}
if soapResp.Body.GetItemResponse.GetItemResponseMessages.GetItemResponseMessage.ResponseClass != ResponseClassSuccess {
return nil, errors.New(soapResp.Body.GetItemResponse.GetItemResponseMessages.GetItemResponseMessage.MessageText)
}
return &soapResp.Body.GetItemResponse, nil
}