panorama/imap/examples/parse_response.rs
2021-02-19 23:03:33 -06:00

31 lines
824 B
Rust

use panorama_imap::Response;
use std::io::Write;
fn main() -> std::io::Result<()> {
loop {
let line = {
print!("Enter IMAP4REV1 response: ");
std::io::stdout().flush().unwrap();
let mut line = String::new();
std::io::stdin().read_line(&mut line)?;
line
};
match Response::from_bytes(line.replace("\n", "\r\n").as_bytes()) {
Ok((remaining, command)) => {
println!("{:#?}", command);
if !remaining.is_empty() {
println!("Remaining data in buffer: {:?}", remaining);
}
}
Err(_) => {
println!("Error parsing the response. Is it correct? Exiting.");
break;
}
}
}
Ok(())
}