Merge pull request #184 from mordak/try_handle_unsolicited
Try handle unsolicited & clippy
This commit is contained in:
commit
39a78fdea4
3 changed files with 20 additions and 22 deletions
|
|
@ -1459,7 +1459,7 @@ impl<T: Read + Write> Connection<T> {
|
||||||
// Remove CRLF
|
// Remove CRLF
|
||||||
let len = into.len();
|
let len = into.len();
|
||||||
let line = &into[(len - read)..(len - 2)];
|
let line = &into[(len - read)..(len - 2)];
|
||||||
eprint!("S: {}\n", String::from_utf8_lossy(line));
|
eprintln!("S: {}", String::from_utf8_lossy(line));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(read)
|
Ok(read)
|
||||||
|
|
@ -1475,7 +1475,7 @@ impl<T: Read + Write> Connection<T> {
|
||||||
self.stream.write_all(&[CR, LF])?;
|
self.stream.write_all(&[CR, LF])?;
|
||||||
self.stream.flush()?;
|
self.stream.flush()?;
|
||||||
if self.debug {
|
if self.debug {
|
||||||
eprint!("C: {}\n", String::from_utf8(buf.to_vec()).unwrap());
|
eprintln!("C: {}", String::from_utf8(buf.to_vec()).unwrap());
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
use crate::client::*;
|
use crate::client::*;
|
||||||
use crate::error::{Error, ParseError, Result};
|
use crate::error::{Error, ParseError, Result};
|
||||||
use crate::parse::handle_unilateral;
|
use crate::parse::try_handle_unilateral;
|
||||||
use crate::types::*;
|
use crate::types::*;
|
||||||
use imap_proto::types::{MailboxDatum, Metadata, Response, ResponseCode};
|
use imap_proto::types::{MailboxDatum, Metadata, Response, ResponseCode};
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
|
|
@ -34,7 +34,7 @@ impl CmdListItemFormat for Metadata {
|
||||||
self.value
|
self.value
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|v| validate_str(v.as_str()).unwrap())
|
.map(|v| validate_str(v.as_str()).unwrap())
|
||||||
.unwrap_or("NIL".to_string())
|
.unwrap_or_else(|| "NIL".to_string())
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -69,9 +69,9 @@ impl Default for MetadataDepth {
|
||||||
impl MetadataDepth {
|
impl MetadataDepth {
|
||||||
fn depth_str<'a>(self) -> &'a str {
|
fn depth_str<'a>(self) -> &'a str {
|
||||||
match self {
|
match self {
|
||||||
MetadataDepth::Zero => return "0",
|
MetadataDepth::Zero => "0",
|
||||||
MetadataDepth::One => return "1",
|
MetadataDepth::One => "1",
|
||||||
MetadataDepth::Infinity => return "infinity",
|
MetadataDepth::Infinity => "infinity",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -97,7 +97,7 @@ fn parse_metadata<'a>(
|
||||||
res.append(&mut values);
|
res.append(&mut values);
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
if let Some(unhandled) = handle_unilateral(resp, unsolicited) {
|
if let Some(unhandled) = try_handle_unilateral(resp, unsolicited) {
|
||||||
break Err(unhandled.into());
|
break Err(unhandled.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -175,18 +175,15 @@ impl<T: Read + Write> Session<T> {
|
||||||
let s = v.as_slice().join(" ");
|
let s = v.as_slice().join(" ");
|
||||||
let mut command = format!("GETMETADATA (DEPTH {}", depth.depth_str());
|
let mut command = format!("GETMETADATA (DEPTH {}", depth.depth_str());
|
||||||
|
|
||||||
match maxsize {
|
if let Some(size) = maxsize {
|
||||||
Some(size) => {
|
command.push_str(format!(" MAXSIZE {}", size).as_str());
|
||||||
command.push_str(format!(" MAXSIZE {}", size).as_str());
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
command.push_str(
|
command.push_str(
|
||||||
format!(
|
format!(
|
||||||
") {} ({})",
|
") {} ({})",
|
||||||
mailbox
|
mailbox
|
||||||
.map(|mbox| validate_str(mbox.as_ref()).unwrap())
|
.map(|mbox| validate_str(mbox).unwrap())
|
||||||
.unwrap_or_else(|| "\"\"".to_string()),
|
.unwrap_or_else(|| "\"\"".to_string()),
|
||||||
s
|
s
|
||||||
)
|
)
|
||||||
|
|
|
||||||
17
src/parse.rs
17
src/parse.rs
|
|
@ -50,7 +50,7 @@ where
|
||||||
|
|
||||||
match map(resp)? {
|
match map(resp)? {
|
||||||
MapOrNot::Map(t) => things.push(t),
|
MapOrNot::Map(t) => things.push(t),
|
||||||
MapOrNot::Not(resp) => match handle_unilateral(resp, unsolicited) {
|
MapOrNot::Not(resp) => match try_handle_unilateral(resp, unsolicited) {
|
||||||
Some(Response::Fetch(..)) => continue,
|
Some(Response::Fetch(..)) => continue,
|
||||||
Some(resp) => break Err(resp.into()),
|
Some(resp) => break Err(resp.into()),
|
||||||
None => {}
|
None => {}
|
||||||
|
|
@ -150,7 +150,7 @@ pub fn parse_expunge(
|
||||||
}
|
}
|
||||||
Ok((rest, data)) => {
|
Ok((rest, data)) => {
|
||||||
lines = rest;
|
lines = rest;
|
||||||
if let Some(resp) = handle_unilateral(data, unsolicited) {
|
if let Some(resp) = try_handle_unilateral(data, unsolicited) {
|
||||||
return Err(resp.into());
|
return Err(resp.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -185,7 +185,7 @@ pub fn parse_capabilities(
|
||||||
}
|
}
|
||||||
Ok((rest, data)) => {
|
Ok((rest, data)) => {
|
||||||
lines = rest;
|
lines = rest;
|
||||||
if let Some(resp) = handle_unilateral(data, unsolicited) {
|
if let Some(resp) = try_handle_unilateral(data, unsolicited) {
|
||||||
break Err(resp.into());
|
break Err(resp.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -217,7 +217,7 @@ pub fn parse_noop(
|
||||||
match imap_proto::parser::parse_response(lines) {
|
match imap_proto::parser::parse_response(lines) {
|
||||||
Ok((rest, data)) => {
|
Ok((rest, data)) => {
|
||||||
lines = rest;
|
lines = rest;
|
||||||
if let Some(resp) = handle_unilateral(data, unsolicited) {
|
if let Some(resp) = try_handle_unilateral(data, unsolicited) {
|
||||||
break Err(resp.into());
|
break Err(resp.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -339,7 +339,7 @@ pub fn parse_ids(
|
||||||
}
|
}
|
||||||
Ok((rest, data)) => {
|
Ok((rest, data)) => {
|
||||||
lines = rest;
|
lines = rest;
|
||||||
if let Some(resp) = handle_unilateral(data, unsolicited) {
|
if let Some(resp) = try_handle_unilateral(data, unsolicited) {
|
||||||
break Err(resp.into());
|
break Err(resp.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -350,9 +350,10 @@ pub fn parse_ids(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if this is simply a unilateral server response
|
// Check if this is simply a unilateral server response (see Section 7 of RFC 3501).
|
||||||
// (see Section 7 of RFC 3501):
|
//
|
||||||
pub(crate) fn handle_unilateral<'a>(
|
// Returns `None` if the response was handled, `Some(res)` if not.
|
||||||
|
pub(crate) fn try_handle_unilateral<'a>(
|
||||||
res: Response<'a>,
|
res: Response<'a>,
|
||||||
unsolicited: &mut mpsc::Sender<UnsolicitedResponse>,
|
unsolicited: &mut mpsc::Sender<UnsolicitedResponse>,
|
||||||
) -> Option<Response<'a>> {
|
) -> Option<Response<'a>> {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue