forked from iubiltekin/ews
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_attachment.go
75 lines (60 loc) · 2.1 KB
/
get_attachment.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
package ews
import (
"encoding/xml"
"errors"
)
type GetAttachmentRequest struct {
XMLName struct{} `xml:"m:GetAttachment"`
Items []AttachmentItemMessage `xml:"m:AttachmentIds"`
}
type AttachmentItemMessage struct {
AttachmentId AttachmentId `xml:"t:AttachmentId"`
}
type getAttachmentResponseEnvelop struct {
XMLName struct{} `xml:"Envelope"`
Body getAttachmentResponseBody `xml:"Body"`
}
type getAttachmentResponseBody struct {
GetAttachmentResponse GetAttachmentResponse `xml:"GetAttachmentResponse"`
}
type GetAttachmentResponse struct {
GetAttachmentResponseMessages GetAttachmentResponseMessages `xml:"ResponseMessages"`
}
type GetAttachmentResponseMessages struct {
GetAttachmentResponseMessage GetAttachmentResponseMessage `xml:"GetAttachmentResponseMessage"`
}
type GetAttachmentResponseMessage struct {
Response
Attachments GetAttachments `xml:"Attachments"`
}
type GetAttachments struct {
FileAttachment []GetFileAttachment `xml:"FileAttachment"`
}
type GetFileAttachment struct {
AttachmentId AttachmentId `xml:"AttachmentId"`
Name string `xml:"Name"`
ContentType string `xml:"ContentType"`
Content string `xml:"Content"`
IsInline bool `xml:"IsInline"`
IsContactPhoto bool `xml:"IsContactPhoto"`
}
// https://docs.microsoft.com/en-us/exchange/client-developer/web-service-reference/getattachment-operation
func GetAttachment(c Client, r *GetAttachmentRequest) (*GetAttachmentResponse, 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 getAttachmentResponseEnvelop
err = xml.Unmarshal(bb, &soapResp)
if err != nil {
return nil, err
}
if soapResp.Body.GetAttachmentResponse.GetAttachmentResponseMessages.GetAttachmentResponseMessage.ResponseClass != ResponseClassSuccess {
return nil, errors.New(soapResp.Body.GetAttachmentResponse.GetAttachmentResponseMessages.GetAttachmentResponseMessage.MessageText)
}
return &soapResp.Body.GetAttachmentResponse, nil
}