diff options
author | Quentin <quentin@dufour.io> | 2024-01-06 10:38:37 +0000 |
---|---|---|
committer | Quentin <quentin@dufour.io> | 2024-01-06 10:38:37 +0000 |
commit | 44ca458c5cf666246e472dea9be70b745a130e8c (patch) | |
tree | b78cca747e5c2bc004cb93b93536623f7abb6ef5 /src/imap/flags.rs | |
parent | bcf6de83419b405fea95b740869f98d43586ea7c (diff) | |
parent | 53dbf82cbce3cb17cbcffd09558677faf8702f54 (diff) | |
download | aerogramme-44ca458c5cf666246e472dea9be70b745a130e8c.tar.gz aerogramme-44ca458c5cf666246e472dea9be70b745a130e8c.zip |
Merge pull request 'Aerogramme refactoring' (#57) from feat/more-imap-qol into main
Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/aerogramme/pulls/57
Diffstat (limited to 'src/imap/flags.rs')
-rw-r--r-- | src/imap/flags.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/imap/flags.rs b/src/imap/flags.rs new file mode 100644 index 0000000..0f6ec64 --- /dev/null +++ b/src/imap/flags.rs @@ -0,0 +1,30 @@ +use imap_codec::imap_types::core::Atom; +use imap_codec::imap_types::flag::{Flag, FlagFetch}; + +pub fn from_str(f: &str) -> Option<FlagFetch<'static>> { + match f.chars().next() { + Some('\\') => match f { + "\\Seen" => Some(FlagFetch::Flag(Flag::Seen)), + "\\Answered" => Some(FlagFetch::Flag(Flag::Answered)), + "\\Flagged" => Some(FlagFetch::Flag(Flag::Flagged)), + "\\Deleted" => Some(FlagFetch::Flag(Flag::Deleted)), + "\\Draft" => Some(FlagFetch::Flag(Flag::Draft)), + "\\Recent" => Some(FlagFetch::Recent), + _ => match Atom::try_from(f.strip_prefix('\\').unwrap().to_string()) { + Err(_) => { + tracing::error!(flag=%f, "Unable to encode flag as IMAP atom"); + None + } + Ok(a) => Some(FlagFetch::Flag(Flag::system(a))), + }, + }, + Some(_) => match Atom::try_from(f.to_string()) { + Err(_) => { + tracing::error!(flag=%f, "Unable to encode flag as IMAP atom"); + None + } + Ok(a) => Some(FlagFetch::Flag(Flag::keyword(a))), + }, + None => None, + } +} |