2021-05-15 19:02:52 +00:00
|
|
|
use std::io::Write;
|
|
|
|
|
2022-11-21 23:19:58 +00:00
|
|
|
use instant_smtp::types::Command;
|
2021-07-20 19:51:44 +00:00
|
|
|
|
2021-05-15 19:02:52 +00:00
|
|
|
fn main() -> std::io::Result<()> {
|
|
|
|
let mut args = std::env::args();
|
|
|
|
|
|
|
|
if let Some(path) = args.nth(1) {
|
|
|
|
let data = std::fs::read(path).unwrap();
|
|
|
|
|
2022-11-21 23:19:58 +00:00
|
|
|
match Command::from_bytes(&data) {
|
2021-05-15 19:02:52 +00:00
|
|
|
Ok((remaining, command)) => {
|
|
|
|
println!("[!] {:#?}", command);
|
|
|
|
let serialized = {
|
|
|
|
let mut serialized = Vec::new();
|
|
|
|
command.serialize(&mut serialized).unwrap();
|
|
|
|
String::from_utf8(serialized).unwrap()
|
|
|
|
};
|
|
|
|
print!("[!] {}", serialized);
|
|
|
|
|
|
|
|
if !remaining.is_empty() {
|
|
|
|
println!("Remaining data in buffer: {:?}", remaining);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Err(error) => {
|
|
|
|
println!("Error parsing the command. Is it correct? ({:?})", error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Ok(());
|
|
|
|
}
|
|
|
|
|
|
|
|
loop {
|
|
|
|
let line = {
|
|
|
|
print!("Enter SMTP command (or \"exit\"): ");
|
|
|
|
std::io::stdout().flush().unwrap();
|
|
|
|
|
|
|
|
let mut line = String::new();
|
|
|
|
std::io::stdin().read_line(&mut line)?;
|
2022-10-06 19:59:15 +00:00
|
|
|
line.replace('\n', "\r\n")
|
2021-05-15 19:02:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if line.trim() == "exit" {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-11-21 23:19:58 +00:00
|
|
|
match Command::from_bytes(line.as_bytes()) {
|
2021-05-15 19:02:52 +00:00
|
|
|
Ok((remaining, command)) => {
|
|
|
|
println!("[!] {:#?}", command);
|
|
|
|
let serialized = {
|
|
|
|
let mut serialized = Vec::new();
|
|
|
|
command.serialize(&mut serialized).unwrap();
|
|
|
|
String::from_utf8(serialized).unwrap()
|
|
|
|
};
|
|
|
|
print!("[!] {}", serialized);
|
|
|
|
|
|
|
|
if !remaining.is_empty() {
|
|
|
|
println!("Remaining data in buffer: {:?}", remaining);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Err(error) => {
|
|
|
|
println!("Error parsing the command. Is it correct? ({:?})", error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|