diff options
author | Quentin Dufour <quentin@deuxfleurs.fr> | 2024-01-04 20:54:21 +0100 |
---|---|---|
committer | Quentin Dufour <quentin@deuxfleurs.fr> | 2024-01-04 20:54:21 +0100 |
commit | 2a9ae1297bf5c4a4b9552eeabb00246d76004f63 (patch) | |
tree | d3f3a14f2a05ef34ff9461ef82b072b64e06a209 /src/imap/flags.rs | |
parent | b22df840dbda699957ae48eca019e3ecfa493bd9 (diff) | |
download | aerogramme-2a9ae1297bf5c4a4b9552eeabb00246d76004f63.tar.gz aerogramme-2a9ae1297bf5c4a4b9552eeabb00246d76004f63.zip |
bcp commit
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, + } +} |