Adding status command and putting parsing response into method
This commit is contained in:
parent
472f77de55
commit
d2a3482f1f
1 changed files with 15 additions and 8 deletions
|
|
@ -149,19 +149,18 @@ impl<T: Read+Write> Client<T> {
|
||||||
/// The LIST command returns a subset of names from the complete set
|
/// The LIST command returns a subset of names from the complete set
|
||||||
/// of all names available to the client.
|
/// of all names available to the client.
|
||||||
pub fn list(&mut self, reference_name: &str, mailbox_search_pattern: &str) -> Result<Vec<String>> {
|
pub fn list(&mut self, reference_name: &str, mailbox_search_pattern: &str) -> Result<Vec<String>> {
|
||||||
match self.run_command(&format!("LIST {} {}", reference_name, mailbox_search_pattern)) {
|
self.run_command_and_parse(&format!("LIST {} {}", reference_name, mailbox_search_pattern))
|
||||||
Ok(lines) => parse_response(lines),
|
|
||||||
Err(e) => Err(e)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The LSUB command returns a subset of names from the set of names
|
/// The LSUB command returns a subset of names from the set of names
|
||||||
/// that the user has declared as being "active" or "subscribed".
|
/// that the user has declared as being "active" or "subscribed".
|
||||||
pub fn lsub(&mut self, reference_name: &str, mailbox_search_pattern: &str) -> Result<Vec<String>> {
|
pub fn lsub(&mut self, reference_name: &str, mailbox_search_pattern: &str) -> Result<Vec<String>> {
|
||||||
match self.run_command(&format!("LSUB {} {}", reference_name, mailbox_search_pattern)) {
|
self.run_command_and_parse(&format!("LSUB {} {}", reference_name, mailbox_search_pattern))
|
||||||
Ok(lines) => parse_response(lines),
|
}
|
||||||
Err(e) => Err(e)
|
|
||||||
}
|
/// The STATUS command requests the status of the indicated mailbox.
|
||||||
|
pub fn status(&mut self, mailbox_name: &str, status_data_items: &str) -> Result<Vec<String>> {
|
||||||
|
self.run_command_and_parse(&format!("STATUS {} {}", mailbox_name, status_data_items))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Runs a command and checks if it returns OK.
|
/// Runs a command and checks if it returns OK.
|
||||||
|
|
@ -172,6 +171,14 @@ impl<T: Read+Write> Client<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Run a command and parse the status response.
|
||||||
|
pub fn run_command_and_parse(&mut self, command: &str) -> Result<Vec<String>> {
|
||||||
|
match self.run_command(command) {
|
||||||
|
Ok(lines) => parse_response(lines),
|
||||||
|
Err(e) => Err(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Runs any command passed to it.
|
/// Runs any command passed to it.
|
||||||
pub fn run_command(&mut self, untagged_command: &str) -> Result<Vec<String>> {
|
pub fn run_command(&mut self, untagged_command: &str) -> Result<Vec<String>> {
|
||||||
let command = self.create_command(untagged_command.to_string());
|
let command = self.create_command(untagged_command.to_string());
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue