Skip to content

Commit

Permalink
add pgp support
Browse files Browse the repository at this point in the history
  • Loading branch information
soywod committed Aug 2, 2023
1 parent 183aa2f commit 99ec7c6
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 98 deletions.
103 changes: 70 additions & 33 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "himalaya"
description = "CLI to manage your emails."
version = "0.8.4-beta"
version = "0.9.0-beta"
authors = ["soywod <clement.douin@posteo.net>"]
edition = "2021"
license = "MIT"
Expand Down Expand Up @@ -46,10 +46,10 @@ log = "0.4"
md5 = "0.7.0"
once_cell = "1.16.0"
pimalaya-email = { git = "https://git.sr.ht/~soywod/pimalaya", default-features = false }
pimalaya-keyring = "=0.0.5"
pimalaya-oauth2 = "=0.0.4"
pimalaya-process = "=0.0.5"
pimalaya-secret = "=0.0.5"
pimalaya-keyring = { git = "https://git.sr.ht/~soywod/pimalaya" }
pimalaya-oauth2 = { git = "https://git.sr.ht/~soywod/pimalaya" }
pimalaya-process = { git = "https://git.sr.ht/~soywod/pimalaya" }
pimalaya-secret = { git = "https://git.sr.ht/~soywod/pimalaya" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
shellexpand = "2.1"
Expand Down
38 changes: 37 additions & 1 deletion src/config/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use pimalaya_email::backend::{ImapAuthConfig, ImapConfig};
#[cfg(feature = "smtp-sender")]
use pimalaya_email::sender::{SmtpAuthConfig, SmtpConfig};
use pimalaya_email::{
account::{OAuth2Config, OAuth2Method, OAuth2Scopes, PasswdConfig},
account::{
OAuth2Config, OAuth2Method, OAuth2Scopes, PasswdConfig, PgpConfig, PgpKey, PgpNativeConfig,
},
backend::{BackendConfig, MaildirConfig},
email::{EmailHooks, EmailTextPlainFormat},
folder::sync::FolderSyncStrategy,
Expand Down Expand Up @@ -387,3 +389,37 @@ pub enum FolderSyncStrategyDef {
#[serde(alias = "ignore")]
Exclude(HashSet<String>),
}

#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
#[serde(remote = "PgpConfig", tag = "backend", rename_all = "kebab-case")]
pub enum PgpConfigDef {
#[default]
None,
#[serde(with = "PgpNativeConfigDef")]
Native(PgpNativeConfig),
}

#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
#[serde(remote = "PgpNativeConfig", rename_all = "kebab-case")]
pub struct PgpNativeConfigDef {
#[serde(default, with = "PgpKeyDef")]
secret_key: PgpKey,
#[serde(default, with = "SecretDef")]
secret_key_passwd: Secret,
#[serde(default, with = "PgpKeyDef")]
public_key: PgpKey,
#[serde(default = "PgpNativeConfig::default_wkd")]
wkd: bool,
#[serde(default = "PgpNativeConfig::default_key_servers")]
key_servers: Vec<String>,
}

#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
#[serde(remote = "PgpKey", rename_all = "kebab-case")]
pub enum PgpKeyDef {
#[default]
None,
Path(PathBuf),
#[serde(with = "EntryDef")]
Keyring(Entry),
}
47 changes: 5 additions & 42 deletions src/domain/account/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use pimalaya_email::backend::ImapAuthConfig;
#[cfg(feature = "smtp-sender")]
use pimalaya_email::sender::SmtpAuthConfig;
use pimalaya_email::{
account::AccountConfig,
account::{AccountConfig, PgpConfig},
backend::BackendConfig,
email::{EmailHooks, EmailTextPlainFormat},
folder::sync::FolderSyncStrategy,
Expand Down Expand Up @@ -90,6 +90,9 @@ pub struct DeserializedAccountConfig {
pub backend: BackendConfig,
#[serde(flatten, with = "SenderConfigDef")]
pub sender: SenderConfig,

#[serde(default, with = "PgpConfigDef")]
pub pgp: PgpConfig,
}

impl DeserializedAccountConfig {
Expand Down Expand Up @@ -155,46 +158,6 @@ impl DeserializedAccountConfig {
.map(ToOwned::to_owned)
.or_else(|| config.email_reading_headers.as_ref().map(ToOwned::to_owned)),
email_reading_format: self.email_reading_format.clone(),
email_reading_verify_cmd: self
.email_reading_verify_cmd
.as_ref()
.map(ToOwned::to_owned)
.or_else(|| {
config
.email_reading_verify_cmd
.as_ref()
.map(ToOwned::to_owned)
}),
email_reading_decrypt_cmd: self
.email_reading_decrypt_cmd
.as_ref()
.map(ToOwned::to_owned)
.or_else(|| {
config
.email_reading_decrypt_cmd
.as_ref()
.map(ToOwned::to_owned)
}),
email_writing_sign_cmd: self
.email_writing_sign_cmd
.as_ref()
.map(ToOwned::to_owned)
.or_else(|| {
config
.email_writing_sign_cmd
.as_ref()
.map(ToOwned::to_owned)
}),
email_writing_encrypt_cmd: self
.email_writing_encrypt_cmd
.as_ref()
.map(ToOwned::to_owned)
.or_else(|| {
config
.email_writing_encrypt_cmd
.as_ref()
.map(ToOwned::to_owned)
}),
email_writing_headers: self
.email_writing_headers
.as_ref()
Expand Down Expand Up @@ -258,7 +221,7 @@ impl DeserializedAccountConfig {

sender
},
pgp: Default::default(),
pgp: self.pgp.clone(),
}
}
}
Loading

0 comments on commit 99ec7c6

Please sign in to comment.