Skip to content

Commit

Permalink
[sdk] Mail MailSetKind more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
charlag committed Oct 17, 2024
1 parent 07c60a5 commit 4bb5739
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions tuta-sdk/rust/sdk/src/folder_system.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use num_enum::TryFromPrimitive;
use crate::entities::tutanota::MailFolder;
use num_enum::TryFromPrimitive;

pub struct FolderSystem {
// this structure should probably change rather soon
folders: Vec<MailFolder>
folders: Vec<MailFolder>,
}

#[derive(PartialEq, TryFromPrimitive)]
Expand All @@ -17,11 +17,12 @@ pub enum MailSetKind {
SPAM = 5,
DRAFT = 6,
ALL = 7,
UNKNOWN = 9999,
}

impl MailFolder {
fn mail_set_kind(&self) -> MailSetKind {
MailSetKind::try_from(self.folderType as u64).unwrap()
MailSetKind::try_from(self.folderType as u64).unwrap_or(MailSetKind::UNKNOWN)
}
}

Expand All @@ -31,6 +32,8 @@ impl FolderSystem {
}

pub fn system_folder_by_type(&self, mail_set_kind: MailSetKind) -> Option<&MailFolder> {
self.folders.iter().find(|f| f.mail_set_kind() == mail_set_kind)
self.folders
.iter()
.find(|f| f.mail_set_kind() == mail_set_kind)
}
}

0 comments on commit 4bb5739

Please sign in to comment.