-
Notifications
You must be signed in to change notification settings - Fork 0
/
command.go
151 lines (113 loc) · 2.82 KB
/
command.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package bpop
import (
"crypto/sha256"
"encoding/json"
"github.com/realbmail/go-bmail-account"
"github.com/realbmail/go-bmail-protocol/bmp"
"github.com/realbmail/go-bmail-protocol/translayer"
"github.com/google/uuid"
)
const (
DefaultMailCount int = 20
DirectionToLeft bool = true
DirectionToRight bool = false
)
type CmdDownload struct {
MailAddr string `json:"mail_addr"`
Owner bmail.Address `json:"owner"`
MailCnt int `json:"mail_cnt"`
Direction bool `json:"direction"` //false -> after TimePivot, true -> before TimePivot
TimePivot int64 `json:"time_pivot"`
}
func (cd *CmdDownload) Hash() []byte {
data, _ := json.Marshal(*cd)
hash := sha256.Sum256(data)
return hash[:]
}
func (cd *CmdDownload) MsgType() uint16 {
return translayer.RETR
}
type CmdState struct {
MailAddr string `json:"mail_addr"`
Owner bmail.Address `json:"owner"`
BeforTime int64 `json:"before_time"`
}
func (cs *CmdState) Hash() []byte {
data, _ := json.Marshal(*cs)
hash := sha256.Sum256(data)
return hash[:]
}
func (cs *CmdState) MsgType() uint16 {
return translayer.STAT
}
type CmdDelete struct {
MailAddr string `json:"mail_addr"`
Owner bmail.Address `json:"owner"`
Eids []uuid.UUID `json:"eid"`
}
func (cd *CmdDelete) Hash() []byte {
data, _ := json.Marshal(*cd)
hash := sha256.Sum256(data)
return hash[:]
}
func (cs *CmdDelete) MsgType() uint16 {
return translayer.DELETE
}
type CmdDownloadAck struct {
CryptEps []*bmp.BMailEnvelope
}
func (cda *CmdDownloadAck) MsgType() uint16 {
return translayer.RETR_RESP
}
func (cda *CmdDownloadAck) GetBytes() ([]byte, error) {
return json.Marshal(*cda)
}
func (cda *CmdDownloadAck) Hash() []byte {
data, _ := json.Marshal(*cda)
hash := sha256.Sum256(data)
return hash[:]
}
type State struct {
TotalSpace int64 `json:"total_space"`
UsedSize int64 `json:"used_size"`
TotalCount int `json:"total_count"`
}
type CmdStateAck struct {
SendMail State `json:"send_mail_space"`
ReceiptMail State `json:"receipt_mail"`
}
func (csa *CmdStateAck) MsgType() uint16 {
return translayer.STAT_RESP
}
func (csa *CmdStateAck) GetBytes() ([]byte, error) {
return json.Marshal(*csa)
}
func (csa *CmdStateAck) Hash() []byte {
data, _ := json.Marshal(*csa)
hash := sha256.Sum256(data)
return hash[:]
}
//Result
const (
MailDeleteSuccess int = iota
MailNotFound
MailDeleteFailed
)
type CmdResult struct {
Eid uuid.UUID `json:"eid"`
Result int `json:"result"`
}
type CmdDeleteAck struct {
Result []CmdResult `json:"result"`
}
func (cda *CmdDeleteAck) MsgType() uint16 {
return translayer.DELETE_RESP
}
func (cda *CmdDeleteAck) GetBytes() ([]byte, error) {
return json.Marshal(*cda)
}
func (cda *CmdDeleteAck) Hash() []byte {
data, _ := json.Marshal(*cda)
hash := sha256.Sum256(data)
return hash[:]
}