Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print unparseable input as a string #107

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
}
}
6 changes: 5 additions & 1 deletion src/imap_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ impl<R: Read + Write + Unpin> ImapStream<R> {
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)
),
)))
}
}
Expand Down
Loading