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
No known key found for this signature in database
GPG key ID: 353E4A18EE0FAB72
6 changed files with 111 additions and 934 deletions

981
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -40,7 +40,7 @@ default = [
# "pgp-native",
]
wizard = ["autoconfig"]
wizard = ["email-lib/account-discovery"]
imap = ["email-lib/imap"]
maildir = ["email-lib/maildir"]
@ -108,7 +108,6 @@ tempfile = "3.3"
[dependencies]
anyhow = "1"
async-trait = "0.1"
autoconfig = { version = "0.4", optional = true }
chrono = "0.4.24"
clap = { version = "4.4", features = ["derive"] }
clap_complete = "4.4"
@ -116,7 +115,8 @@ clap_mangen = "0.2"
console = "0.15.2"
dialoguer = "0.10.2"
dirs = "4.0"
email-lib = { version = "=0.20.1", default-features = false }
# email-lib = { version = "=0.20.1", default-features = false }
email-lib = { git = "https://git.sr.ht/~soywod/pimalaya", default-features = false }
email_address = "0.2.4"
env_logger = "0.8"
erased-serde = "0.3"

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? {

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;

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},
};

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},
};