From 63043cb45d58d03bd9c6f73d2d12cd4f15674f57 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Sun, 26 Jan 2020 23:27:36 +0100 Subject: [PATCH] add after_login_hint, refine ffi --- deltachat-ffi/deltachat.h | 8 ++++++-- src/provider.rs | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/deltachat-ffi/deltachat.h b/deltachat-ffi/deltachat.h index ee4dc5422..2e50f4cce 100644 --- a/deltachat-ffi/deltachat.h +++ b/deltachat-ffi/deltachat.h @@ -3708,7 +3708,9 @@ dc_provider_t* dc_provider_new_from_email (const dc_context_t*, cons * * @memberof dc_provider_t * @param provider The dc_provider_t struct. - * @return A string which must be released using dc_str_unref(). + * @return String with a fully-qualified URL, + * if there is no such URL, an empty string is returned, NULL is never returned. + * The returned value must be released using dc_str_unref(). */ char* dc_provider_get_overview_page (const dc_provider_t* provider); @@ -3723,7 +3725,9 @@ char* dc_provider_get_overview_page (const dc_provider_t* prov * * @memberof dc_provider_t * @param provider The dc_provider_t struct. - * @return A string which must be released using dc_str_unref(). + * @return A string with the hint to show to the user, may contain multiple lines, + * if there is no such hint, an empty string is returned, NULL is never returned. + * The returned value must be released using dc_str_unref(). */ char* dc_provider_get_before_login_hint (const dc_provider_t* provider); diff --git a/src/provider.rs b/src/provider.rs index e90cdc431..f7b146516 100644 --- a/src/provider.rs +++ b/src/provider.rs @@ -46,17 +46,18 @@ pub struct Provider { pub domains: &'static str, pub status: Status, pub before_login_hint: &'static str, + pub after_login_hint: &'static str, pub overview_page: &'static str, - pub server: Vec, // this seems to be okay + pub server: Vec, } -// TODO: the database will be auto-generated from the provider-db lazy_static::lazy_static! { static ref DATABASE: Vec = vec![ Provider { domains: "nauta.cu", status: Status::OK, before_login_hint: "", + after_login_hint: "", overview_page: "", server: vec![ Server { protocol: IMAP, socket: STARTTLS, server: "imap.nauta.cu", port: 143, username_pattern: EMAIL }, @@ -71,6 +72,7 @@ lazy_static::lazy_static! { Hopefully sooner or later there will be a fix; \ for now, we suggest to use another e-mail-address \ or try Delta Chat again when the issue is fixed.", + after_login_hint: "", overview_page: "https://provider.delta.chat/outlook.com", server: vec![ ], @@ -82,6 +84,7 @@ lazy_static::lazy_static! { if you have \"2-Step Verification\" enabled. \ If this setting is not available, \ you need to enable \"Less secure apps\".", + after_login_hint: "", overview_page: "https://provider.delta.chat/gmail.com", server: vec![ ], @@ -106,3 +109,28 @@ pub fn get_provider_info(addr: &str) -> Option<&Provider> { None } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_get_provider_info() { + let provider = get_provider_info("user@unexistant.org"); + assert!(provider.is_none()); + + let provider = get_provider_info("nauta.cu"); // this is no email address + assert!(provider.is_none()); + + let provider = get_provider_info("user@nauta.cu").unwrap(); + assert!(provider.status == Status::OK); + + let provider = get_provider_info("user@gmail.com").unwrap(); + assert!(provider.status == Status::PREPARATION); + assert!(!provider.before_login_hint.is_empty()); + assert!(!provider.overview_page.is_empty()); + + let provider = get_provider_info("user@googlemail.com").unwrap(); + assert!(provider.status == Status::PREPARATION); + } +}