diff --git a/src/client.rs b/src/client.rs index 6fcf2b9..f51a57e 100644 --- a/src/client.rs +++ b/src/client.rs @@ -2470,4 +2470,24 @@ mod tests { assert_eq!(metadata[1].value, None); } } + + #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(feature = "runtime-async-std", async_std::test)] + async fn test_parsing_error() { + // Simulate someone connecting to SMTP server with IMAP client. + let response = b"220 mail.example.org ESMTP Postcow\r\n".to_vec(); + let command = "A0001 NOOP\r\n"; + let mock_stream = MockStream::new(response); + let mut session = mock_session!(mock_stream); + assert!(session + .noop() + .await + .unwrap_err() + .to_string() + .contains("220 mail.example.org ESMTP Postcow")); + assert!( + session.stream.inner.written_buf == command.as_bytes().to_vec(), + "Invalid NOOP command" + ); + } } diff --git a/src/imap_stream.rs b/src/imap_stream.rs index 706c03a..0bad554 100644 --- a/src/imap_stream.rs +++ b/src/imap_stream.rs @@ -105,7 +105,11 @@ impl ImapStream { self.decode_needs = 0; Err(Some(io::Error::new( io::ErrorKind::Other, - format!("{:?} during parsing of {:?}", other, buf), + format!( + "{:?} during parsing of {:?}", + other, + String::from_utf8_lossy(buf) + ), ))) } }