diff --git a/Cargo.lock b/Cargo.lock index b3bfaa3..2dba8c7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1001,7 +1001,7 @@ dependencies = [ "mail-send", "maildirpp", "md5", - "mml-lib 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "mml-lib", "notmuch", "oauth-lib 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "once_cell", @@ -2069,7 +2069,7 @@ dependencies = [ "keyring-lib", "log", "md5", - "mml-lib 1.0.1", + "mml-lib", "oauth-lib 0.1.0", "once_cell", "process-lib", @@ -2687,23 +2687,6 @@ dependencies = [ [[package]] name = "mml-lib" version = "1.0.1" -dependencies = [ - "async-recursion", - "chumsky", - "log", - "mail-builder", - "mail-parser", - "nanohtml2text", - "shellexpand-utils 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "thiserror", - "tree_magic_mini", -] - -[[package]] -name = "mml-lib" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "915efb96feb76c123001341d1631dc06c9bbe14c1a249ef709cf84b341eb8295" dependencies = [ "async-recursion", "chumsky", diff --git a/Cargo.toml b/Cargo.toml index e8f25e9..2f7eea1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,9 +25,9 @@ imap-backend = ["email-lib/imap-backend"] notmuch-backend = ["email-lib/notmuch-backend"] smtp-sender = ["email-lib/smtp-sender"] pgp = [] -pgp-commands = ["pgp", "email-lib/pgp-commands"] -pgp-gpg = ["pgp", "email-lib/pgp-gpg"] -pgp-native = ["pgp", "email-lib/pgp-native"] +pgp-commands = ["pgp", "mml-lib/pgp-commands", "email-lib/pgp-commands"] +pgp-gpg = ["pgp", "mml-lib/pgp-gpg", "email-lib/pgp-gpg"] +pgp-native = ["pgp", "mml-lib/pgp-native", "email-lib/pgp-native"] # dev dependencies @@ -107,6 +107,8 @@ version = "=0.1.0" [dependencies.mml-lib] # version = "=1.0.1" +default-features = false +features = ["compiler", "interpreter"] path = "/home/soywod/sourcehut/pimalaya/mml" [dependencies.secret-lib] diff --git a/LICENSE b/LICENSE index 113587b..90fc14c 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2022 soywod +Copyright (c) 2022-2023 soywod Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/src/backend.rs b/src/backend.rs index b907263..e99f5bb 100644 --- a/src/backend.rs +++ b/src/backend.rs @@ -162,13 +162,21 @@ impl BackendBuilder { .map(|mdir_config| MaildirSessionBuilder::new(account_config.clone(), mdir_config)), #[cfg(feature = "imap-backend")] - imap: toml_account_config - .imap - .as_ref() - .filter(|_| is_imap_used) - .map(|imap_config| { - ImapSessionBuilder::new(account_config.clone(), imap_config.clone()) - }), + imap: { + let ctx_builder = toml_account_config + .imap + .as_ref() + .filter(|_| is_imap_used) + .map(|imap_config| { + ImapSessionBuilder::new(account_config.clone(), imap_config.clone()) + .with_prebuilt_credentials() + }); + + match ctx_builder { + Some(ctx_builder) => Some(ctx_builder.await?), + None => None, + } + }, #[cfg(feature = "notmuch-backend")] notmuch: toml_account_config .notmuch diff --git a/src/config/prelude.rs b/src/config/prelude.rs index 0b24daa..f61982b 100644 --- a/src/config/prelude.rs +++ b/src/config/prelude.rs @@ -537,10 +537,33 @@ pub enum FolderSyncStrategyDef { #[cfg(feature = "pgp")] #[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)] +#[serde(remote = "Option", from = "OptionPgpConfig")] +pub struct OptionPgpConfigDef; + +#[cfg(feature = "pgp")] +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct OptionPgpConfig { + #[serde(default, skip)] + is_none: bool, + #[serde(flatten, with = "PgpConfigDef")] + inner: PgpConfig, +} + +#[cfg(feature = "pgp")] +impl From for Option { + fn from(config: OptionPgpConfig) -> Option { + if config.is_none { + None + } else { + Some(config.inner) + } + } +} + +#[cfg(feature = "pgp")] +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] #[serde(remote = "PgpConfig", tag = "backend", rename_all = "kebab-case")] pub enum PgpConfigDef { - #[default] - None, #[cfg(feature = "pgp-commands")] #[serde(with = "CmdsPgpConfigDef", alias = "commands")] Cmds(CmdsPgpConfig), diff --git a/src/domain/tpl/handlers.rs b/src/domain/tpl/handlers.rs index f59b2f7..b036370 100644 --- a/src/domain/tpl/handlers.rs +++ b/src/domain/tpl/handlers.rs @@ -77,10 +77,11 @@ pub async fn save( .join("\n") }; - let compiler = MmlCompilerBuilder::new(); + #[allow(unused_mut)] + let mut compiler = MmlCompilerBuilder::new(); #[cfg(feature = "pgp")] - let compiler = compiler.with_pgp(config.pgp.clone()); + compiler.set_some_pgp(config.pgp.clone()); let email = compiler.build(tpl.as_str())?.compile().await?.into_vec()?; @@ -108,10 +109,11 @@ pub async fn send( .join("\n") }; - let compiler = MmlCompilerBuilder::new(); + #[allow(unused_mut)] + let mut compiler = MmlCompilerBuilder::new(); #[cfg(feature = "pgp")] - let compiler = compiler.with_pgp(config.pgp.clone()); + compiler.set_some_pgp(config.pgp.clone()); let email = compiler.build(tpl.as_str())?.compile().await?.into_vec()?; diff --git a/src/ui/editor.rs b/src/ui/editor.rs index 34eb59d..b65f461 100644 --- a/src/ui/editor.rs +++ b/src/ui/editor.rs @@ -77,10 +77,11 @@ pub async fn edit_tpl_with_editor( Ok(PostEditChoice::Send) => { printer.print_log("Sending email…")?; - let compiler = MmlCompilerBuilder::new(); + #[allow(unused_mut)] + let mut compiler = MmlCompilerBuilder::new(); #[cfg(feature = "pgp")] - let compiler = compiler.with_pgp(config.pgp.clone()); + compiler.set_some_pgp(config.pgp.clone()); let email = compiler.build(tpl.as_str())?.compile().await?.into_vec()?; @@ -107,10 +108,11 @@ pub async fn edit_tpl_with_editor( break; } Ok(PostEditChoice::RemoteDraft) => { - let compiler = MmlCompilerBuilder::new(); + #[allow(unused_mut)] + let mut compiler = MmlCompilerBuilder::new(); #[cfg(feature = "pgp")] - let compiler = compiler.with_pgp(config.pgp.clone()); + compiler.set_some_pgp(config.pgp.clone()); let email = compiler.build(tpl.as_str())?.compile().await?.into_vec()?;