Add proper imap-shell in tools subcommand for debugging

Add imap-shell to tools subcommand.

To use, run

  $ meli tools imap-shell <account-name>

Where account name is what you have in your config file.

For convenience, typing an invalid name will list all the valid names:

  $ meli tools imap-shell "asdf"
  The configuration file does not contain the account `asdf`. It contains the following:
  user@example.com
  work
  personal account
  Try again with a valid account name.

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
pull/401/head
Manos Pitsidianakis 4 months ago
parent e187bb3f0d
commit 571bd98497
No known key found for this signature in database
GPG Key ID: 7729C7707F7E09D0

@ -260,6 +260,8 @@ pub fn tool(path: Option<PathBuf>, opt: crate::args::ToolOpt) -> Result<()> {
}
}
ToolOpt::ImapShell { .. } => {
use melib::imap::{imap_codec::imap_types::command::CommandBody, RequiredResponses};
let mut imap = melib::imap::ImapType::new(
&account_conf.account,
Box::new(|_| true),
@ -270,10 +272,66 @@ pub fn tool(path: Option<PathBuf>, opt: crate::args::ToolOpt) -> Result<()> {
let ex = melib::smol::Executor::new();
futures::executor::block_on(ex.run(futures::future::pending::<()>()));
});
(imap.as_any_mut())
let imap = (imap.as_any_mut())
.downcast_mut::<melib::imap::ImapType>()
.unwrap();
let mut conn = melib::imap::ImapConnection::new_connection(
&imap.server_conf,
"ImapType::shell".into(),
imap.uid_store.clone(),
);
futures::executor::block_on(timeout(imap.server_conf.timeout, conn.connect()))
.unwrap()
.shell();
.unwrap();
let mut res = Vec::with_capacity(8 * 1024);
futures::executor::block_on(timeout(
imap.server_conf.timeout,
conn.send_command(CommandBody::Noop),
))
.unwrap()
.unwrap();
futures::executor::block_on(timeout(
imap.server_conf.timeout,
conn.read_response(&mut res, RequiredResponses::empty()),
))
.unwrap()
.unwrap();
let mut input = String::new();
println!(
"Connected. Type a valid IMAP command such as LIST \"\" \"*\" and CAPABILITY hit \
Return. Exit with Ctrl+C or with the command QUIT."
);
loop {
use std::io;
input.clear();
res.clear();
match io::stdin().read_line(&mut input) {
Ok(_) => {
futures::executor::block_on(timeout(
imap.server_conf.timeout,
conn.send_command_raw(input.as_bytes()),
))
.unwrap()
.unwrap();
futures::executor::block_on(timeout(
imap.server_conf.timeout,
conn.read_lines(&mut res, Vec::new()),
))
.unwrap()
.unwrap();
if input.trim().eq_ignore_ascii_case("logout") {
break;
}
println!("\rC: {}", input.trim());
print!("S: {}", String::from_utf8_lossy(&res));
}
Err(error) => println!("error: {}", error),
}
}
}
#[cfg(feature = "jmap")]
ToolOpt::JmapShell { .. } => {

@ -52,6 +52,7 @@ use std::{
time::{Duration, SystemTime},
};
pub extern crate imap_codec;
pub use cache::ModSequence;
use futures::{lock::Mutex as FutureMutex, stream::Stream};
use imap_codec::imap_types::{

Loading…
Cancel
Save