add provider info function

This commit is contained in:
Simon Laux
2019-09-04 16:51:28 +02:00
parent 46520edd87
commit c0c014d7e2
4 changed files with 51 additions and 0 deletions

View File

@@ -16,6 +16,8 @@ use std::convert::TryInto;
use std::ptr;
use std::str::FromStr;
extern crate deltachat_provider_overview;
use deltachat::contact::Contact;
use deltachat::dc_tools::{as_str, dc_strdup, StrExt};
use deltachat::*;
@@ -2530,6 +2532,19 @@ fn as_opt_str<'a>(s: *const libc::c_char) -> Option<&'a str> {
Some(dc_tools::as_str(s))
}
pub unsafe extern "C" fn dc_get_json_provider_info_from_email(
email: *const libc::c_char,
) -> *mut libc::c_char {
let option = deltachat_provider_overview::get_provider_info(
deltachat_provider_overview::get_domain_from_email(dc_tools::as_str(email)),
);
if let Some(provider) = option {
serde_json::to_string(provider.0).unwrap().strdup()
} else {
dc_strdup(ptr::null())
}
}
pub trait ResultExt<T> {
fn unwrap_or_log_default(self, context: &context::Context, message: &str) -> T;
fn log_err(&self, context: &context::Context, message: &str);