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:
Jon Gjengset 2018-10-05 14:53:11 -04:00
parent 946a6eef34
commit a10769feba
No known key found for this signature in database
GPG key ID: D64AC9D67176DC71
2 changed files with 19 additions and 23 deletions

View file

@ -623,15 +623,14 @@ impl <T: Read + Write> Session<T> {
/// Searches the mailbox for messages that match the given criteria and returns
/// 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))
.and_then(parse_ids)
}
/// Searches the mailbox for messages that match the given criteria and returns
/// the list of unique identifier numbers of those messages.
pub fn uid_search(&mut self, query: &str) -> ZeroCopyResult<HashSet<u32>> {
eprint!("{}", format!("UID SEARCH {}", query));
pub fn uid_search(&mut self, query: &str) -> Result<HashSet<u32>> {
self.run_command_and_read_response(&format!("UID SEARCH {}", query))
.and_then(parse_ids)
}

View file

@ -222,8 +222,8 @@ pub fn parse_mailbox(mut lines: &[u8]) -> Result<Mailbox> {
}
}
pub fn parse_ids(lines: Vec<u8>) -> ZeroCopyResult<HashSet<u32>> {
let f = |mut lines| {
pub fn parse_ids(lines: Vec<u8>) -> Result<HashSet<u32>> {
let mut lines = &lines[..];
let mut ids = HashSet::new();
loop {
match imap_proto::parse_response(lines) {
@ -243,9 +243,6 @@ pub fn parse_ids(lines: Vec<u8>) -> ZeroCopyResult<HashSet<u32>> {
}
}
}
};
unsafe { ZeroCopy::new(lines, f) }
}
#[cfg(test)]