mirror of
https://github.com/soywod/himalaya.git
synced 2024-07-05 17:15:12 +00:00
improve oauth2 config reset
This commit is contained in:
parent
5749bc3a82
commit
728f2555d7
|
@ -4,10 +4,10 @@
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
|
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
|
||||||
use log::{info, trace};
|
use log::{info, trace, warn};
|
||||||
use pimalaya_email::{
|
use pimalaya_email::{
|
||||||
folder::sync::Strategy as SyncFoldersStrategy, AccountConfig, Backend, BackendConfig,
|
folder::sync::Strategy as SyncFoldersStrategy, AccountConfig, Backend, BackendConfig,
|
||||||
BackendSyncBuilder, BackendSyncProgressEvent,
|
BackendSyncBuilder, BackendSyncProgressEvent, EmailSender,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -17,20 +17,45 @@ use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Configure the current selected account
|
/// Configure the current selected account
|
||||||
pub fn configure(backend_config: &BackendConfig, reset: bool) -> Result<()> {
|
pub fn configure(
|
||||||
|
account_config: &AccountConfig,
|
||||||
|
backend_config: &BackendConfig,
|
||||||
|
reset: bool,
|
||||||
|
) -> Result<()> {
|
||||||
info!("entering the configure account handler");
|
info!("entering the configure account handler");
|
||||||
match backend_config {
|
|
||||||
BackendConfig::None => (),
|
if reset {
|
||||||
BackendConfig::Maildir(_) => (),
|
|
||||||
#[cfg(feature = "imap-backend")]
|
#[cfg(feature = "imap-backend")]
|
||||||
BackendConfig::Imap(imap_config) => {
|
if let BackendConfig::Imap(imap_config) = backend_config {
|
||||||
imap_config
|
println!("Resetting IMAP secrets…");
|
||||||
.auth
|
if let Err(err) = imap_config.auth.reset() {
|
||||||
.configure(reset, configure_oauth2_client_secret)?;
|
warn!("error while resetting imap secrets, skipping it");
|
||||||
|
warn!("{err}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#[cfg(feature = "notmuch-backend")]
|
|
||||||
BackendConfig::Notmuch(config) => (),
|
#[cfg(feature = "smtp-sender")]
|
||||||
};
|
if let EmailSender::Smtp(smtp_config) = &account_config.email_sender {
|
||||||
|
println!("Resetting SMTP secrets…");
|
||||||
|
if let Err(err) = smtp_config.auth.reset() {
|
||||||
|
warn!("error while resetting smtp secrets, skipping it");
|
||||||
|
warn!("{err}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "imap-backend")]
|
||||||
|
if let BackendConfig::Imap(imap_config) = backend_config {
|
||||||
|
println!("Configuring IMAP secrets…");
|
||||||
|
imap_config.auth.configure(configure_oauth2_client_secret)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "smtp-sender")]
|
||||||
|
if let EmailSender::Smtp(smtp_config) = &account_config.email_sender {
|
||||||
|
println!("Configuring SMTP secrets…");
|
||||||
|
smtp_config.auth.configure(configure_oauth2_client_secret)?;
|
||||||
|
}
|
||||||
|
|
||||||
println!("Account successfully configured!");
|
println!("Account successfully configured!");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,7 +138,7 @@ fn main() -> Result<()> {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
Some(account::args::Cmd::Configure(reset)) => {
|
Some(account::args::Cmd::Configure(reset)) => {
|
||||||
return account::handlers::configure(&backend_config, reset);
|
return account::handlers::configure(&account_config, &backend_config, reset);
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue