2021-02-20 05:03:33 +00:00
|
|
|
use std::fmt;
|
|
|
|
|
|
|
|
/// Commands, without the tag part.
|
2021-03-07 00:56:35 +00:00
|
|
|
#[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,
|
|
|
|
},
|
2021-03-07 02:04:58 +00:00
|
|
|
Search {
|
|
|
|
criteria: SearchCriteria,
|
|
|
|
},
|
|
|
|
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,
|
2021-02-20 05:03:33 +00:00
|
|
|
}
|
|
|
|
|
2021-03-07 00:56:35 +00:00
|
|
|
impl fmt::Debug for Command {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
use Command::*;
|
|
|
|
match self {
|
|
|
|
Login { .. } => write!(f, "LOGIN"),
|
2021-03-07 02:04:58 +00:00
|
|
|
_ => <Self as fmt::Display>::fmt(self, f),
|
2021-03-07 00:56:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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),
|
2021-03-07 02:04:58 +00:00
|
|
|
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),
|
2021-03-07 02:04:58 +00:00
|
|
|
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"),
|
2021-02-20 05:03:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-03-07 02:04:58 +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"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|