-
Notifications
You must be signed in to change notification settings - Fork 27
/
attachments.go
51 lines (39 loc) · 1.09 KB
/
attachments.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
package api
import (
"fmt"
"strings"
"github.com/alcionai/clues"
"github.com/microsoftgraph/msgraph-sdk-go/models"
"github.com/alcionai/corso/src/internal/common/ptr"
)
func HasAttachments(body models.ItemBodyable) bool {
if body == nil {
return false
}
if ct, ok := ptr.ValOK(body.GetContentType()); !ok || ct == models.TEXT_BODYTYPE {
return false
}
if body, ok := ptr.ValOK(body.GetContent()); !ok || len(body) == 0 {
return false
}
return strings.Contains(ptr.Val(body.GetContent()), "src=\"cid:")
}
func makeSessionAttachment(name string, size int64) *models.AttachmentItem {
attItem := models.NewAttachmentItem()
attType := models.FILE_ATTACHMENTTYPE
attItem.SetAttachmentType(&attType)
attItem.SetName(&name)
attItem.SetSize(&size)
return attItem
}
func GetAttachmentContent(attachment models.Attachmentable) ([]byte, error) {
ibs, err := attachment.GetBackingStore().Get("contentBytes")
if err != nil {
return nil, err
}
bs, ok := ibs.([]byte)
if !ok {
return nil, clues.New(fmt.Sprintf("unexpected type for attachment content: %T", ibs))
}
return bs, nil
}