This commit is contained in:
Jon Gjengset 2018-07-21 12:26:30 -04:00
parent dea9398e08
commit 4c4fd89232
No known key found for this signature in database
GPG key ID: D64AC9D67176DC71
3 changed files with 20 additions and 14 deletions

View file

@ -7,8 +7,9 @@ use std::time::Duration;
use super::authenticator::Authenticator; use super::authenticator::Authenticator;
use super::error::{Error, ParseError, Result, ValidateError}; use super::error::{Error, ParseError, Result, ValidateError};
use super::parse::{parse_authenticate_response, parse_capabilities, parse_fetches, parse_mailbox, use super::parse::{
parse_names}; parse_authenticate_response, parse_capabilities, parse_fetches, parse_mailbox, parse_names,
};
use super::types::*; use super::types::*;
static TAG_PREFIX: &'static str = "a"; static TAG_PREFIX: &'static str = "a";
@ -165,7 +166,10 @@ impl<'a, T: SetReadTimeout + Read + Write + 'a> IdleHandle<'a, T> {
/// Block until the selected mailbox changes, or until the given amount of time has expired. /// Block until the selected mailbox changes, or until the given amount of time has expired.
pub fn wait_timeout(mut self, timeout: Duration) -> Result<()> { pub fn wait_timeout(mut self, timeout: Duration) -> Result<()> {
self.client.stream.get_mut().set_read_timeout(Some(timeout))?; self.client
.stream
.get_mut()
.set_read_timeout(Some(timeout))?;
let res = self.wait_inner(); let res = self.wait_inner();
self.client.stream.get_mut().set_read_timeout(None).is_ok(); self.client.stream.get_mut().set_read_timeout(None).is_ok();
res res
@ -274,9 +278,7 @@ impl<T: Read + Write> Client<T> {
self.readline(&mut line)?; self.readline(&mut line)?;
if line.starts_with(b"+") { if line.starts_with(b"+") {
let data = parse_authenticate_response( let data = parse_authenticate_response(String::from_utf8(line).unwrap())?;
String::from_utf8(line).unwrap()
)?;
let auth_response = authenticator.process(data); let auth_response = authenticator.process(data);
self.write_line(auth_response.into_bytes().as_slice())? self.write_line(auth_response.into_bytes().as_slice())?
@ -536,14 +538,14 @@ impl<T: Read + Write> Client<T> {
use imap_proto::Status; use imap_proto::Status;
match status { match status {
Status::Bad => { Status::Bad => {
break Err(Error::BadResponse(expl.unwrap_or( break Err(Error::BadResponse(
"no explanation given".to_string(), expl.unwrap_or("no explanation given".to_string()),
))) ))
} }
Status::No => { Status::No => {
break Err(Error::NoResponse(expl.unwrap_or( break Err(Error::NoResponse(
"no explanation given".to_string(), expl.unwrap_or("no explanation given".to_string()),
))) ))
} }
_ => break Err(Error::Parse(ParseError::Invalid(data.split_off(0)))), _ => break Err(Error::Parse(ParseError::Invalid(data.split_off(0)))),
} }

View file

@ -96,7 +96,11 @@ pub fn parse_fetches(lines: Vec<u8>) -> ZeroCopyResult<Vec<Fetch>> {
AttributeValue::Uid(uid) => fetch.uid = Some(uid), AttributeValue::Uid(uid) => fetch.uid = Some(uid),
AttributeValue::Rfc822(rfc) => fetch.rfc822 = rfc, AttributeValue::Rfc822(rfc) => fetch.rfc822 = rfc,
AttributeValue::Rfc822Header(rfc) => fetch.rfc822_header = rfc, AttributeValue::Rfc822Header(rfc) => fetch.rfc822_header = rfc,
AttributeValue::BodySection {section: _, index: _, data} => fetch.body = data, AttributeValue::BodySection {
section: _,
index: _,
data,
} => fetch.body = data,
_ => {} _ => {}
} }
} }

View file

@ -1,7 +1,7 @@
// Note that none of these fields are *actually* 'static. // Note that none of these fields are *actually* 'static.
// Rather, they are tied to the lifetime of the `ZeroCopy` that contains this `Name`. // Rather, they are tied to the lifetime of the `ZeroCopy` that contains this `Name`.
use std::collections::HashSet;
use std::collections::hash_set::Iter; use std::collections::hash_set::Iter;
use std::collections::HashSet;
pub struct Capabilities(pub(crate) HashSet<&'static str>); pub struct Capabilities(pub(crate) HashSet<&'static str>);
use std::borrow::Borrow; use std::borrow::Borrow;