mirror of
https://github.com/chatmail/core.git
synced 2026-04-26 09:56:35 +03:00
back to stable async-std + use surf instead of reqwest
removes tokio from our dependency tree, now only one async executor
This commit is contained in:
@@ -94,12 +94,12 @@ fn parse_xml(in_emailaddr: &str, xml_raw: &str) -> Result<LoginParam, Error> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn moz_autoconfigure(
|
||||
pub async fn moz_autoconfigure(
|
||||
context: &Context,
|
||||
url: &str,
|
||||
param_in: &LoginParam,
|
||||
) -> Result<LoginParam, Error> {
|
||||
let xml_raw = read_url(context, url)?;
|
||||
let xml_raw = read_url(context, url).await?;
|
||||
|
||||
let res = parse_xml(¶m_in.addr, &xml_raw);
|
||||
if let Err(err) = &res {
|
||||
|
||||
@@ -112,7 +112,7 @@ fn parse_xml(xml_raw: &str) -> Result<ParsingResult, Error> {
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
pub fn outlk_autodiscover(
|
||||
pub async fn outlk_autodiscover(
|
||||
context: &Context,
|
||||
url: &str,
|
||||
_param_in: &LoginParam,
|
||||
@@ -120,7 +120,7 @@ pub fn outlk_autodiscover(
|
||||
let mut url = url.to_string();
|
||||
/* Follow up to 10 xml-redirects (http-redirects are followed in read_url() */
|
||||
for _i in 0..10 {
|
||||
let xml_raw = read_url(context, &url)?;
|
||||
let xml_raw = read_url(context, &url).await?;
|
||||
let res = parse_xml(&xml_raw);
|
||||
if let Err(err) = &res {
|
||||
warn!(context, "{}", err);
|
||||
|
||||
@@ -248,7 +248,7 @@ async fn exec_step(
|
||||
"https://autoconfig.{}/mail/config-v1.1.xml?emailaddress={}",
|
||||
param_domain, param_addr_urlencoded
|
||||
);
|
||||
*param_autoconfig = moz_autoconfigure(ctx, &url, ¶m).ok();
|
||||
*param_autoconfig = moz_autoconfigure(ctx, &url, ¶m).await.ok();
|
||||
}
|
||||
}
|
||||
6 => {
|
||||
@@ -259,7 +259,7 @@ async fn exec_step(
|
||||
"https://{}/.well-known/autoconfig/mail/config-v1.1.xml?emailaddress={}",
|
||||
param_domain, param_addr_urlencoded
|
||||
);
|
||||
*param_autoconfig = moz_autoconfigure(ctx, &url, ¶m).ok();
|
||||
*param_autoconfig = moz_autoconfigure(ctx, &url, ¶m).await.ok();
|
||||
}
|
||||
}
|
||||
/* Outlook section start ------------- */
|
||||
@@ -268,7 +268,7 @@ async fn exec_step(
|
||||
progress!(ctx, 310);
|
||||
if param_autoconfig.is_none() {
|
||||
let url = format!("https://{}/autodiscover/autodiscover.xml", param_domain);
|
||||
*param_autoconfig = outlk_autodiscover(ctx, &url, ¶m).ok();
|
||||
*param_autoconfig = outlk_autodiscover(ctx, &url, ¶m).await.ok();
|
||||
}
|
||||
}
|
||||
8 => {
|
||||
@@ -278,7 +278,7 @@ async fn exec_step(
|
||||
"https://{}{}/autodiscover/autodiscover.xml",
|
||||
"autodiscover.", param_domain
|
||||
);
|
||||
*param_autoconfig = outlk_autodiscover(ctx, &url, ¶m).ok();
|
||||
*param_autoconfig = outlk_autodiscover(ctx, &url, ¶m).await.ok();
|
||||
}
|
||||
}
|
||||
/* ----------- Outlook section end */
|
||||
@@ -289,7 +289,7 @@ async fn exec_step(
|
||||
"http://autoconfig.{}/mail/config-v1.1.xml?emailaddress={}",
|
||||
param_domain, param_addr_urlencoded
|
||||
);
|
||||
*param_autoconfig = moz_autoconfigure(ctx, &url, ¶m).ok();
|
||||
*param_autoconfig = moz_autoconfigure(ctx, &url, ¶m).await.ok();
|
||||
}
|
||||
}
|
||||
10 => {
|
||||
@@ -300,7 +300,7 @@ async fn exec_step(
|
||||
"http://{}/.well-known/autoconfig/mail/config-v1.1.xml",
|
||||
param_domain
|
||||
);
|
||||
*param_autoconfig = moz_autoconfigure(ctx, &url, ¶m).ok();
|
||||
*param_autoconfig = moz_autoconfigure(ctx, &url, ¶m).await.ok();
|
||||
}
|
||||
}
|
||||
/* B. If we have no configuration yet, search configuration in Thunderbird's centeral database */
|
||||
@@ -309,7 +309,7 @@ async fn exec_step(
|
||||
if param_autoconfig.is_none() {
|
||||
/* always SSL for Thunderbird's database */
|
||||
let url = format!("https://autoconfig.thunderbird.net/v1.1/{}", param_domain);
|
||||
*param_autoconfig = moz_autoconfigure(ctx, &url, ¶m).ok();
|
||||
*param_autoconfig = moz_autoconfigure(ctx, &url, ¶m).await.ok();
|
||||
}
|
||||
}
|
||||
/* C. Do we have any autoconfig result?
|
||||
|
||||
@@ -3,17 +3,13 @@ use crate::context::Context;
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum Error {
|
||||
#[error("URL request error")]
|
||||
GetError(#[from] reqwest::Error),
|
||||
GetError(surf::Error),
|
||||
}
|
||||
|
||||
pub fn read_url(context: &Context, url: &str) -> Result<String, Error> {
|
||||
pub async fn read_url(context: &Context, url: &str) -> Result<String, Error> {
|
||||
info!(context, "Requesting URL {}", url);
|
||||
|
||||
match reqwest::blocking::Client::new()
|
||||
.get(url)
|
||||
.send()
|
||||
.and_then(|res| res.text())
|
||||
{
|
||||
match surf::get(url).recv_string().await {
|
||||
Ok(res) => Ok(res),
|
||||
Err(err) => {
|
||||
info!(context, "Can\'t read URL {}", url);
|
||||
|
||||
Reference in New Issue
Block a user