From 1246be8a5b89433cf1f163d170aecd2b21bf0ebd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20DOUIN?= Date: Fri, 12 Jan 2024 10:16:43 +0100 Subject: [PATCH] fix wizard serialization issues --- Cargo.lock | 8 - Cargo.toml | 12 +- README.md | 2 +- flake.nix | 1 + src/account/config.rs | 4 +- src/config/wizard.rs | 369 ++++++++++++++++++++++++++++++++++++++++-- src/imap/wizard.rs | 12 +- src/smtp/wizard.rs | 12 +- 8 files changed, 383 insertions(+), 37 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f7b8faaf..f8a8bec4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1463,8 +1463,6 @@ dependencies = [ [[package]] name = "email-lib" version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3b77f4c2aee25fe234194b651bfadc3b5a3e3c817ca8ba1cd0044f1dd462723" dependencies = [ "advisory-lock", "anyhow", @@ -2960,8 +2958,6 @@ dependencies = [ [[package]] name = "mml-lib" version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3767365c25258656f689a63f645fff963c94716caba0dc079bf19c2119ea1df7" dependencies = [ "async-recursion", "chumsky", @@ -3714,8 +3710,6 @@ dependencies = [ [[package]] name = "process-lib" version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76cb01de71b99c9d36dacf51218b950e03f80a86ee5f910ff723a1693796bad3" dependencies = [ "log", "once_cell", @@ -4252,8 +4246,6 @@ dependencies = [ [[package]] name = "secret-lib" version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "545285fca1cf00676621557d25814d589264d5635e8a767c603b3ff89364370e" dependencies = [ "keyring-lib", "process-lib", diff --git a/Cargo.toml b/Cargo.toml index d0f7a77c..cc34231d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,8 +35,8 @@ default = [ "attachment", "template", - # "pgp-commands", # enable PGP based on shell commands - # "pgp-gpg", # enable + # "pgp-commands", + # "pgp-gpg", # "pgp-native", ] @@ -116,7 +116,7 @@ clap_mangen = "0.2" console = "0.15.2" dialoguer = "0.10.2" dirs = "4.0" -email-lib = { version = "=0.20.0", default-features = false } +email-lib = { version = "=0.20.1", default-features = false } email_address = "0.2.4" env_logger = "0.8" erased-serde = "0.3" @@ -125,11 +125,11 @@ keyring-lib = "=0.3.2" log = "0.4" mail-builder = "0.3" md5 = "0.7.0" -mml-lib = { version = "=1.0.6", default-features = false } +mml-lib = { version = "=1.0.7", default-features = false } oauth-lib = "=0.1.0" once_cell = "1.16" -process-lib = "=0.3.0" -secret-lib = "=0.3.2" +process-lib = "=0.3.1" +secret-lib = "=0.3.3" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" shellexpand-utils = "=0.2.0" diff --git a/README.md b/README.md index caeff36a..a7c52b1a 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,7 @@ If you just want to **discuss** about the project, feel free to join the [Matrix Special thanks to the [NLnet foundation](https://nlnet.nl/project/Himalaya/index.html) and the [European Commission](https://www.ngi.eu/) that helped the project to receive financial support from: - [NGI Assure](https://nlnet.nl/assure/) in 2022 -- [NGI Zero Untrust](https://nlnet.nl/entrust/) in 2023 +- [NGI Zero Entrust](https://nlnet.nl/entrust/) in 2023 If you appreciate the project, feel free to donate using one of the following providers: diff --git a/flake.nix b/flake.nix index 7030070a..96df0e46 100644 --- a/flake.nix +++ b/flake.nix @@ -45,6 +45,7 @@ # Rust rust-toolchain + cargo-watch # OpenSSL openssl.dev diff --git a/src/account/config.rs b/src/account/config.rs index dbd4ec0f..9830f807 100644 --- a/src/account/config.rs +++ b/src/account/config.rs @@ -45,10 +45,10 @@ pub struct TomlAccountConfig { pub flag: Option, pub message: Option, - #[cfg(feature = "maildir")] - pub maildir: Option, #[cfg(feature = "imap")] pub imap: Option, + #[cfg(feature = "maildir")] + pub maildir: Option, #[cfg(feature = "notmuch")] pub notmuch: Option, #[cfg(feature = "smtp")] diff --git a/src/config/wizard.rs b/src/config/wizard.rs index 9547fe8f..4898ea3b 100644 --- a/src/config/wizard.rs +++ b/src/config/wizard.rs @@ -94,16 +94,21 @@ pub(crate) async fn configure(path: PathBuf) -> Result { let path = expand::path(path); println!("Writing the configuration to {path:?}…"); + let toml = pretty_serialize(&config)?; + fs::create_dir_all(path.parent().unwrap_or(&path))?; + fs::write(path, toml)?; - let mut doc = toml::to_string(&config)?.parse::()?; + println!("Exiting the wizard…"); + Ok(config) +} + +fn pretty_serialize(config: &TomlConfig) -> Result { + let mut doc: Document = toml::to_string(&config)?.parse()?; doc.iter_mut().for_each(|(_, item)| { - set_table_dotted(item, "folder-aliases"); - set_table_dotted(item, "sync-folders-strategy"); - set_table_dotted(item, "folder"); if let Some(item) = get_table_mut(item, "folder") { - set_tables_dotted(item, ["add", "list", "expunge", "purge", "delete"]); + set_tables_dotted(item, ["alias", "add", "list", "expunge", "purge", "delete"]); } set_table_dotted(item, "envelope"); @@ -124,7 +129,9 @@ pub(crate) async fn configure(path: PathBuf) -> Result { ); } + #[cfg(feature = "maildir")] set_table_dotted(item, "maildir"); + #[cfg(feature = "imap")] { set_table_dotted(item, "imap"); @@ -132,9 +139,10 @@ pub(crate) async fn configure(path: PathBuf) -> Result { set_tables_dotted(item, ["passwd", "oauth2"]); } } + #[cfg(feature = "notmuch")] set_table_dotted(item, "notmuch"); - set_table_dotted(item, "sendmail"); + #[cfg(feature = "smtp")] { set_table_dotted(item, "smtp"); @@ -143,14 +151,22 @@ pub(crate) async fn configure(path: PathBuf) -> Result { } } + #[cfg(feature = "sendmail")] + set_table_dotted(item, "sendmail"); + + #[cfg(feature = "account-sync")] + { + set_table_dotted(item, "sync"); + if let Some(item) = get_table_mut(item, "sync") { + set_tables_dotted(item, ["strategy"]); + } + } + #[cfg(feature = "pgp")] set_table_dotted(item, "pgp"); }); - fs::create_dir_all(path.parent().unwrap_or(&path))?; - fs::write(path, doc.to_string())?; - - Ok(config) + Ok(doc.to_string()) } fn get_table_mut<'a>(item: &'a mut Item, key: &'a str) -> Option<&'a mut Item> { @@ -168,3 +184,336 @@ fn set_tables_dotted<'a>(item: &'a mut Item, keys: impl IntoIterator Result Result Result Default::default(), }; - ImapAuthConfig::Passwd(PasswdConfig { passwd: secret }) + ImapAuthConfig::Passwd(PasswdConfig(secret)) }; let config = ImapConfig { diff --git a/src/smtp/wizard.rs b/src/smtp/wizard.rs index 75b088be..b3138563 100644 --- a/src/smtp/wizard.rs +++ b/src/smtp/wizard.rs @@ -135,6 +135,8 @@ pub(crate) async fn configure(account_name: &str, email: &str) -> Result Result Result Default::default(), }; - SmtpAuthConfig::Passwd(PasswdConfig { passwd: secret }) + SmtpAuthConfig::Passwd(PasswdConfig(secret)) }; let config = SmtpConfig {