mirror of
https://github.com/chatmail/core.git
synced 2026-05-02 04:46:29 +03:00
refactor: Move proxy_config out of ConfiguredLoginParam (#6712)
We want to store ConfiguredLoginParam in the database as Json per-login, but proxy_config should be global for all logins.
This commit is contained in:
@@ -432,7 +432,6 @@ async fn get_configured_param(
|
|||||||
.collect(),
|
.collect(),
|
||||||
smtp_user: param.smtp.user.clone(),
|
smtp_user: param.smtp.user.clone(),
|
||||||
smtp_password,
|
smtp_password,
|
||||||
proxy_config: ProxyConfig::load(ctx).await?,
|
|
||||||
provider,
|
provider,
|
||||||
certificate_checks: match param.certificate_checks {
|
certificate_checks: match param.certificate_checks {
|
||||||
EnteredCertificateChecks::Automatic => ConfiguredCertificateChecks::Automatic,
|
EnteredCertificateChecks::Automatic => ConfiguredCertificateChecks::Automatic,
|
||||||
@@ -454,7 +453,8 @@ async fn configure(ctx: &Context, param: &EnteredLoginParam) -> Result<Configure
|
|||||||
let update_device_chats_handle = task::spawn(async move { ctx2.update_device_chats().await });
|
let update_device_chats_handle = task::spawn(async move { ctx2.update_device_chats().await });
|
||||||
|
|
||||||
let configured_param = get_configured_param(ctx, param).await?;
|
let configured_param = get_configured_param(ctx, param).await?;
|
||||||
let strict_tls = configured_param.strict_tls();
|
let proxy_config = ProxyConfig::load(ctx).await?;
|
||||||
|
let strict_tls = configured_param.strict_tls(proxy_config.is_some());
|
||||||
|
|
||||||
progress!(ctx, 550);
|
progress!(ctx, 550);
|
||||||
|
|
||||||
@@ -464,15 +464,15 @@ async fn configure(ctx: &Context, param: &EnteredLoginParam) -> Result<Configure
|
|||||||
let smtp_param = configured_param.smtp.clone();
|
let smtp_param = configured_param.smtp.clone();
|
||||||
let smtp_password = configured_param.smtp_password.clone();
|
let smtp_password = configured_param.smtp_password.clone();
|
||||||
let smtp_addr = configured_param.addr.clone();
|
let smtp_addr = configured_param.addr.clone();
|
||||||
let proxy_config = configured_param.proxy_config.clone();
|
|
||||||
|
|
||||||
|
let proxy_config2 = proxy_config.clone();
|
||||||
let smtp_config_task = task::spawn(async move {
|
let smtp_config_task = task::spawn(async move {
|
||||||
let mut smtp = Smtp::new();
|
let mut smtp = Smtp::new();
|
||||||
smtp.connect(
|
smtp.connect(
|
||||||
&context_smtp,
|
&context_smtp,
|
||||||
&smtp_param,
|
&smtp_param,
|
||||||
&smtp_password,
|
&smtp_password,
|
||||||
&proxy_config,
|
&proxy_config2,
|
||||||
&smtp_addr,
|
&smtp_addr,
|
||||||
strict_tls,
|
strict_tls,
|
||||||
configured_param.oauth2,
|
configured_param.oauth2,
|
||||||
@@ -490,7 +490,7 @@ async fn configure(ctx: &Context, param: &EnteredLoginParam) -> Result<Configure
|
|||||||
let mut imap = Imap::new(
|
let mut imap = Imap::new(
|
||||||
configured_param.imap.clone(),
|
configured_param.imap.clone(),
|
||||||
configured_param.imap_password.clone(),
|
configured_param.imap_password.clone(),
|
||||||
configured_param.proxy_config.clone(),
|
proxy_config,
|
||||||
&configured_param.addr,
|
&configured_param.addr,
|
||||||
strict_tls,
|
strict_tls,
|
||||||
configured_param.oauth2,
|
configured_param.oauth2,
|
||||||
|
|||||||
@@ -271,12 +271,14 @@ impl Imap {
|
|||||||
let param = ConfiguredLoginParam::load(context)
|
let param = ConfiguredLoginParam::load(context)
|
||||||
.await?
|
.await?
|
||||||
.context("Not configured")?;
|
.context("Not configured")?;
|
||||||
|
let proxy_config = ProxyConfig::load(context).await?;
|
||||||
|
let strict_tls = param.strict_tls(proxy_config.is_some());
|
||||||
let imap = Self::new(
|
let imap = Self::new(
|
||||||
param.imap.clone(),
|
param.imap.clone(),
|
||||||
param.imap_password.clone(),
|
param.imap_password.clone(),
|
||||||
param.proxy_config.clone(),
|
proxy_config,
|
||||||
¶m.addr,
|
¶m.addr,
|
||||||
param.strict_tls(),
|
strict_tls,
|
||||||
param.oauth2,
|
param.oauth2,
|
||||||
idle_interrupt_receiver,
|
idle_interrupt_receiver,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -441,9 +441,6 @@ pub(crate) struct ConfiguredLoginParam {
|
|||||||
|
|
||||||
pub smtp_password: String,
|
pub smtp_password: String,
|
||||||
|
|
||||||
/// Proxy configuration.
|
|
||||||
pub proxy_config: Option<ProxyConfig>,
|
|
||||||
|
|
||||||
pub provider: Option<&'static Provider>,
|
pub provider: Option<&'static Provider>,
|
||||||
|
|
||||||
/// TLS options: whether to allow invalid certificates and/or
|
/// TLS options: whether to allow invalid certificates and/or
|
||||||
@@ -742,8 +739,6 @@ impl ConfiguredLoginParam {
|
|||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
let proxy_config = ProxyConfig::load(context).await?;
|
|
||||||
|
|
||||||
Ok(Some(ConfiguredLoginParam {
|
Ok(Some(ConfiguredLoginParam {
|
||||||
addr,
|
addr,
|
||||||
imap,
|
imap,
|
||||||
@@ -754,7 +749,6 @@ impl ConfiguredLoginParam {
|
|||||||
smtp_password: send_pw,
|
smtp_password: send_pw,
|
||||||
certificate_checks,
|
certificate_checks,
|
||||||
provider,
|
provider,
|
||||||
proxy_config,
|
|
||||||
oauth2,
|
oauth2,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
@@ -837,11 +831,11 @@ impl ConfiguredLoginParam {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn strict_tls(&self) -> bool {
|
pub(crate) fn strict_tls(&self, connected_through_proxy: bool) -> bool {
|
||||||
let provider_strict_tls = self.provider.map(|provider| provider.opt.strict_tls);
|
let provider_strict_tls = self.provider.map(|provider| provider.opt.strict_tls);
|
||||||
match self.certificate_checks {
|
match self.certificate_checks {
|
||||||
ConfiguredCertificateChecks::OldAutomatic => {
|
ConfiguredCertificateChecks::OldAutomatic => {
|
||||||
provider_strict_tls.unwrap_or(self.proxy_config.is_some())
|
provider_strict_tls.unwrap_or(connected_through_proxy)
|
||||||
}
|
}
|
||||||
ConfiguredCertificateChecks::Automatic => provider_strict_tls.unwrap_or(true),
|
ConfiguredCertificateChecks::Automatic => provider_strict_tls.unwrap_or(true),
|
||||||
ConfiguredCertificateChecks::Strict => true,
|
ConfiguredCertificateChecks::Strict => true,
|
||||||
@@ -962,8 +956,6 @@ mod tests {
|
|||||||
}],
|
}],
|
||||||
smtp_user: "".to_string(),
|
smtp_user: "".to_string(),
|
||||||
smtp_password: "bar".to_string(),
|
smtp_password: "bar".to_string(),
|
||||||
// proxy_config is not saved by `save_to_database`, using default value
|
|
||||||
proxy_config: None,
|
|
||||||
provider: None,
|
provider: None,
|
||||||
certificate_checks: ConfiguredCertificateChecks::Strict,
|
certificate_checks: ConfiguredCertificateChecks::Strict,
|
||||||
oauth2: false,
|
oauth2: false,
|
||||||
@@ -1066,7 +1058,6 @@ mod tests {
|
|||||||
],
|
],
|
||||||
smtp_user: "alice@posteo.de".to_string(),
|
smtp_user: "alice@posteo.de".to_string(),
|
||||||
smtp_password: "foobarbaz".to_string(),
|
smtp_password: "foobarbaz".to_string(),
|
||||||
proxy_config: None,
|
|
||||||
provider: get_provider_by_id("posteo"),
|
provider: get_provider_by_id("posteo"),
|
||||||
certificate_checks: ConfiguredCertificateChecks::Strict,
|
certificate_checks: ConfiguredCertificateChecks::Strict,
|
||||||
oauth2: false,
|
oauth2: false,
|
||||||
|
|||||||
@@ -90,13 +90,14 @@ impl Smtp {
|
|||||||
let lp = ConfiguredLoginParam::load(context)
|
let lp = ConfiguredLoginParam::load(context)
|
||||||
.await?
|
.await?
|
||||||
.context("Not configured")?;
|
.context("Not configured")?;
|
||||||
|
let proxy_config = ProxyConfig::load(context).await?;
|
||||||
self.connect(
|
self.connect(
|
||||||
context,
|
context,
|
||||||
&lp.smtp,
|
&lp.smtp,
|
||||||
&lp.smtp_password,
|
&lp.smtp_password,
|
||||||
&lp.proxy_config,
|
&proxy_config,
|
||||||
&lp.addr,
|
&lp.addr,
|
||||||
lp.strict_tls(),
|
lp.strict_tls(proxy_config.is_some()),
|
||||||
lp.oauth2,
|
lp.oauth2,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
|||||||
Reference in New Issue
Block a user