Handle unsolicited responses in noop.
This commit is contained in:
parent
1827ade315
commit
5df0759446
2 changed files with 46 additions and 1 deletions
|
|
@ -507,7 +507,8 @@ impl<T: Read + Write> Session<T> {
|
|||
|
||||
/// Noop always succeeds, and it does nothing.
|
||||
pub fn noop(&mut self) -> Result<()> {
|
||||
self.run_command_and_check_ok("NOOP")
|
||||
self.run_command_and_read_response("NOOP")
|
||||
.and_then(|lines| parse_noop(lines, &mut self.unsolicited_responses_tx))
|
||||
}
|
||||
|
||||
/// Logout informs the server that the client is done with the connection.
|
||||
|
|
|
|||
44
src/parse.rs
44
src/parse.rs
|
|
@ -205,6 +205,50 @@ pub fn parse_capabilities(
|
|||
unsafe { ZeroCopy::make(lines, f) }
|
||||
}
|
||||
|
||||
pub fn parse_noop(
|
||||
lines: Vec<u8>,
|
||||
unsolicited: &mut mpsc::Sender<UnsolicitedResponse>,
|
||||
) -> Result<()> {
|
||||
let mut lines: &[u8] = &lines;
|
||||
|
||||
loop {
|
||||
if lines.is_empty() {
|
||||
break Ok(());
|
||||
}
|
||||
|
||||
match imap_proto::parse_response(lines) {
|
||||
Ok((rest, data)) => {
|
||||
lines = rest;
|
||||
match data {
|
||||
Response::MailboxData(MailboxDatum::Status { mailbox, status }) => {
|
||||
unsolicited
|
||||
.send(UnsolicitedResponse::Status {
|
||||
mailbox: mailbox.into(),
|
||||
attributes: status,
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
Response::MailboxData(MailboxDatum::Recent(n)) => {
|
||||
unsolicited.send(UnsolicitedResponse::Recent(n)).unwrap();
|
||||
}
|
||||
Response::MailboxData(MailboxDatum::Exists(n)) => {
|
||||
unsolicited.send(UnsolicitedResponse::Exists(n)).unwrap();
|
||||
}
|
||||
Response::Expunge(n) => {
|
||||
unsolicited.send(UnsolicitedResponse::Expunge(n)).unwrap();
|
||||
}
|
||||
resp => {
|
||||
break Err(resp.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
break Err(Error::Parse(ParseError::Invalid(lines.to_vec())));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse_mailbox(
|
||||
mut lines: &[u8],
|
||||
unsolicited: &mut mpsc::Sender<UnsolicitedResponse>,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue