clean unused deps

This commit is contained in:
Clément DOUIN 2024-09-03 11:02:23 +02:00
parent cce0baf81a
commit cfc88118bb
No known key found for this signature in database
GPG key ID: 353E4A18EE0FAB72
7 changed files with 10 additions and 372 deletions

12
Cargo.lock generated
View file

@ -291,9 +291,9 @@ checksum = "8b75356056920673b02621b35afd0f7dda9306d03c79a30f5c56c44cf256e3de"
[[package]]
name = "async-trait"
version = "0.1.81"
version = "0.1.82"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e0c28dcc82d7c8ead5cb13beb15405b57b8546e93215673ff8ca0349a028107"
checksum = "a27b8a3a6e1a44fa4c8baf1f653e4172e81486d4941f2237e20dc2d0cf4ddff1"
dependencies = [
"proc-macro2",
"quote",
@ -1232,7 +1232,7 @@ dependencies = [
[[package]]
name = "email-lib"
version = "0.25.0"
source = "git+https://github.com/pimalaya/core#d61f0e9c6fb26abd0d7f104e6839fcd02ef423bc"
source = "git+https://github.com/pimalaya/core#45efcdc68797efdbdf7ee23a1e77b84ff32c2925"
dependencies = [
"async-trait",
"chrono",
@ -1896,16 +1896,12 @@ dependencies = [
"process-lib",
"secret-lib",
"serde",
"serde-toml-merge",
"serde_json",
"shellexpand-utils",
"sled",
"tokio",
"toml",
"toml_edit 0.22.20",
"tracing",
"tracing-error",
"tracing-subscriber",
"url",
"uuid",
]
@ -2895,7 +2891,7 @@ dependencies = [
[[package]]
name = "oauth-lib"
version = "0.1.1"
source = "git+https://github.com/pimalaya/core#d61f0e9c6fb26abd0d7f104e6839fcd02ef423bc"
source = "git+https://github.com/pimalaya/core#45efcdc68797efdbdf7ee23a1e77b84ff32c2925"
dependencies = [
"log",
"oauth2",

View file

@ -40,7 +40,7 @@ sendmail = ["email-lib/sendmail", "pimalaya-tui/sendmail"]
keyring = ["email-lib/keyring", "pimalaya-tui/keyring", "secret-lib?/keyring-tokio"]
oauth2 = ["dep:oauth-lib", "email-lib/oauth2", "pimalaya-tui/oauth2", "keyring"]
wizard = ["dep:email_address", "dep:secret-lib", "dep:toml_edit", "email-lib/autoconfig"]
wizard = ["dep:email_address", "dep:secret-lib", "email-lib/autoconfig"]
pgp = []
pgp-commands = ["email-lib/pgp-commands", "mml-lib/pgp-commands", "pgp"]
@ -69,16 +69,12 @@ pimalaya-tui = { version = "=0.1.0", default-features = false, features = ["emai
process-lib = { version = "=0.4.2", features = ["derive"] }
secret-lib = { version = "=0.4.6", default-features = false, features = ["command", "derive"], optional = true }
serde = { version = "1", features = ["derive"] }
serde-toml-merge = "0.3"
serde_json = "1"
shellexpand-utils = "=0.2.1"
sled = "=0.34.7"
tokio = { version = "1.23", default-features = false, features = ["macros", "rt-multi-thread"] }
toml = "0.8"
toml_edit = { version = "0.22", optional = true }
tracing = "0.1.40"
tracing-error = "0.2.0"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
url = "2.2"
uuid = { version = "0.8", features = ["v4"] }

View file

@ -60,13 +60,11 @@ pub async fn configure_sender(
)?;
match backend {
// TODO
#[cfg(feature = "smtp")]
BackendKind::Smtp => {
let config = wizard::smtp::start(account_name, email, autoconfig).await?;
Ok(BackendConfig::Smtp(config))
}
// TODO
#[cfg(feature = "sendmail")]
BackendKind::Sendmail => {
let config = wizard::sendmail::start()?;

View file

@ -1,8 +1,7 @@
use std::{fs, path::PathBuf};
use color_eyre::Result;
use pimalaya_tui::{print, prompt};
use toml_edit::{DocumentMut, Table};
use pimalaya_tui::{config::TomlConfig, print, prompt};
use crate::account;
@ -19,323 +18,10 @@ pub async fn configure(path: &PathBuf) -> Result<Config> {
let path = prompt::path("Where to save the configuration?", Some(path))?;
println!("Writing the configuration to {}", path.display());
let toml = pretty_serialize(&config)?;
let toml = config.pretty_serialize()?;
fs::create_dir_all(path.parent().unwrap_or(&path))?;
fs::write(path, toml)?;
println!("Done! Exiting the wizard…");
Ok(config)
}
fn pretty_serialize(config: &Config) -> Result<String> {
let mut doc: DocumentMut = toml::to_string(&config)?.parse()?;
doc.iter_mut().for_each(|(_, item)| {
if let Some(table) = item.as_table_mut() {
table.iter_mut().for_each(|(_, item)| {
if let Some(table) = item.as_table_mut() {
set_table_dotted(table);
}
})
}
});
Ok(doc.to_string())
}
fn set_table_dotted(table: &mut Table) {
let keys: Vec<String> = table.iter().map(|(key, _)| key.to_string()).collect();
for ref key in keys {
if let Some(table) = table.get_mut(key).unwrap().as_table_mut() {
table.set_dotted(true);
set_table_dotted(table)
}
}
}
// #[cfg(test)]
// mod test {
// use std::collections::HashMap;
// use crate::{account::config::TomlAccountConfig, config::TomlConfig};
// use super::pretty_serialize;
// fn assert_eq(config: TomlAccountConfig, expected_toml: &str) {
// let config = TomlConfig {
// accounts: HashMap::from_iter([("test".into(), config)]),
// ..Default::default()
// };
// let toml = pretty_serialize(&config).expect("serialize error");
// assert_eq!(toml, expected_toml);
// let expected_config = toml::from_str(&toml).expect("deserialize error");
// assert_eq!(config, expected_config);
// }
// #[test]
// fn pretty_serialize_default() {
// assert_eq(
// TomlAccountConfig {
// email: "test@localhost".into(),
// ..Default::default()
// },
// r#"[accounts.test]
// email = "test@localhost"
// "#,
// )
// }
// #[cfg(feature = "imap")]
// #[test]
// fn pretty_serialize_imap_passwd_cmd() {
// use email::{
// account::config::passwd::PasswdConfig,
// imap::config::{ImapAuthConfig, ImapConfig},
// };
// use secret::Secret;
// assert_eq(
// TomlAccountConfig {
// email: "test@localhost".into(),
// imap: Some(ImapConfig {
// host: "localhost".into(),
// port: 143,
// login: "test@localhost".into(),
// auth: ImapAuthConfig::Passwd(PasswdConfig(Secret::new_command(
// "pass show test",
// ))),
// ..Default::default()
// }),
// ..Default::default()
// },
// r#"[accounts.test]
// email = "test@localhost"
// imap.host = "localhost"
// imap.port = 143
// imap.login = "test@localhost"
// imap.passwd.command = "pass show test"
// "#,
// );
// }
// #[cfg(feature = "imap")]
// #[test]
// fn pretty_serialize_imap_passwd_cmds() {
// use email::{
// account::config::passwd::PasswdConfig,
// imap::config::{ImapAuthConfig, ImapConfig},
// };
// use secret::Secret;
// assert_eq(
// TomlAccountConfig {
// email: "test@localhost".into(),
// imap: Some(ImapConfig {
// host: "localhost".into(),
// port: 143,
// login: "test@localhost".into(),
// auth: ImapAuthConfig::Passwd(PasswdConfig(Secret::new_command(vec![
// "pass show test",
// "tr -d '[:blank:]'",
// ]))),
// ..Default::default()
// }),
// ..Default::default()
// },
// r#"[accounts.test]
// email = "test@localhost"
// imap.host = "localhost"
// imap.port = 143
// imap.login = "test@localhost"
// imap.passwd.command = ["pass show test", "tr -d '[:blank:]'"]
// "#,
// );
// }
// #[cfg(feature = "imap")]
// #[test]
// fn pretty_serialize_imap_oauth2() {
// use email::{
// account::config::oauth2::OAuth2Config,
// imap::config::{ImapAuthConfig, ImapConfig},
// };
// assert_eq(
// TomlAccountConfig {
// email: "test@localhost".into(),
// imap: Some(ImapConfig {
// host: "localhost".into(),
// port: 143,
// login: "test@localhost".into(),
// auth: ImapAuthConfig::OAuth2(OAuth2Config {
// client_id: "client-id".into(),
// auth_url: "auth-url".into(),
// token_url: "token-url".into(),
// ..Default::default()
// }),
// ..Default::default()
// }),
// ..Default::default()
// },
// r#"[accounts.test]
// email = "test@localhost"
// imap.host = "localhost"
// imap.port = 143
// imap.login = "test@localhost"
// imap.oauth2.method = "xoauth2"
// imap.oauth2.client-id = "client-id"
// imap.oauth2.auth-url = "auth-url"
// imap.oauth2.token-url = "token-url"
// imap.oauth2.pkce = false
// imap.oauth2.scopes = []
// "#,
// );
// }
// #[cfg(feature = "maildir")]
// #[test]
// fn pretty_serialize_maildir() {
// use email::maildir::config::MaildirConfig;
// assert_eq(
// TomlAccountConfig {
// email: "test@localhost".into(),
// maildir: Some(MaildirConfig {
// root_dir: "/tmp/test".into(),
// }),
// ..Default::default()
// },
// r#"[accounts.test]
// email = "test@localhost"
// maildir.root-dir = "/tmp/test"
// "#,
// );
// }
// #[cfg(feature = "smtp")]
// #[test]
// fn pretty_serialize_smtp_passwd_cmd() {
// use email::{
// account::config::passwd::PasswdConfig,
// smtp::config::{SmtpAuthConfig, SmtpConfig},
// };
// use secret::Secret;
// assert_eq(
// TomlAccountConfig {
// email: "test@localhost".into(),
// smtp: Some(SmtpConfig {
// host: "localhost".into(),
// port: 143,
// login: "test@localhost".into(),
// auth: SmtpAuthConfig::Passwd(PasswdConfig(Secret::new_command(
// "pass show test",
// ))),
// ..Default::default()
// }),
// ..Default::default()
// },
// r#"[accounts.test]
// email = "test@localhost"
// smtp.host = "localhost"
// smtp.port = 143
// smtp.login = "test@localhost"
// smtp.passwd.command = "pass show test"
// "#,
// );
// }
// #[cfg(feature = "smtp")]
// #[test]
// fn pretty_serialize_smtp_passwd_cmds() {
// use email::{
// account::config::passwd::PasswdConfig,
// smtp::config::{SmtpAuthConfig, SmtpConfig},
// };
// use secret::Secret;
// assert_eq(
// TomlAccountConfig {
// email: "test@localhost".into(),
// smtp: Some(SmtpConfig {
// host: "localhost".into(),
// port: 143,
// login: "test@localhost".into(),
// auth: SmtpAuthConfig::Passwd(PasswdConfig(Secret::new_command(vec![
// "pass show test",
// "tr -d '[:blank:]'",
// ]))),
// ..Default::default()
// }),
// ..Default::default()
// },
// r#"[accounts.test]
// email = "test@localhost"
// smtp.host = "localhost"
// smtp.port = 143
// smtp.login = "test@localhost"
// smtp.passwd.command = ["pass show test", "tr -d '[:blank:]'"]
// "#,
// );
// }
// #[cfg(feature = "smtp")]
// #[test]
// fn pretty_serialize_smtp_oauth2() {
// use email::{
// account::config::oauth2::OAuth2Config,
// smtp::config::{SmtpAuthConfig, SmtpConfig},
// };
// assert_eq(
// TomlAccountConfig {
// email: "test@localhost".into(),
// smtp: Some(SmtpConfig {
// host: "localhost".into(),
// port: 143,
// login: "test@localhost".into(),
// auth: SmtpAuthConfig::OAuth2(OAuth2Config {
// client_id: "client-id".into(),
// auth_url: "auth-url".into(),
// token_url: "token-url".into(),
// ..Default::default()
// }),
// ..Default::default()
// }),
// ..Default::default()
// },
// r#"[accounts.test]
// email = "test@localhost"
// smtp.host = "localhost"
// smtp.port = 143
// smtp.login = "test@localhost"
// smtp.oauth2.method = "xoauth2"
// smtp.oauth2.client-id = "client-id"
// smtp.oauth2.auth-url = "auth-url"
// smtp.oauth2.token-url = "token-url"
// smtp.oauth2.pkce = false
// smtp.oauth2.scopes = []
// "#,
// );
// }
// #[cfg(feature = "pgp-cmds")]
// #[test]
// fn pretty_serialize_pgp_cmds() {
// use email::account::config::pgp::PgpConfig;
// assert_eq(
// TomlAccountConfig {
// email: "test@localhost".into(),
// pgp: Some(PgpConfig::Cmds(Default::default())),
// ..Default::default()
// },
// r#"[accounts.test]
// email = "test@localhost"
// pgp.backend = "cmds"
// "#,
// );
// }
// }

View file

@ -9,7 +9,6 @@ pub mod folder;
pub mod manual;
pub mod output;
pub mod printer;
pub mod tracing;
pub mod ui;
#[doc(inline)]

View file

@ -10,6 +10,9 @@ use pimalaya_tui::cli::tracing;
async fn main() -> Result<()> {
let tracing = tracing::install()?;
#[cfg(feature = "keyring")]
secret::keyring::set_global_service_name("himalaya-cli");
// if the first argument starts by "mailto:", execute straight the
// mailto message command
let mailto = std::env::args()

View file

@ -1,40 +0,0 @@
use color_eyre::eyre::Result;
use std::env;
use tracing_error::ErrorLayer;
use tracing_subscriber::{filter::LevelFilter, fmt, prelude::*, EnvFilter};
pub fn install() -> Result<LevelFilter> {
let fmt_layer = fmt::layer();
let (filter_layer, current_filter) = match EnvFilter::try_from_default_env() {
Err(_) => (EnvFilter::try_new("off").unwrap(), LevelFilter::OFF),
Ok(layer) => {
let level = layer.max_level_hint().unwrap_or(LevelFilter::OFF);
(layer, level)
}
};
let registry = tracing_subscriber::registry()
.with(filter_layer)
.with(ErrorLayer::default());
if current_filter == LevelFilter::OFF {
registry.with(fmt_layer.without_time()).init()
} else {
registry.with(fmt_layer).init()
}
if env::var("RUST_BACKTRACE").is_err() && current_filter == LevelFilter::TRACE {
env::set_var("RUST_BACKTRACE", "1");
}
let debug = current_filter >= LevelFilter::DEBUG;
color_eyre::config::HookBuilder::new()
.capture_span_trace_by_default(debug)
.display_location_section(debug)
.display_env_section(false)
.install()?;
Ok(current_filter)
}