melib: add SpecialUseMailbox::detect_usage method

This commit is contained in:
Manos Pitsidianakis 2019-12-07 14:04:25 +02:00
parent 30e9114d9c
commit aa9a6a3128
No known key found for this signature in database
GPG Key ID: 73627C2F690DF710
3 changed files with 25 additions and 22 deletions

View File

@ -370,6 +370,28 @@ impl Default for SpecialUsageMailbox {
}
}
impl SpecialUsageMailbox {
pub fn detect_usage(name: &str) -> Option<SpecialUsageMailbox> {
if name.eq_ignore_ascii_case("inbox") {
Some(SpecialUsageMailbox::Inbox)
} else if name.eq_ignore_ascii_case("archive") {
Some(SpecialUsageMailbox::Archive)
} else if name.eq_ignore_ascii_case("drafts") {
Some(SpecialUsageMailbox::Drafts)
} else if name.eq_ignore_ascii_case("junk") {
Some(SpecialUsageMailbox::Junk)
} else if name.eq_ignore_ascii_case("spam") {
Some(SpecialUsageMailbox::Junk)
} else if name.eq_ignore_ascii_case("sent") {
Some(SpecialUsageMailbox::Sent)
} else if name.eq_ignore_ascii_case("trash") {
Some(SpecialUsageMailbox::Trash)
} else {
Some(SpecialUsageMailbox::Normal)
}
}
}
pub trait BackendFolder: Debug {
fn hash(&self) -> FolderHash;
fn name(&self) -> &str;

View File

@ -182,7 +182,8 @@ impl From<FileAccount> for AccountConf {
.split(if s.contains('/') { '/' } else { '.' })
.last()
.unwrap_or("");
folder_confs.get_mut(s).unwrap().folder_conf.usage = usage(name);
folder_confs.get_mut(s).unwrap().folder_conf.usage =
SpecialUsageMailbox::detect_usage(name);
}
if folder_confs[s].folder_conf().ignore.is_unset() {
@ -564,26 +565,6 @@ impl Serialize for CacheType {
}
}
pub fn usage(name: &str) -> Option<SpecialUsageMailbox> {
if name.eq_ignore_ascii_case("inbox") {
Some(SpecialUsageMailbox::Inbox)
} else if name.eq_ignore_ascii_case("archive") {
Some(SpecialUsageMailbox::Archive)
} else if name.eq_ignore_ascii_case("drafts") {
Some(SpecialUsageMailbox::Drafts)
} else if name.eq_ignore_ascii_case("junk") {
Some(SpecialUsageMailbox::Junk)
} else if name.eq_ignore_ascii_case("spam") {
Some(SpecialUsageMailbox::Junk)
} else if name.eq_ignore_ascii_case("sent") {
Some(SpecialUsageMailbox::Sent)
} else if name.eq_ignore_ascii_case("trash") {
Some(SpecialUsageMailbox::Trash)
} else {
Some(SpecialUsageMailbox::Normal)
}
}
pub fn create_config_file(p: &Path) -> Result<()> {
let mut file = OpenOptions::new()
.write(true)

View File

@ -353,7 +353,7 @@ impl Account {
} else {
let mut new = FileFolderConf::default();
new.folder_conf.subscribe = super::ToggleFlag::InternalVal(true);
new.folder_conf.usage = super::usage(f.name());
new.folder_conf.usage = SpecialUsageMailbox::detect_usage(f.name());
folder_confs.insert(f.hash(), new);
}
folder_names.insert(f.hash(), f.path().to_string());