Adding list command

This commit is contained in:
Matt McCoy 2016-06-24 21:17:18 -04:00
parent 8418983253
commit 92341ad125

View file

@ -3,7 +3,7 @@ use openssl::ssl::{SslContext, SslStream};
use std::io::{self, Read, Write}; use std::io::{self, Read, Write};
use super::mailbox::Mailbox; use super::mailbox::Mailbox;
use super::parse::{parse_response_ok, parse_capability, parse_select_or_examine}; use super::parse::{parse_response_ok, parse_capability, parse_select_or_examine, parse_response};
use super::error::{Error, Result}; use super::error::{Error, Result};
static TAG_PREFIX: &'static str = "a"; static TAG_PREFIX: &'static str = "a";
@ -146,6 +146,15 @@ impl<T: Read+Write> Client<T> {
self.run_command_and_check_ok(&format!("COPY {} {}", sequence_set, mailbox_name).to_string()) self.run_command_and_check_ok(&format!("COPY {} {}", sequence_set, mailbox_name).to_string())
} }
/// 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<Vec<String>> {
match self.run_command(&format!("LIST {} {}", reference_name, mailbox_search_pattern)) {
Ok(lines) => parse_response(lines),
Err(e) => Err(e)
}
}
/// Runs a command and checks if it returns OK. /// Runs a command and checks if it returns OK.
pub fn run_command_and_check_ok(&mut self, command: &str) -> Result<()> { pub fn run_command_and_check_ok(&mut self, command: &str) -> Result<()> {
match self.run_command(command) { match self.run_command(command) {