Moving parse capability into parse file
This commit is contained in:
parent
829b7de542
commit
5d94a5d7d7
2 changed files with 22 additions and 22 deletions
|
|
@ -4,7 +4,7 @@ use std::io::{Error, ErrorKind, Read, Result, Write};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
use super::mailbox::Mailbox;
|
use super::mailbox::Mailbox;
|
||||||
use super::parse::parse_response_ok;
|
use super::parse::{parse_response_ok, parse_capability};
|
||||||
|
|
||||||
static TAG_PREFIX: &'static str = "a";
|
static TAG_PREFIX: &'static str = "a";
|
||||||
const INITIAL_TAG: u32 = 0;
|
const INITIAL_TAG: u32 = 0;
|
||||||
|
|
@ -170,31 +170,11 @@ impl<T: Read+Write> Client<T> {
|
||||||
/// Capability requests a listing of capabilities that the server supports.
|
/// Capability requests a listing of capabilities that the server supports.
|
||||||
pub fn capability(&mut self) -> Result<Vec<String>> {
|
pub fn capability(&mut self) -> Result<Vec<String>> {
|
||||||
match self.run_command(&format!("CAPABILITY").to_string()) {
|
match self.run_command(&format!("CAPABILITY").to_string()) {
|
||||||
Ok(lines) => self.parse_capability(lines),
|
Ok(lines) => parse_capability(lines),
|
||||||
Err(e) => Err(e)
|
Err(e) => Err(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_capability(&mut self, lines: Vec<String>) -> Result<Vec<String>> {
|
|
||||||
let capability_regex = Regex::new(r"^\* CAPABILITY (.*)\r\n").unwrap();
|
|
||||||
|
|
||||||
//Check Ok
|
|
||||||
match parse_response_ok(lines.clone()) {
|
|
||||||
Ok(_) => (),
|
|
||||||
Err(e) => return Err(e)
|
|
||||||
};
|
|
||||||
|
|
||||||
for line in lines.iter() {
|
|
||||||
if capability_regex.is_match(line) {
|
|
||||||
let cap = capability_regex.captures(line).unwrap();
|
|
||||||
let capabilities_str = cap.at(1).unwrap();
|
|
||||||
return Ok(capabilities_str.split(' ').map(|x| x.to_string()).collect());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Err(Error::new(ErrorKind::Other, "Error parsing capabilities response"))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Expunge permanently removes all messages that have the \Deleted flag set from the currently
|
/// Expunge permanently removes all messages that have the \Deleted flag set from the currently
|
||||||
/// selected mailbox.
|
/// selected mailbox.
|
||||||
pub fn expunge(&mut self) -> Result<()> {
|
pub fn expunge(&mut self) -> Result<()> {
|
||||||
|
|
|
||||||
20
src/parse.rs
20
src/parse.rs
|
|
@ -1,6 +1,26 @@
|
||||||
use std::io::{Error, ErrorKind, Result};
|
use std::io::{Error, ErrorKind, Result};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
|
pub fn parse_capability(lines: Vec<String>) -> Result<Vec<String>> {
|
||||||
|
let capability_regex = Regex::new(r"^\* CAPABILITY (.*)\r\n").unwrap();
|
||||||
|
|
||||||
|
//Check Ok
|
||||||
|
match parse_response_ok(lines.clone()) {
|
||||||
|
Ok(_) => (),
|
||||||
|
Err(e) => return Err(e)
|
||||||
|
};
|
||||||
|
|
||||||
|
for line in lines.iter() {
|
||||||
|
if capability_regex.is_match(line) {
|
||||||
|
let cap = capability_regex.captures(line).unwrap();
|
||||||
|
let capabilities_str = cap.at(1).unwrap();
|
||||||
|
return Ok(capabilities_str.split(' ').map(|x| x.to_string()).collect());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Err(Error::new(ErrorKind::Other, "Error parsing capabilities response"))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn parse_response_ok(lines: Vec<String>) -> Result<()> {
|
pub fn parse_response_ok(lines: Vec<String>) -> Result<()> {
|
||||||
let ok_regex = Regex::new(r"^([a-zA-Z0-9]+) ([a-zA-Z0-9]+)(.*)").unwrap();
|
let ok_regex = Regex::new(r"^([a-zA-Z0-9]+) ([a-zA-Z0-9]+)(.*)").unwrap();
|
||||||
let last_line = lines.last().unwrap();
|
let last_line = lines.last().unwrap();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue