From d2a3482f1f321be569fdf91e07e5fc55282fc42a Mon Sep 17 00:00:00 2001 From: Matt McCoy Date: Fri, 24 Jun 2016 21:27:36 -0400 Subject: [PATCH] Adding status command and putting parsing response into method --- src/client.rs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/client.rs b/src/client.rs index cf2ed01..e8f0228 100644 --- a/src/client.rs +++ b/src/client.rs @@ -149,19 +149,18 @@ impl Client { /// The LIST command returns a subset of names from the complete set /// of all names available to the client. pub fn list(&mut self, reference_name: &str, mailbox_search_pattern: &str) -> Result> { - match self.run_command(&format!("LIST {} {}", reference_name, mailbox_search_pattern)) { - Ok(lines) => parse_response(lines), - Err(e) => Err(e) - } + self.run_command_and_parse(&format!("LIST {} {}", reference_name, mailbox_search_pattern)) } /// The LSUB command returns a subset of names from the set of names /// that the user has declared as being "active" or "subscribed". pub fn lsub(&mut self, reference_name: &str, mailbox_search_pattern: &str) -> Result> { - match self.run_command(&format!("LSUB {} {}", reference_name, mailbox_search_pattern)) { - Ok(lines) => parse_response(lines), - Err(e) => Err(e) - } + self.run_command_and_parse(&format!("LSUB {} {}", reference_name, mailbox_search_pattern)) + } + + /// The STATUS command requests the status of the indicated mailbox. + pub fn status(&mut self, mailbox_name: &str, status_data_items: &str) -> Result> { + self.run_command_and_parse(&format!("STATUS {} {}", mailbox_name, status_data_items)) } /// Runs a command and checks if it returns OK. @@ -172,6 +171,14 @@ impl Client { } } + // Run a command and parse the status response. + pub fn run_command_and_parse(&mut self, command: &str) -> Result> { + match self.run_command(command) { + Ok(lines) => parse_response(lines), + Err(e) => Err(e) + } + } + /// Runs any command passed to it. pub fn run_command(&mut self, untagged_command: &str) -> Result> { let command = self.create_command(untagged_command.to_string());