mirror of
https://github.com/chatmail/core.git
synced 2026-05-20 07:16:31 +03:00
Resultify outlk_autodiscover
This commit is contained in:
@@ -22,10 +22,22 @@ pub enum Error {
|
|||||||
|
|
||||||
#[fail(display = "Bad or incomplete autoconfig")]
|
#[fail(display = "Bad or incomplete autoconfig")]
|
||||||
IncompleteAutoconfig(LoginParam),
|
IncompleteAutoconfig(LoginParam),
|
||||||
|
|
||||||
|
#[fail(display = "Failed to get URL {}", _0)]
|
||||||
|
ReadUrlError(#[cause] super::read_url::Error),
|
||||||
|
|
||||||
|
#[fail(display = "Number of redirection is exceeded")]
|
||||||
|
RedirectionError,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type Result<T> = std::result::Result<T, Error>;
|
pub type Result<T> = std::result::Result<T, Error>;
|
||||||
|
|
||||||
|
impl From<super::read_url::Error> for Error {
|
||||||
|
fn from(err: super::read_url::Error) -> Error {
|
||||||
|
Error::ReadUrlError(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct OutlookAutodiscover {
|
struct OutlookAutodiscover {
|
||||||
pub out: LoginParam,
|
pub out: LoginParam,
|
||||||
pub out_imap_set: bool,
|
pub out_imap_set: bool,
|
||||||
@@ -42,7 +54,7 @@ enum ParsingResult {
|
|||||||
RedirectUrl(String),
|
RedirectUrl(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_xml(xml_raw: &str) -> Result<ParsingResult, Error> {
|
fn parse_xml(xml_raw: &str) -> Result<ParsingResult> {
|
||||||
let mut outlk_ad = OutlookAutodiscover {
|
let mut outlk_ad = OutlookAutodiscover {
|
||||||
out: LoginParam::new(),
|
out: LoginParam::new(),
|
||||||
out_imap_set: false,
|
out_imap_set: false,
|
||||||
@@ -133,26 +145,21 @@ pub fn outlk_autodiscover(
|
|||||||
context: &Context,
|
context: &Context,
|
||||||
url: &str,
|
url: &str,
|
||||||
_param_in: &LoginParam,
|
_param_in: &LoginParam,
|
||||||
) -> Option<LoginParam> {
|
) -> Result<LoginParam> {
|
||||||
let mut url = url.to_string();
|
let mut url = url.to_string();
|
||||||
/* Follow up to 10 xml-redirects (http-redirects are followed in read_url() */
|
/* Follow up to 10 xml-redirects (http-redirects are followed in read_url() */
|
||||||
for _i in 0..10 {
|
for _i in 0..10 {
|
||||||
if let Ok(xml_raw) = read_url(context, &url) {
|
let xml_raw = read_url(context, &url)?;
|
||||||
match parse_xml(&xml_raw) {
|
let res = parse_xml(&xml_raw);
|
||||||
Err(err) => {
|
if let Err(err) = &res {
|
||||||
warn!(context, "{}", err);
|
warn!(context, "{}", err);
|
||||||
return None;
|
}
|
||||||
}
|
match res? {
|
||||||
Ok(res) => match res {
|
ParsingResult::RedirectUrl(redirect_url) => url = redirect_url,
|
||||||
ParsingResult::RedirectUrl(redirect_url) => url = redirect_url,
|
ParsingResult::LoginParam(login_param) => return Ok(login_param),
|
||||||
ParsingResult::LoginParam(login_param) => return Some(login_param),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return None;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None
|
Err(Error::RedirectionError)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn outlk_autodiscover_endtag_cb(event: &BytesEnd, outlk_ad: &mut OutlookAutodiscover) {
|
fn outlk_autodiscover_endtag_cb(event: &BytesEnd, outlk_ad: &mut OutlookAutodiscover) {
|
||||||
|
|||||||
@@ -193,7 +193,7 @@ pub fn JobConfigureImap(context: &Context) {
|
|||||||
"https://{}{}/autodiscover/autodiscover.xml",
|
"https://{}{}/autodiscover/autodiscover.xml",
|
||||||
"", param_domain
|
"", param_domain
|
||||||
);
|
);
|
||||||
param_autoconfig = outlk_autodiscover(context, &url, ¶m);
|
param_autoconfig = outlk_autodiscover(context, &url, ¶m).ok();
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
@@ -204,7 +204,7 @@ pub fn JobConfigureImap(context: &Context) {
|
|||||||
"https://{}{}/autodiscover/autodiscover.xml",
|
"https://{}{}/autodiscover/autodiscover.xml",
|
||||||
"autodiscover.", param_domain
|
"autodiscover.", param_domain
|
||||||
);
|
);
|
||||||
param_autoconfig = outlk_autodiscover(context, &url, ¶m);
|
param_autoconfig = outlk_autodiscover(context, &url, ¶m).ok();
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user