Tidy up search a little
There's no reason to carry around a ZeroCopy here, since we own all the values.
This commit is contained in:
parent
946a6eef34
commit
a10769feba
2 changed files with 19 additions and 23 deletions
|
|
@ -623,15 +623,14 @@ impl <T: Read + Write> Session<T> {
|
||||||
|
|
||||||
/// Searches the mailbox for messages that match the given criteria and returns
|
/// Searches the mailbox for messages that match the given criteria and returns
|
||||||
/// the list of message sequence numbers of those messages.
|
/// the list of message sequence numbers of those messages.
|
||||||
pub fn search(&mut self, query: &str) -> ZeroCopyResult<HashSet<u32>> {
|
pub fn search(&mut self, query: &str) -> Result<HashSet<u32>> {
|
||||||
self.run_command_and_read_response(&format!("SEARCH {}", query))
|
self.run_command_and_read_response(&format!("SEARCH {}", query))
|
||||||
.and_then(parse_ids)
|
.and_then(parse_ids)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Searches the mailbox for messages that match the given criteria and returns
|
/// Searches the mailbox for messages that match the given criteria and returns
|
||||||
/// the list of unique identifier numbers of those messages.
|
/// the list of unique identifier numbers of those messages.
|
||||||
pub fn uid_search(&mut self, query: &str) -> ZeroCopyResult<HashSet<u32>> {
|
pub fn uid_search(&mut self, query: &str) -> Result<HashSet<u32>> {
|
||||||
eprint!("{}", format!("UID SEARCH {}", query));
|
|
||||||
self.run_command_and_read_response(&format!("UID SEARCH {}", query))
|
self.run_command_and_read_response(&format!("UID SEARCH {}", query))
|
||||||
.and_then(parse_ids)
|
.and_then(parse_ids)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
37
src/parse.rs
37
src/parse.rs
|
|
@ -222,30 +222,27 @@ pub fn parse_mailbox(mut lines: &[u8]) -> Result<Mailbox> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_ids(lines: Vec<u8>) -> ZeroCopyResult<HashSet<u32>> {
|
pub fn parse_ids(lines: Vec<u8>) -> Result<HashSet<u32>> {
|
||||||
let f = |mut lines| {
|
let mut lines = &lines[..];
|
||||||
let mut ids = HashSet::new();
|
let mut ids = HashSet::new();
|
||||||
loop {
|
loop {
|
||||||
match imap_proto::parse_response(lines) {
|
match imap_proto::parse_response(lines) {
|
||||||
IResult::Done(rest, Response::IDs(c)) => {
|
IResult::Done(rest, Response::IDs(c)) => {
|
||||||
lines = rest;
|
lines = rest;
|
||||||
ids.extend(c);
|
ids.extend(c);
|
||||||
|
|
||||||
if lines.is_empty() {
|
if lines.is_empty() {
|
||||||
break Ok(ids);
|
break Ok(ids);
|
||||||
}
|
|
||||||
}
|
|
||||||
IResult::Done(_, resp) => {
|
|
||||||
break Err(resp.into());
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
break Err(Error::Parse(ParseError::Invalid(lines.to_vec())));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
IResult::Done(_, resp) => {
|
||||||
|
break Err(resp.into());
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
break Err(Error::Parse(ParseError::Invalid(lines.to_vec())));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
unsafe { ZeroCopy::new(lines, f) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue