fix imap credentials and pgp

This commit is contained in:
Clément DOUIN 2023-12-03 13:03:36 +01:00
parent a5cacb3f67
commit f24a0475cc
No known key found for this signature in database
GPG key ID: 353E4A18EE0FAB72
7 changed files with 60 additions and 40 deletions

21
Cargo.lock generated
View file

@ -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",

View file

@ -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]

View file

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2022 soywod <clement.douin@posteo.net>
Copyright (c) 2022-2023 soywod <clement.douin@posteo.net>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View file

@ -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

View file

@ -537,10 +537,33 @@ pub enum FolderSyncStrategyDef {
#[cfg(feature = "pgp")]
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
#[serde(remote = "Option<PgpConfig>", 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<OptionPgpConfig> for Option<PgpConfig> {
fn from(config: OptionPgpConfig) -> Option<PgpConfig> {
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),

View file

@ -77,10 +77,11 @@ pub async fn save<P: Printer>(
.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<P: Printer>(
.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()?;

View file

@ -77,10 +77,11 @@ pub async fn edit_tpl_with_editor<P: Printer>(
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<P: Printer>(
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()?;