Debian Codegraph @

label_types.go

raw
1 package proton
2
3 import (
4 "encoding/json"
5 "strings"
6 )
7
8 const (
9 InboxLabel = "0"
10 AllDraftsLabel = "1"
11 AllSentLabel = "2"
12 TrashLabel = "3"
13 SpamLabel = "4"
14 AllMailLabel = "5"
15 ArchiveLabel = "6"
16 SentLabel = "7"
17 DraftsLabel = "8"
18 OutboxLabel = "9"
19 StarredLabel = "10"
20 AllScheduledLabel = "12"
21 )
22
23 type Label struct {
24 ID string
25 ParentID string
26
27 Name string
28 Path []string
29 Color string
30 Type LabelType
31 }
32
33 func (label *Label) UnmarshalJSON(data []byte) error {
34 type Alias Label
35
36 aux := &struct {
37 Path string
38
39 *Alias
40 }{
41 Alias: (*Alias)(label),
42 }
43
44 if err := json.Unmarshal(data, &aux); err != nil {
45 return err
46 }
47
48 label.Path = strings.Split(aux.Path, "/")
49
50 return nil
51 }
52
53 func (label Label) MarshalJSON() ([]byte, error) {
54 type Alias Label
55
56 aux := &struct {
57 Path string
58
59 *Alias
60 }{
61 Path: strings.Join(label.Path, "/"),
62 Alias: (*Alias)(&label),
63 }
64
65 return json.Marshal(aux)
66 }
67
68 type CreateLabelReq struct {
69 Name string
70 Color string
71 Type LabelType
72
73 ParentID string `json:",omitempty"`
74 }
75
76 type UpdateLabelReq struct {
77 Name string
78 Color string
79
80 ParentID string `json:",omitempty"`
81 }
82
83 type LabelType int
84
85 const (
86 LabelTypeLabel LabelType = iota + 1
87 LabelTypeContactGroup
88 LabelTypeFolder
89 LabelTypeSystem
90 )