mirror of
https://github.com/soywod/himalaya.git
synced 2024-11-22 02:50:19 +00:00
fix smtp default config, fix cargo imports
This commit is contained in:
parent
b478c545ad
commit
5d21433816
4 changed files with 132 additions and 44 deletions
5
Cargo.lock
generated
5
Cargo.lock
generated
|
@ -2101,6 +2101,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "pimalaya-email"
|
||||
version = "0.7.1"
|
||||
source = "git+https://git.sr.ht/~soywod/pimalaya#5474a733194623c74665c8d37066974cf3fe4477"
|
||||
dependencies = [
|
||||
"ammonia",
|
||||
"chrono",
|
||||
|
@ -2141,6 +2142,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "pimalaya-keyring"
|
||||
version = "0.0.1"
|
||||
source = "git+https://git.sr.ht/~soywod/pimalaya#5474a733194623c74665c8d37066974cf3fe4477"
|
||||
dependencies = [
|
||||
"keyring",
|
||||
"log",
|
||||
|
@ -2150,6 +2152,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "pimalaya-oauth2"
|
||||
version = "0.0.1"
|
||||
source = "git+https://git.sr.ht/~soywod/pimalaya#5474a733194623c74665c8d37066974cf3fe4477"
|
||||
dependencies = [
|
||||
"log",
|
||||
"oauth2",
|
||||
|
@ -2161,6 +2164,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "pimalaya-process"
|
||||
version = "0.0.1"
|
||||
source = "git+https://git.sr.ht/~soywod/pimalaya#5474a733194623c74665c8d37066974cf3fe4477"
|
||||
dependencies = [
|
||||
"log",
|
||||
"thiserror",
|
||||
|
@ -2169,6 +2173,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "pimalaya-secret"
|
||||
version = "0.0.1"
|
||||
source = "git+https://git.sr.ht/~soywod/pimalaya#5474a733194623c74665c8d37066974cf3fe4477"
|
||||
dependencies = [
|
||||
"log",
|
||||
"pimalaya-keyring",
|
||||
|
|
|
@ -51,11 +51,10 @@ erased-serde = "0.3"
|
|||
indicatif = "0.17"
|
||||
log = "0.4"
|
||||
once_cell = "1.16.0"
|
||||
# pimalaya-email = { git = "https://git.sr.ht/~soywod/pimalaya" }
|
||||
pimalaya-email = { path = "/home/soywod/sourcehut/pimalaya/email" }
|
||||
pimalaya-keyring = { path = "/home/soywod/sourcehut/pimalaya/keyring" }
|
||||
pimalaya-process = { path = "/home/soywod/sourcehut/pimalaya/process" }
|
||||
pimalaya-secret = { path = "/home/soywod/sourcehut/pimalaya/secret" }
|
||||
pimalaya-email = { git = "https://git.sr.ht/~soywod/pimalaya" }
|
||||
pimalaya-keyring = { 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"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use pimalaya_email::{
|
||||
folder::sync::Strategy as SyncFoldersStrategy, EmailHooks, EmailSender, EmailTextPlainFormat,
|
||||
ImapAuthConfig, MaildirConfig, OAuth2Config, OAuth2Method, OAuth2Scopes, SendmailConfig,
|
||||
SmtpConfig,
|
||||
SmtpAuthConfig, SmtpConfig,
|
||||
};
|
||||
use pimalaya_keyring::Entry;
|
||||
use pimalaya_process::Cmd;
|
||||
|
@ -23,7 +23,16 @@ pub struct CmdDef;
|
|||
#[serde(remote = "Entry", from = "String")]
|
||||
pub struct EntryDef;
|
||||
|
||||
#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(remote = "OAuth2Method")]
|
||||
pub enum OAuth2MethodDef {
|
||||
#[serde(rename = "xoauth2", alias = "XOAUTH2")]
|
||||
XOAuth2,
|
||||
#[serde(rename = "oauthbearer", alias = "OAUTHBEARER")]
|
||||
OAuthBearer,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(remote = "SmtpConfig")]
|
||||
struct SmtpConfigDef {
|
||||
#[serde(rename = "smtp-host")]
|
||||
|
@ -38,12 +47,97 @@ struct SmtpConfigDef {
|
|||
pub insecure: Option<bool>,
|
||||
#[serde(rename = "smtp-login")]
|
||||
pub login: String,
|
||||
#[serde(rename = "smtp-passwd-cmd")]
|
||||
pub passwd_cmd: String,
|
||||
#[serde(flatten, with = "SmtpAuthConfigDef")]
|
||||
pub auth: SmtpAuthConfig,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(remote = "SmtpAuthConfig", tag = "smtp-auth")]
|
||||
pub enum SmtpAuthConfigDef {
|
||||
#[serde(rename = "passwd", alias = "password", with = "SmtpPasswdDef")]
|
||||
Passwd(Secret),
|
||||
#[serde(rename = "oauth2", with = "SmtpOAuth2ConfigDef")]
|
||||
OAuth2(OAuth2Config),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(remote = "Secret", rename_all = "kebab-case")]
|
||||
pub enum SmtpPasswdDef {
|
||||
#[serde(rename = "smtp-passwd")]
|
||||
Raw(String),
|
||||
#[serde(rename = "smtp-passwd-cmd", with = "CmdDef")]
|
||||
Cmd(Cmd),
|
||||
#[serde(rename = "smtp-passwd-keyring", with = "EntryDef")]
|
||||
Keyring(Entry),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(remote = "OAuth2Config")]
|
||||
pub struct SmtpOAuth2ConfigDef {
|
||||
#[serde(rename = "smtp-oauth2-method", with = "OAuth2MethodDef")]
|
||||
pub method: OAuth2Method,
|
||||
#[serde(rename = "smtp-oauth2-client-id")]
|
||||
pub client_id: String,
|
||||
#[serde(flatten, with = "SmtpOAuth2ClientSecretDef")]
|
||||
pub client_secret: Secret,
|
||||
#[serde(rename = "smtp-oauth2-auth-url")]
|
||||
pub auth_url: String,
|
||||
#[serde(rename = "smtp-oauth2-token-url")]
|
||||
pub token_url: String,
|
||||
#[serde(flatten, with = "SmtpOAuth2AccessTokenDef")]
|
||||
pub access_token: Secret,
|
||||
#[serde(flatten, with = "SmtpOAuth2RefreshTokenDef")]
|
||||
pub refresh_token: Secret,
|
||||
#[serde(flatten, with = "SmtpOAuth2ScopesDef")]
|
||||
pub scopes: OAuth2Scopes,
|
||||
#[serde(rename = "smtp-oauth2-pkce", default)]
|
||||
pub pkce: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(remote = "Secret")]
|
||||
pub enum SmtpOAuth2ClientSecretDef {
|
||||
#[serde(rename = "smtp-oauth2-client-secret")]
|
||||
Raw(String),
|
||||
#[serde(rename = "smtp-oauth2-client-secret-cmd", with = "CmdDef")]
|
||||
Cmd(Cmd),
|
||||
#[serde(rename = "smtp-oauth2-client-secret-keyring", with = "EntryDef")]
|
||||
Keyring(Entry),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(remote = "Secret")]
|
||||
pub enum SmtpOAuth2AccessTokenDef {
|
||||
#[serde(rename = "smtp-oauth2-access-token")]
|
||||
Raw(String),
|
||||
#[serde(rename = "smtp-oauth2-access-token-cmd", with = "CmdDef")]
|
||||
Cmd(Cmd),
|
||||
#[serde(rename = "smtp-oauth2-access-token-keyring", with = "EntryDef")]
|
||||
Keyring(Entry),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(remote = "Secret")]
|
||||
pub enum SmtpOAuth2RefreshTokenDef {
|
||||
#[serde(rename = "smtp-oauth2-refresh-token")]
|
||||
Raw(String),
|
||||
#[serde(rename = "smtp-oauth2-refresh-token-cmd", with = "CmdDef")]
|
||||
Cmd(Cmd),
|
||||
#[serde(rename = "smtp-oauth2-refresh-token-keyring", with = "EntryDef")]
|
||||
Keyring(Entry),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(remote = "OAuth2Scopes")]
|
||||
pub enum SmtpOAuth2ScopesDef {
|
||||
#[serde(rename = "smtp-oauth2-scope")]
|
||||
Scope(String),
|
||||
#[serde(rename = "smtp-oauth2-scopes")]
|
||||
Scopes(Vec<String>),
|
||||
}
|
||||
|
||||
#[cfg(feature = "imap-backend")]
|
||||
#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(remote = "ImapConfig")]
|
||||
pub struct ImapConfigDef {
|
||||
#[serde(rename = "imap-host")]
|
||||
|
@ -69,19 +163,17 @@ pub struct ImapConfigDef {
|
|||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(remote = "ImapAuthConfig", tag = "imap-auth", rename_all = "lowercase")]
|
||||
#[serde(remote = "ImapAuthConfig", tag = "imap-auth")]
|
||||
pub enum ImapAuthConfigDef {
|
||||
#[serde(skip)]
|
||||
None,
|
||||
#[serde(with = "PasswdDef")]
|
||||
#[serde(rename = "passwd", alias = "password", with = "ImapPasswdDef")]
|
||||
Passwd(Secret),
|
||||
#[serde(with = "OAuth2ConfigDef")]
|
||||
#[serde(rename = "oauth2", with = "ImapOAuth2ConfigDef")]
|
||||
OAuth2(OAuth2Config),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(remote = "Secret", rename_all = "kebab-case")]
|
||||
pub enum PasswdDef {
|
||||
pub enum ImapPasswdDef {
|
||||
#[serde(rename = "imap-passwd")]
|
||||
Raw(String),
|
||||
#[serde(rename = "imap-passwd-cmd", with = "CmdDef")]
|
||||
|
@ -91,31 +183,31 @@ pub enum PasswdDef {
|
|||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(remote = "OAuth2Config", rename_all = "kebab-case")]
|
||||
pub struct OAuth2ConfigDef {
|
||||
#[serde(remote = "OAuth2Config")]
|
||||
pub struct ImapOAuth2ConfigDef {
|
||||
#[serde(rename = "imap-oauth2-method", with = "OAuth2MethodDef")]
|
||||
pub method: OAuth2Method,
|
||||
#[serde(rename = "imap-oauth2-client-id")]
|
||||
pub client_id: String,
|
||||
#[serde(flatten, with = "ClientSecretDef")]
|
||||
#[serde(flatten, with = "ImapOAuth2ClientSecretDef")]
|
||||
pub client_secret: Secret,
|
||||
#[serde(rename = "imap-oauth2-auth-url")]
|
||||
pub auth_url: String,
|
||||
#[serde(rename = "imap-oauth2-token-url")]
|
||||
pub token_url: String,
|
||||
#[serde(flatten, with = "AccessTokenDef")]
|
||||
#[serde(flatten, with = "ImapOAuth2AccessTokenDef")]
|
||||
pub access_token: Secret,
|
||||
#[serde(flatten, with = "RefreshTokenDef")]
|
||||
#[serde(flatten, with = "ImapOAuth2RefreshTokenDef")]
|
||||
pub refresh_token: Secret,
|
||||
#[serde(flatten, with = "OAuth2ScopesDef")]
|
||||
#[serde(flatten, with = "ImapOAuth2ScopesDef")]
|
||||
pub scopes: OAuth2Scopes,
|
||||
#[serde(default)]
|
||||
#[serde(rename = "imap-oauth2-pkce", default)]
|
||||
pub pkce: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(remote = "Secret", rename_all = "kebab-case")]
|
||||
pub enum ClientSecretDef {
|
||||
#[serde(remote = "Secret")]
|
||||
pub enum ImapOAuth2ClientSecretDef {
|
||||
#[serde(rename = "imap-oauth2-client-secret")]
|
||||
Raw(String),
|
||||
#[serde(rename = "imap-oauth2-client-secret-cmd", with = "CmdDef")]
|
||||
|
@ -125,8 +217,8 @@ pub enum ClientSecretDef {
|
|||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(remote = "Secret", rename_all = "kebab-case")]
|
||||
pub enum AccessTokenDef {
|
||||
#[serde(remote = "Secret")]
|
||||
pub enum ImapOAuth2AccessTokenDef {
|
||||
#[serde(rename = "imap-oauth2-access-token")]
|
||||
Raw(String),
|
||||
#[serde(rename = "imap-oauth2-access-token-cmd", with = "CmdDef")]
|
||||
|
@ -136,8 +228,8 @@ pub enum AccessTokenDef {
|
|||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(remote = "Secret", rename_all = "kebab-case")]
|
||||
pub enum RefreshTokenDef {
|
||||
#[serde(remote = "Secret")]
|
||||
pub enum ImapOAuth2RefreshTokenDef {
|
||||
#[serde(rename = "imap-oauth2-refresh-token")]
|
||||
Raw(String),
|
||||
#[serde(rename = "imap-oauth2-refresh-token-cmd", with = "CmdDef")]
|
||||
|
@ -147,17 +239,8 @@ pub enum RefreshTokenDef {
|
|||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(remote = "OAuth2Method")]
|
||||
pub enum OAuth2MethodDef {
|
||||
#[serde(rename = "xoauth2", alias = "XOAUTH2")]
|
||||
XOAuth2,
|
||||
#[serde(rename = "oauthbearer", alias = "OAUTHBEARER")]
|
||||
OAuthBearer,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(remote = "OAuth2Scopes", rename_all = "kebab-case")]
|
||||
pub enum OAuth2ScopesDef {
|
||||
#[serde(remote = "OAuth2Scopes")]
|
||||
pub enum ImapOAuth2ScopesDef {
|
||||
#[serde(rename = "imap-oauth2-scope")]
|
||||
Scope(String),
|
||||
#[serde(rename = "imap-oauth2-scopes")]
|
||||
|
|
|
@ -42,10 +42,11 @@ pub(crate) fn configure(base: &DeserializedBaseAccountConfig) -> Result<EmailSen
|
|||
.default(base.email.clone())
|
||||
.interact()?;
|
||||
|
||||
smtp_config.passwd_cmd = Input::with_theme(&*THEME)
|
||||
.with_prompt("What shell command should we run to get your password?")
|
||||
.default(format!("pass show {}", &base.email))
|
||||
.interact()?;
|
||||
// FIXME: add all variants: password, password command and oauth2
|
||||
// smtp_config.auth = Input::with_theme(&*THEME)
|
||||
// .with_prompt("What shell command should we run to get your password?")
|
||||
// .default(format!("pass show {}", &base.email))
|
||||
// .interact()?;
|
||||
|
||||
Ok(EmailSender::Smtp(smtp_config))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue