use imap_codec::{
decode::{CommandDecodeError, Decoder},
CommandCodec,
};
#[path = "common/common.rs"]
mod common;
use common::{read_more, COLOR_SERVER, RESET};
use crate::common::Role;
const WELCOME: &str = r#"# Parsing of IMAP commands
"C:" denotes the client,
"S:" denotes the server, and
".." denotes the continuation of an (incomplete) command, e.g., due to the use of an IMAP literal.
Note: "\n" will be automatically replaced by "\r\n".
--------------------------------------------------------------------------------------------------
Enter IMAP command (or "exit").
"#;
fn main() {
println!("{}", WELCOME);
let mut buffer = Vec::new();
loop {
match CommandCodec::default().decode(&buffer) {
Ok((remaining, command)) => {
println!("{:#?}", command);
buffer = remaining.to_vec();
}
Err(CommandDecodeError::Incomplete) => {
read_more(&mut buffer, Role::Client);
}
Err(CommandDecodeError::LiteralFound { .. }) => {
println!("S: {COLOR_SERVER}+ {RESET}");
read_more(&mut buffer, Role::Client);
}
Err(CommandDecodeError::Failed) => {
println!("Error parsing command.");
println!("Clearing buffer.");
buffer.clear();
}
}
}
}