Skip to content

Commit 84b7b00

Browse files
committed
Print unparseable input as a string
Otherwise users get error messages where unparseable server response is printed as an array of bytes such as [50, 50, 48, 32, 109, 97, 105, 108, 46, 101, 120, 97, 109, 112, 108, 101, 46, 111, 114, 103, 32, 69, 83, 77, 84, 80, 32, 80, 111, 115, 116, 99, 111, 119]
1 parent 62fdb8f commit 84b7b00

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/client.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2470,4 +2470,24 @@ mod tests {
24702470
assert_eq!(metadata[1].value, None);
24712471
}
24722472
}
2473+
2474+
#[cfg_attr(feature = "runtime-tokio", tokio::test)]
2475+
#[cfg_attr(feature = "runtime-async-std", async_std::test)]
2476+
async fn test_parsing_error() {
2477+
// Simulate someone connecting to SMTP server with IMAP client.
2478+
let response = b"220 mail.example.org ESMTP Postcow\r\n".to_vec();
2479+
let command = "A0001 NOOP\r\n";
2480+
let mock_stream = MockStream::new(response);
2481+
let mut session = mock_session!(mock_stream);
2482+
assert!(session
2483+
.noop()
2484+
.await
2485+
.unwrap_err()
2486+
.to_string()
2487+
.contains("220 mail.example.org ESMTP Postcow"));
2488+
assert!(
2489+
session.stream.inner.written_buf == command.as_bytes().to_vec(),
2490+
"Invalid NOOP command"
2491+
);
2492+
}
24732493
}

src/imap_stream.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,11 @@ impl<R: Read + Write + Unpin> ImapStream<R> {
105105
self.decode_needs = 0;
106106
Err(Some(io::Error::new(
107107
io::ErrorKind::Other,
108-
format!("{:?} during parsing of {:?}", other, buf),
108+
format!(
109+
"{:?} during parsing of {:?}",
110+
other,
111+
String::from_utf8_lossy(buf)
112+
),
109113
)))
110114
}
111115
}

0 commit comments

Comments
 (0)