Skip to content
This repository was archived by the owner on Jul 6, 2024. It is now read-only.

Commit 2f2b8b1

Browse files
committed
feat: More LabelIDs and Message Unread status in event
1 parent e96329c commit 2f2b8b1

File tree

4 files changed

+111
-4
lines changed

4 files changed

+111
-4
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "proton-api-rs"
33
authors = ["Leander Beernaert <lbb-dev@pm.me>"]
4-
version = "0.7.2"
4+
version = "0.8.0"
55
edition = "2021"
66
license = "AGPL-3.0-only"
77
description = "Unofficial implemention of proton REST API in rust"

src/domain/event.rs

Lines changed: 102 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::domain::Boolean;
12
use serde::Deserialize;
23
use serde_repr::Deserialize_repr;
34
use std::fmt::{Display, Formatter};
@@ -41,15 +42,113 @@ pub enum MessageAction {
4142
#[derive(Debug, Deserialize, Eq, PartialEq, Hash, Clone)]
4243
pub 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)]
4754
pub 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+
4993
impl 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
}

src/domain/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ mod user;
66
pub use event::*;
77
pub use user::*;
88

9+
use serde_repr::Deserialize_repr;
910
use std::fmt::{Display, Formatter};
1011

1112
pub type SecretString = secrecy::SecretString;
@@ -28,3 +29,10 @@ impl Display for TwoFactorAuth {
2829
}
2930
}
3031
}
32+
33+
#[derive(Debug, Deserialize_repr, Eq, PartialEq, Copy, Clone)]
34+
#[repr(u8)]
35+
pub enum Boolean {
36+
False = 0,
37+
True = 1,
38+
}

src/requests/auth.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,6 @@ impl<'a> http::Request for AuthRefreshRequest<'a> {
245245
fn build_request(&self, factory: &dyn RequestFactory) -> RequestData {
246246
factory
247247
.new_request(http::Method::Post, "auth/v4/refresh")
248-
.header(http::X_PM_UID_HEADER, &self.uid.0)
249248
.json(AuthRefresh {
250249
uid: &self.uid.0,
251250
refresh_token: self.token,

0 commit comments

Comments
 (0)