diff --git a/src/context.rs b/src/context.rs index 8c0942944..99d6749d7 100644 --- a/src/context.rs +++ b/src/context.rs @@ -249,16 +249,8 @@ unsafe fn cb_set_config(context: &Context, key: *const libc::c_char, value: *con * * @private @memberof Context */ -unsafe fn cb_get_config( - context: &Context, - key: *const libc::c_char, - def: *const libc::c_char, -) -> *mut libc::c_char { - let res = context - .sql - .get_config(context, as_str(key)) - .unwrap_or_else(|| to_string(def)); - to_cstring(res) +fn cb_get_config(context: &Context, key: &str) -> Option { + context.sql.get_config(context, key) } pub unsafe fn dc_context_unref(context: &mut Context) { diff --git a/src/imap.rs b/src/imap.rs index b07767372..17b544c49 100644 --- a/src/imap.rs +++ b/src/imap.rs @@ -5,7 +5,7 @@ use std::time::{Duration, SystemTime}; use crate::constants::*; use crate::context::Context; use crate::dc_loginparam::*; -use crate::dc_tools::{as_str, to_cstring}; +use crate::dc_tools::to_cstring; use crate::oauth2::dc_get_oauth2_access_token; use crate::types::*; use crate::x::free; @@ -705,26 +705,16 @@ impl Imap { fn get_config_last_seen_uid>(&self, context: &Context, folder: S) -> (u32, u32) { let key = format!("imap.mailbox.{}", folder.as_ref()); - let val1 = unsafe { - let key_c = to_cstring(key); - let val = (self.get_config)(context, key_c, 0 as *const libc::c_char); - free(key_c as *mut _); - val - }; - if val1.is_null() { - return (0, 0); + if let Some(entry) = (self.get_config)(context, &key) { + // the entry has the format `imap.mailbox.=:` + let mut parts = entry.split(':'); + ( + parts.next().unwrap().parse().unwrap_or_else(|_| 0), + parts.next().unwrap().parse().unwrap_or_else(|_| 0), + ) + } else { + (0, 0) } - let entry = as_str(val1); - - if entry.is_empty() { - return (0, 0); - } - // the entry has the format `imap.mailbox.=:` - let mut parts = entry.split(':'); - ( - parts.next().unwrap().parse().unwrap_or_else(|_| 0), - parts.next().unwrap().parse().unwrap_or_else(|_| 0), - ) } fn fetch_from_single_folder>(&self, context: &Context, folder: S) -> usize { diff --git a/src/types.rs b/src/types.rs index 3cf1043df..47bcbd23c 100644 --- a/src/types.rs +++ b/src/types.rs @@ -36,8 +36,7 @@ pub type dc_precheck_imf_t = unsafe fn(_: &Context, _: *const libc::c_char, _: &str, _: u32) -> libc::c_int; pub type dc_set_config_t = unsafe fn(_: &Context, _: *const libc::c_char, _: *const libc::c_char) -> (); -pub type dc_get_config_t = - unsafe fn(_: &Context, _: *const libc::c_char, _: *const libc::c_char) -> *mut libc::c_char; +pub type dc_get_config_t = fn(_: &Context, _: &str) -> Option; pub type sqlite_int64 = i64; pub type sqlite3_int64 = sqlite_int64;