panorama/imap/src/command.rs

124 lines
3 KiB
Rust
Raw Normal View History

2021-02-20 05:03:33 +00:00
use std::fmt;
/// Commands, without the tag part.
#[derive(Clone)]
2021-02-20 05:03:33 +00:00
pub enum Command {
Capability,
2021-02-21 13:42:40 +00:00
Starttls,
2021-02-24 12:43:50 +00:00
Login {
username: String,
password: String,
},
Select {
mailbox: String,
},
List {
reference: String,
mailbox: String,
},
Search {
criteria: SearchCriteria,
},
Fetch {
// TODO: do sequence-set
uids: Vec<u32>,
items: FetchItems,
},
UidSearch {
criteria: SearchCriteria,
},
UidFetch {
// TODO: do sequence-set
uids: Vec<u32>,
items: FetchItems,
},
2021-02-24 12:43:50 +00:00
#[cfg(feature = "rfc2177-idle")]
2021-03-09 09:27:25 +00:00
#[cfg_attr(docsrs, doc(cfg(feature = "rfc2177-idle")))]
2021-02-24 12:43:50 +00:00
Idle,
#[cfg(feature = "rfc2177-idle")]
#[cfg_attr(docsrs, doc(cfg(feature = "rfc2177-idle")))]
Done,
2021-02-20 05:03:33 +00:00
}
impl fmt::Debug for Command {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use Command::*;
match self {
Login { .. } => write!(f, "LOGIN"),
_ => <Self as fmt::Display>::fmt(self, f),
}
}
}
2021-02-20 05:03:33 +00:00
impl fmt::Display for Command {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2021-02-23 04:01:39 +00:00
use Command::*;
2021-02-20 05:03:33 +00:00
match self {
2021-02-23 04:01:39 +00:00
Capability => write!(f, "CAPABILITY"),
Starttls => write!(f, "STARTTLS"),
2021-03-01 08:03:21 +00:00
Login { username, password } => write!(f, "LOGIN {:?} {:?}", username, password),
2021-02-23 04:01:39 +00:00
Select { mailbox } => write!(f, "SELECT {}", mailbox),
Search { criteria } => write!(f, "SEARCH {}", criteria),
UidSearch { criteria } => write!(f, "UID SEARCH {}", criteria),
2021-02-23 04:01:39 +00:00
List { reference, mailbox } => write!(f, "LIST {:?} {:?}", reference, mailbox),
Fetch { uids, items } => write!(
f,
"FETCH {} {}",
uids.iter()
.map(|s| s.to_string())
.collect::<Vec<_>>()
.join(","),
items
),
UidFetch { uids, items } => write!(
f,
"UID FETCH {} {}",
uids.iter()
.map(|s| s.to_string())
.collect::<Vec<_>>()
.join(","),
items
),
2021-02-24 12:43:50 +00:00
#[cfg(feature = "rfc2177-idle")]
Idle => write!(f, "IDLE"),
#[cfg(feature = "rfc2177-idle")]
Done => write!(f, "DONE"),
2021-02-20 05:03:33 +00:00
}
}
}
#[derive(Clone, Debug)]
pub enum SearchCriteria {
All,
}
impl fmt::Display for SearchCriteria {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use SearchCriteria::*;
match self {
All => write!(f, "ALL"),
}
}
}
#[derive(Clone, Debug)]
pub enum FetchItems {
All,
Fast,
Full,
}
impl fmt::Display for FetchItems {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use FetchItems::*;
match self {
All => write!(f, "ALL"),
Fast => write!(f, "FAST"),
Full => write!(f, "FULL"),
}
}
}