-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenvelope.go
51 lines (43 loc) · 808 Bytes
/
envelope.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 models
import (
"strconv"
"strings"
)
type Envelope struct {
Message Message
Attachments []Attachment
}
type Message struct {
ID int64 `sql:"primary_key"`
CreatedAt Time
Date Time
Subject string
From string
To MessageTo
Text string
HTML string
}
type MessageTo []string
func (ss MessageTo) EQ(strs ...string) bool {
for _, str := range strs {
for _, s := range ss {
if s == str {
return true
}
}
}
return false
}
type Attachment struct {
ID int64 `sql:"primary_key"`
MessageID int64
Name string
Mime string
Extension string
}
func (a Attachment) IsImage() bool {
return strings.HasPrefix(a.Mime, "image/")
}
func (a Attachment) FileName() string {
return strconv.FormatInt(a.ID, 10) + a.Extension
}