plug autoconfig to imap and smtp wizards

This commit is contained in:
Clément DOUIN
2024-01-09 21:36:17 +01:00
parent b0d7e773dc
commit 6f9f75cfd2
4 changed files with 550 additions and 343 deletions
+20
View File
@@ -1,5 +1,8 @@
use anyhow::Result;
use autoconfig::config::Config as AutoConfig;
use dialoguer::Select;
use log::{debug, warn};
use std::sync::OnceLock;
#[cfg(feature = "imap")]
use crate::imap;
@@ -31,6 +34,23 @@ const SEND_MESSAGE_BACKEND_KINDS: &[BackendKind] = &[
BackendKind::Sendmail,
];
static AUTOCONFIG: OnceLock<AutoConfig> = OnceLock::new();
#[cfg(any(feature = "imap", feature = "smtp"))]
pub(crate) async fn get_or_init_autoconfig(email: &str) -> Option<&AutoConfig> {
match AUTOCONFIG.get() {
Some(autoconfig) => Some(autoconfig),
None => match autoconfig::from_addr(email).await {
Ok(autoconfig) => Some(AUTOCONFIG.get_or_init(|| autoconfig)),
Err(err) => {
warn!("cannot discover SMTP configuration from {email}: {err}");
debug!("{err:?}");
None
}
},
}
}
pub(crate) async fn configure(
#[allow(unused)] account_name: &str,
#[allow(unused)] email: &str,