diff --git a/src/config.rs b/src/config.rs index 839af5cfb..63772ab8a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -71,7 +71,7 @@ impl Context { let rel_path = self.sql.get_config(self, key); rel_path.map(|p| dc_get_abs_path_safe(self, &p).to_str().unwrap().to_string()) } - Config::SysVersion => Some(std::str::from_utf8(DC_VERSION_STR).unwrap().into()), + Config::SysVersion => Some((&*DC_VERSION_STR).clone()), Config::SysMsgsizeMaxRecommended => Some(format!("{}", 24 * 1024 * 1024 / 4 * 3)), Config::SysConfigKeys => Some(get_config_keys_string()), _ => self.sql.get_config(self, key), diff --git a/src/constants.rs b/src/constants.rs index 6f22595e9..bfb2fbaf7 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -1,8 +1,13 @@ //! Constants #![allow(non_camel_case_types)] + +use lazy_static::lazy_static; + use deltachat_derive::*; -pub const DC_VERSION_STR: &[u8; 14] = b"1.0.0-alpha.3\x00"; +lazy_static! { + pub static ref DC_VERSION_STR: String = env!("CARGO_PKG_VERSION").to_string(); +} #[repr(u8)] #[derive(Debug, Display, Clone, Copy, PartialEq, Eq, FromPrimitive, ToPrimitive, ToSql, FromSql)] diff --git a/src/context.rs b/src/context.rs index aee416167..9ca80c361 100644 --- a/src/context.rs +++ b/src/context.rs @@ -440,7 +440,7 @@ pub unsafe fn dc_get_info(context: &Context) -> *mut libc::c_char { public_key_count={}\n\ fingerprint={}\n\ level=awesome\n", - as_str(DC_VERSION_STR as *const u8 as *const _), + &*DC_VERSION_STR, rusqlite::version(), sqlite3_threadsafe(), // arch @@ -481,7 +481,7 @@ pub unsafe fn dc_get_info(context: &Context) -> *mut libc::c_char { } pub unsafe fn dc_get_version_str() -> *mut libc::c_char { - dc_strdup(DC_VERSION_STR as *const u8 as *const libc::c_char) + (&*DC_VERSION_STR).strdup() } pub fn dc_get_fresh_msgs(context: &Context) -> *mut dc_array_t { diff --git a/src/dc_mimefactory.rs b/src/dc_mimefactory.rs index e4f22e6de..5b1cbb06a 100644 --- a/src/dc_mimefactory.rs +++ b/src/dc_mimefactory.rs @@ -13,7 +13,7 @@ use std::ptr; use crate::constants::*; use crate::contact::*; -use crate::context::Context; +use crate::context::{dc_get_version_str, Context}; use crate::dc_chat::*; use crate::dc_e2ee::*; use crate::dc_location::*; @@ -478,18 +478,19 @@ pub unsafe fn dc_mimefactory_render(mut factory: *mut dc_mimefactory_t) -> libc: .map(|s| format!("/{}", s)) .unwrap_or_default(); let os_part = CString::new(os_part).expect("String -> CString conversion failed"); - + let version = dc_get_version_str(); mailimf_fields_add( imf_fields, mailimf_field_new_custom( strdup(b"X-Mailer\x00" as *const u8 as *const libc::c_char), dc_mprintf( b"Delta Chat Core %s%s\x00" as *const u8 as *const libc::c_char, - DC_VERSION_STR as *const u8 as *const libc::c_char, + version, os_part.as_ptr(), ), ), ); + free(version.cast()); mailimf_fields_add( imf_fields, @@ -960,12 +961,14 @@ pub unsafe fn dc_mimefactory_render(mut factory: *mut dc_mimefactory_t) -> libc: message_text = format!("{}\r\n", p2).strdup(); let human_mime_part: *mut mailmime = build_body_text(message_text); mailmime_add_part(multipart, human_mime_part); + let version = dc_get_version_str(); message_text2 = dc_mprintf(b"Reporting-UA: Delta Chat %s\r\nOriginal-Recipient: rfc822;%s\r\nFinal-Recipient: rfc822;%s\r\nOriginal-Message-ID: <%s>\r\nDisposition: manual-action/MDN-sent-automatically; displayed\r\n\x00" as *const u8 as *const libc::c_char, - DC_VERSION_STR as *const u8 as *const libc::c_char, + version, (*factory).from_addr, (*factory).from_addr, (*(*factory).msg).rfc724_mid); + free(version.cast()); let content_type_0: *mut mailmime_content = mailmime_content_new_with_str( b"message/disposition-notification\x00" as *const u8 as *const libc::c_char, );