replaced autoconfig by custom email-lib account discovery module

This commit is contained in:
Clément DOUIN
2024-01-18 11:59:27 +01:00
parent 2342a83d0d
commit 7d4ad9c1d9
6 changed files with 111 additions and 934 deletions
+16 -20
View File
@@ -1,11 +1,13 @@
use std::str::FromStr;
use anyhow::{bail, Result};
#[cfg(feature = "account-sync")]
use dialoguer::Confirm;
use dialoguer::Input;
use email::account;
#[cfg(feature = "account-sync")]
use email::account::sync::config::SyncConfig;
use email_address::EmailAddress;
use log::{debug, trace, warn};
#[allow(unused)]
use crate::backend::{self, config::BackendConfig, BackendKind};
@@ -20,11 +22,6 @@ use super::TomlAccountConfig;
pub(crate) async fn configure() -> Result<Option<(String, TomlAccountConfig)>> {
let mut config = TomlAccountConfig::default();
let account_name = Input::with_theme(&*THEME)
.with_prompt("Account name")
.default(String::from("personal"))
.interact()?;
config.email = Input::with_theme(&*THEME)
.with_prompt("Email address")
.validate_with(|email: &String| {
@@ -36,11 +33,21 @@ pub(crate) async fn configure() -> Result<Option<(String, TomlAccountConfig)>> {
})
.interact()?;
let email = &config.email;
let addr = EmailAddress::from_str(&config.email).unwrap();
let autoconfig_email = config.email.to_owned();
let autoconfig =
tokio::spawn(async move { account::discover::from_addr(&autoconfig_email).await.ok() });
let account_name = Input::with_theme(&*THEME)
.with_prompt("Account name")
.default(addr.domain().split_once('.').unwrap().0.to_owned())
.interact()?;
config.display_name = Some(
Input::with_theme(&*THEME)
.with_prompt("Full display name")
.default(addr.local_part().to_owned())
.interact()?,
);
@@ -52,19 +59,8 @@ pub(crate) async fn configure() -> Result<Option<(String, TomlAccountConfig)>> {
.into(),
);
let autoconfig = match autoconfig::from_addr(email).await {
Ok(autoconfig) => {
println!("An automatic configuration has been found for {email},");
println!("it will be used by default for the rest of the configuration.\n");
trace!("{autoconfig:#?}");
Some(autoconfig)
}
Err(err) => {
warn!("cannot discover configuration from {email}: {err}");
debug!("{err:?}");
None
}
};
let email = &config.email;
let autoconfig = autoconfig.await?;
let autoconfig = autoconfig.as_ref();
match backend::wizard::configure(&account_name, email, autoconfig).await? {
+1 -1
View File
@@ -1,6 +1,6 @@
use anyhow::Result;
use autoconfig::config::Config as AutoConfig;
use dialoguer::Select;
use email::account::discover::config::AutoConfig;
#[cfg(feature = "imap")]
use crate::imap;
+6 -4
View File
@@ -1,10 +1,12 @@
use anyhow::Result;
use autoconfig::config::{AuthenticationType, Config as AutoConfig, SecurityType, ServerType};
use dialoguer::{Confirm, Input, Password, Select};
use email::{
account::config::{
oauth2::{OAuth2Config, OAuth2Method, OAuth2Scopes},
passwd::PasswdConfig,
account::{
config::{
oauth2::{OAuth2Config, OAuth2Method, OAuth2Scopes},
passwd::PasswdConfig,
},
discover::config::{AuthenticationType, AutoConfig, SecurityType, ServerType},
},
imap::config::{ImapAuthConfig, ImapConfig, ImapEncryptionKind},
};
+6 -4
View File
@@ -1,10 +1,12 @@
use anyhow::Result;
use autoconfig::config::{AuthenticationType, Config as AutoConfig, SecurityType, ServerType};
use dialoguer::{Confirm, Input, Password, Select};
use email::{
account::config::{
oauth2::{OAuth2Config, OAuth2Method, OAuth2Scopes},
passwd::PasswdConfig,
account::{
config::{
oauth2::{OAuth2Config, OAuth2Method, OAuth2Scopes},
passwd::PasswdConfig,
},
discover::config::{AuthenticationType, AutoConfig, SecurityType, ServerType},
},
smtp::config::{SmtpAuthConfig, SmtpConfig, SmtpEncryptionKind},
};