Fix initial tag tyype and remove regex creation checks

This commit is contained in:
Matt McCoy 2016-06-21 13:32:13 -04:00
parent 8981a03870
commit 78f22be622

View file

@ -4,7 +4,7 @@ use std::io::{Error, ErrorKind, Read, Result, Write};
use regex::Regex; use regex::Regex;
static TAG_PREFIX: &'static str = "a"; static TAG_PREFIX: &'static str = "a";
const INITIAL_TAG: i32 = 1; const INITIAL_TAG: u32 = 1;
/// Stream to interface with the IMAP server. This interface is only for the command stream. /// Stream to interface with the IMAP server. This interface is only for the command stream.
pub struct IMAPStream<T> { pub struct IMAPStream<T> {
@ -68,40 +68,19 @@ impl<T: Read+Write> IMAPStream<T> {
} }
fn parse_select_or_examine(&mut self, lines: Vec<String>) -> Result<IMAPMailbox> { fn parse_select_or_examine(&mut self, lines: Vec<String>) -> Result<IMAPMailbox> {
let exists_regex = match Regex::new(r"^\* (\d+) EXISTS\r\n") { let exists_regex = Regex::new(r"^\* (\d+) EXISTS\r\n").unwrap();
Ok(re) => re,
Err(err) => panic!("{}", err),
};
let recent_regex = match Regex::new(r"^\* (\d+) RECENT\r\n") { let recent_regex = Regex::new(r"^\* (\d+) RECENT\r\n").unwrap();
Ok(re) => re,
Err(err) => panic!("{}", err),
};
let flags_regex = match Regex::new(r"^\* FLAGS (.+)\r\n") { let flags_regex = Regex::new(r"^\* FLAGS (.+)\r\n").unwrap();
Ok(re) => re,
Err(err) => panic!("{}", err),
};
let unseen_regex = match Regex::new(r"^OK \[UNSEEN (\d+)\](.*)\r\n") { let unseen_regex = Regex::new(r"^OK \[UNSEEN (\d+)\](.*)\r\n").unwrap();
Ok(re) => re,
Err(err) => panic!("{}", err),
};
let uid_validity_regex = match Regex::new(r"^OK \[UIDVALIDITY (\d+)\](.*)\r\n") { let uid_validity_regex = Regex::new(r"^OK \[UIDVALIDITY (\d+)\](.*)\r\n").unwrap();
Ok(re) => re,
Err(err) => panic!("{}", err),
};
let uid_next_regex = match Regex::new(r"^OK \[UIDNEXT (\d+)\](.*)\r\n") { let uid_next_regex = Regex::new(r"^OK \[UIDNEXT (\d+)\](.*)\r\n").unwrap();
Ok(re) => re,
Err(err) => panic!("{}", err),
};
let permanent_flags_regex = match Regex::new(r"^OK \[PERMANENTFLAGS (.+)\]\r\n") { let permanent_flags_regex = Regex::new(r"^OK \[PERMANENTFLAGS (.+)\]\r\n").unwrap();
Ok(re) => re,
Err(err) => panic!("{}", err),
};
//Check Ok //Check Ok
match self.parse_response_ok(lines.clone()) { match self.parse_response_ok(lines.clone()) {