1
+ use crate :: domain:: Boolean ;
1
2
use serde:: Deserialize ;
2
3
use serde_repr:: Deserialize_repr ;
3
4
use std:: fmt:: { Display , Formatter } ;
@@ -41,15 +42,113 @@ pub enum MessageAction {
41
42
#[ derive( Debug , Deserialize , Eq , PartialEq , Hash , Clone ) ]
42
43
pub struct MessageId ( String ) ;
43
44
45
+ impl Display for MessageId {
46
+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
47
+ self . 0 . fmt ( f)
48
+ }
49
+ }
50
+
44
51
/// Labels API ID. Note that label IDs are used interchangeably between what we would consider
45
52
/// mail labels and mailboxes.
46
53
#[ derive( Debug , Deserialize , Eq , PartialEq , Hash , Clone ) ]
47
54
pub struct LabelID ( String ) ;
48
55
56
+ /// SysLabelID represents system label identifiers that are constant for every account.
57
+ #[ derive( Debug , Eq , PartialEq , Hash , Copy , Clone ) ]
58
+ pub struct SysLabelID ( & ' static str ) ;
59
+
60
+ impl PartialEq < LabelID > for SysLabelID {
61
+ fn eq ( & self , other : & LabelID ) -> bool {
62
+ self . 0 == other. 0
63
+ }
64
+ }
65
+
66
+ impl PartialEq < SysLabelID > for LabelID {
67
+ fn eq ( & self , other : & SysLabelID ) -> bool {
68
+ self . 0 == other. 0
69
+ }
70
+ }
71
+
72
+ impl From < SysLabelID > for LabelID {
73
+ fn from ( value : SysLabelID ) -> Self {
74
+ Self ( value. 0 . into ( ) )
75
+ }
76
+ }
77
+
78
+ impl SysLabelID {
79
+ pub const INBOX : SysLabelID = SysLabelID ( "0" ) ;
80
+ pub const ALL_DRAFTS : SysLabelID = SysLabelID ( "1" ) ;
81
+ pub const ALL_SENT : SysLabelID = SysLabelID ( "1" ) ;
82
+ pub const TRASH : SysLabelID = SysLabelID ( "3" ) ;
83
+ pub const SPAM : SysLabelID = SysLabelID ( "4" ) ;
84
+ pub const ALL_MAIL : SysLabelID = SysLabelID ( "5" ) ;
85
+ pub const ARCHIVE : SysLabelID = SysLabelID ( "5" ) ;
86
+ pub const SENT : SysLabelID = SysLabelID ( "7" ) ;
87
+ pub const DRAFTS : SysLabelID = SysLabelID ( "8" ) ;
88
+ pub const OUTBOX : SysLabelID = SysLabelID ( "9" ) ;
89
+ pub const STARRED : SysLabelID = SysLabelID ( "10" ) ;
90
+ pub const ALL_SCHEDULED : SysLabelID = SysLabelID ( "12" ) ;
91
+ }
92
+
49
93
impl LabelID {
50
- /// Default LabelID for the `INBOX` mailbox.
51
94
pub fn inbox ( ) -> Self {
52
- Self ( "0" . to_string ( ) )
95
+ SysLabelID :: INBOX . into ( )
96
+ }
97
+
98
+ pub fn all_drafts ( ) -> Self {
99
+ SysLabelID :: ALL_DRAFTS . into ( )
100
+ }
101
+
102
+ pub fn all_sent ( ) -> Self {
103
+ SysLabelID :: ALL_SENT . into ( )
104
+ }
105
+
106
+ pub fn trash ( ) -> Self {
107
+ SysLabelID :: TRASH . into ( )
108
+ }
109
+
110
+ pub fn spam ( ) -> Self {
111
+ SysLabelID :: SPAM . into ( )
112
+ }
113
+
114
+ pub fn all_mail ( ) -> Self {
115
+ SysLabelID :: ALL_MAIL . into ( )
116
+ }
117
+
118
+ pub fn archive ( ) -> Self {
119
+ SysLabelID :: ARCHIVE . into ( )
120
+ }
121
+
122
+ pub fn sent ( ) -> Self {
123
+ SysLabelID :: SENT . into ( )
124
+ }
125
+
126
+ pub fn drafts ( ) -> Self {
127
+ SysLabelID :: DRAFTS . into ( )
128
+ }
129
+
130
+ pub fn outbox ( ) -> Self {
131
+ SysLabelID :: OUTBOX . into ( )
132
+ }
133
+
134
+ pub fn starred ( ) -> Self {
135
+ SysLabelID :: STARRED . into ( )
136
+ }
137
+
138
+ pub fn all_scheduled ( ) -> Self {
139
+ SysLabelID :: ALL_SCHEDULED . into ( )
140
+ }
141
+ }
142
+
143
+ impl Display for LabelID {
144
+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
145
+ self . 0 . fmt ( f)
146
+ }
147
+ }
148
+
149
+ impl Display for SysLabelID {
150
+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
151
+ self . 0 . fmt ( f)
53
152
}
54
153
}
55
154
@@ -74,4 +173,5 @@ pub struct Message {
74
173
pub subject : String ,
75
174
pub sender_address : String ,
76
175
pub sender_name : Option < String > ,
176
+ pub unread : Boolean ,
77
177
}
0 commit comments