1+ use crate :: domain:: Boolean ;
12use serde:: Deserialize ;
23use serde_repr:: Deserialize_repr ;
34use std:: fmt:: { Display , Formatter } ;
@@ -41,15 +42,113 @@ pub enum MessageAction {
4142#[ derive( Debug , Deserialize , Eq , PartialEq , Hash , Clone ) ]
4243pub struct MessageId ( String ) ;
4344
45+ impl Display for MessageId {
46+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
47+ self . 0 . fmt ( f)
48+ }
49+ }
50+
4451/// Labels API ID. Note that label IDs are used interchangeably between what we would consider
4552/// mail labels and mailboxes.
4653#[ derive( Debug , Deserialize , Eq , PartialEq , Hash , Clone ) ]
4754pub struct LabelID ( String ) ;
4855
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+
4993impl LabelID {
50- /// Default LabelID for the `INBOX` mailbox.
5194 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)
53152 }
54153}
55154
@@ -74,4 +173,5 @@ pub struct Message {
74173 pub subject : String ,
75174 pub sender_address : String ,
76175 pub sender_name : Option < String > ,
176+ pub unread : Boolean ,
77177}
0 commit comments