From 400ab2cdab8648040a73e30bbe17c69dcc7347ca Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Thu, 12 Sep 2019 12:38:32 +0300 Subject: [PATCH 1/9] Return bool from dc_msg_get_showpadlock --- deltachat-ffi/src/lib.rs | 2 +- examples/repl/cmdline.rs | 2 +- src/message.rs | 9 ++------- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/deltachat-ffi/src/lib.rs b/deltachat-ffi/src/lib.rs index 5d0f08366..6dec8e23a 100644 --- a/deltachat-ffi/src/lib.rs +++ b/deltachat-ffi/src/lib.rs @@ -2085,7 +2085,7 @@ pub unsafe extern "C" fn dc_msg_get_showpadlock(msg: *mut dc_msg_t) -> libc::c_i return 0; } let ffi_msg = &*msg; - message::dc_msg_get_showpadlock(&ffi_msg.message) + message::dc_msg_get_showpadlock(&ffi_msg.message) as libc::c_int } #[no_mangle] diff --git a/examples/repl/cmdline.rs b/examples/repl/cmdline.rs index 3df2ab041..b88791e9b 100644 --- a/examples/repl/cmdline.rs +++ b/examples/repl/cmdline.rs @@ -229,7 +229,7 @@ unsafe fn log_msg(context: &Context, prefix: impl AsRef, msg: &Message) { "{}#{}{}{}: {} (Contact#{}): {} {}{}{}{} [{}]", prefix.as_ref(), dc_msg_get_id(msg) as libc::c_int, - if 0 != dc_msg_get_showpadlock(msg) { + if dc_msg_get_showpadlock(msg) { "🔒" } else { "" diff --git a/src/message.rs b/src/message.rs index 553922fd2..7b50fb9b5 100644 --- a/src/message.rs +++ b/src/message.rs @@ -699,13 +699,8 @@ pub fn dc_msg_get_duration(msg: &Message) -> libc::c_int { msg.param.get_int(Param::Duration).unwrap_or_default() } -// TODO should return bool /rtn -pub fn dc_msg_get_showpadlock(msg: &Message) -> libc::c_int { - if msg.param.get_int(Param::GuranteeE2ee).unwrap_or_default() != 0 { - return 1; - } - - 0 +pub fn dc_msg_get_showpadlock(msg: &Message) -> bool { + msg.param.get_int(Param::GuranteeE2ee).unwrap_or_default() != 0 } pub fn dc_msg_get_summary(context: &Context, msg: &mut Message, chat: Option<&Chat>) -> Lot { From 97edd2391008eff2544ae458f2ca6ead9be8994a Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Thu, 12 Sep 2019 12:39:55 +0300 Subject: [PATCH 2/9] Return bool from add_to_chat_contacts_table --- src/chat.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/chat.rs b/src/chat.rs index 662cd8584..ce9fb410b 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -1271,7 +1271,7 @@ pub unsafe fn create_group_chat( let chat_id = sql::get_rowid(context, &context.sql, "chats", "grpid", grpid); if chat_id != 0 { - if 0 != add_to_chat_contacts_table(context, chat_id, 1) { + if add_to_chat_contacts_table(context, chat_id, 1) { let mut draft_msg = dc_msg_new(Viewtype::Text); dc_msg_set_text(&mut draft_msg, draft_txt.as_ptr()); set_draft_raw(context, chat_id, Some(&mut draft_msg)); @@ -1285,8 +1285,7 @@ pub unsafe fn create_group_chat( /* you MUST NOT modify this or the following strings */ // Context functions to work with chats -// TODO should return bool /rtn -pub fn add_to_chat_contacts_table(context: &Context, chat_id: u32, contact_id: u32) -> libc::c_int { +pub fn add_to_chat_contacts_table(context: &Context, chat_id: u32, contact_id: u32) -> bool { // add a contact to a chat; the function does not check the type or if any of the record exist or are already // added to the chat! sql::execute( @@ -1295,7 +1294,7 @@ pub fn add_to_chat_contacts_table(context: &Context, chat_id: u32, contact_id: u "INSERT INTO chats_contacts (chat_id, contact_id) VALUES(?, ?)", params![chat_id as i32, contact_id as i32], ) - .is_ok() as libc::c_int + .is_ok() } pub unsafe fn add_contact_to_chat(context: &Context, chat_id: u32, contact_id: u32) -> libc::c_int { @@ -1367,7 +1366,7 @@ pub fn add_contact_to_chat_ex( } } if OK_TO_CONTINUE { - if 0 == add_to_chat_contacts_table(context, chat_id, contact_id) { + if !add_to_chat_contacts_table(context, chat_id, contact_id) { OK_TO_CONTINUE = false; } } From 0f67b16f29a8d5e178d7ee855b9ee54cd227db9e Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Thu, 12 Sep 2019 12:45:52 +0300 Subject: [PATCH 3/9] Return bool from add_contact_to_chat_ex --- deltachat-ffi/src/lib.rs | 2 +- examples/repl/cmdline.rs | 2 +- src/chat.rs | 13 ++++++------- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/deltachat-ffi/src/lib.rs b/deltachat-ffi/src/lib.rs index 6dec8e23a..c042ded02 100644 --- a/deltachat-ffi/src/lib.rs +++ b/deltachat-ffi/src/lib.rs @@ -848,7 +848,7 @@ pub unsafe extern "C" fn dc_add_contact_to_chat( let context = &*context; - chat::add_contact_to_chat(context, chat_id, contact_id) + chat::add_contact_to_chat(context, chat_id, contact_id) as libc::c_int } #[no_mangle] diff --git a/examples/repl/cmdline.rs b/examples/repl/cmdline.rs index b88791e9b..8f6ea5a5e 100644 --- a/examples/repl/cmdline.rs +++ b/examples/repl/cmdline.rs @@ -705,7 +705,7 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E ensure!(!arg1.is_empty(), "Argument missing."); let contact_id_0: libc::c_int = arg1.parse()?; - if 0 != chat::add_contact_to_chat( + if chat::add_contact_to_chat( context, sel_chat.as_ref().unwrap().get_id(), contact_id_0 as uint32_t, diff --git a/src/chat.rs b/src/chat.rs index ce9fb410b..243f1f88f 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -1297,24 +1297,23 @@ pub fn add_to_chat_contacts_table(context: &Context, chat_id: u32, contact_id: u .is_ok() } -pub unsafe fn add_contact_to_chat(context: &Context, chat_id: u32, contact_id: u32) -> libc::c_int { +pub unsafe fn add_contact_to_chat(context: &Context, chat_id: u32, contact_id: u32) -> bool { add_contact_to_chat_ex(context, chat_id, contact_id, 0) } -// TODO should return bool /rtn #[allow(non_snake_case)] pub fn add_contact_to_chat_ex( context: &Context, chat_id: u32, contact_id: u32, flags: libc::c_int, -) -> libc::c_int { +) -> bool { let mut OK_TO_CONTINUE = true; - let mut success: libc::c_int = 0; + let mut success = false; let contact = Contact::get_by_id(context, contact_id); if contact.is_err() || chat_id <= DC_CHAT_ID_LAST_SPECIAL { - return 0; + return false; } let mut msg = dc_msg_new_untyped(); @@ -1351,7 +1350,7 @@ pub fn add_contact_to_chat_ex( if 0 != is_contact_in_chat(context, chat_id, contact_id) { if 0 == flags & 0x1 { - success = 1; + success = true; OK_TO_CONTINUE = false; } } else { @@ -1391,7 +1390,7 @@ pub fn add_contact_to_chat_ex( ); } context.call_cb(Event::MSGS_CHANGED, chat_id as uintptr_t, 0 as uintptr_t); - success = 1; + success = true; } } } From fad49e08d7889f20c2e912c966382fd5a56cbccd Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Thu, 12 Sep 2019 12:50:08 +0300 Subject: [PATCH 4/9] message.rs: resolve "should return bool" TODOs --- deltachat-ffi/src/lib.rs | 10 +++++----- examples/repl/cmdline.rs | 6 +----- src/chat.rs | 2 +- src/dc_imex.rs | 2 +- src/dc_mimefactory.rs | 6 +++--- src/message.rs | 41 ++++++++++------------------------------ 6 files changed, 21 insertions(+), 46 deletions(-) diff --git a/deltachat-ffi/src/lib.rs b/deltachat-ffi/src/lib.rs index c042ded02..20b61f50a 100644 --- a/deltachat-ffi/src/lib.rs +++ b/deltachat-ffi/src/lib.rs @@ -2152,7 +2152,7 @@ pub unsafe extern "C" fn dc_msg_is_sent(msg: *mut dc_msg_t) -> libc::c_int { return 0; } let ffi_msg = &*msg; - message::dc_msg_is_sent(&ffi_msg.message) + message::dc_msg_is_sent(&ffi_msg.message).into() } #[no_mangle] @@ -2172,7 +2172,7 @@ pub unsafe extern "C" fn dc_msg_is_forwarded(msg: *mut dc_msg_t) -> libc::c_int return 0; } let ffi_msg = &*msg; - message::dc_msg_is_forwarded(&ffi_msg.message) + message::dc_msg_is_forwarded(&ffi_msg.message).into() } #[no_mangle] @@ -2182,7 +2182,7 @@ pub unsafe extern "C" fn dc_msg_is_info(msg: *mut dc_msg_t) -> libc::c_int { return 0; } let ffi_msg = &*msg; - message::dc_msg_is_info(&ffi_msg.message) + message::dc_msg_is_info(&ffi_msg.message).into() } #[no_mangle] @@ -2192,7 +2192,7 @@ pub unsafe extern "C" fn dc_msg_is_increation(msg: *mut dc_msg_t) -> libc::c_int return 0; } let ffi_msg = &*msg; - message::dc_msg_is_increation(&ffi_msg.message) + message::dc_msg_is_increation(&ffi_msg.message).into() } #[no_mangle] @@ -2202,7 +2202,7 @@ pub unsafe extern "C" fn dc_msg_is_setupmessage(msg: *mut dc_msg_t) -> libc::c_i return 0; } let ffi_msg = &*msg; - message::dc_msg_is_setupmessage(&ffi_msg.message) as libc::c_int + message::dc_msg_is_setupmessage(&ffi_msg.message).into() } #[no_mangle] diff --git a/examples/repl/cmdline.rs b/examples/repl/cmdline.rs index 8f6ea5a5e..8e0923f06 100644 --- a/examples/repl/cmdline.rs +++ b/examples/repl/cmdline.rs @@ -248,11 +248,7 @@ unsafe fn log_msg(context: &Context, prefix: impl AsRef, msg: &Message) { } else { "[FRESH]" }, - if 0 != dc_msg_is_info(msg) { - "[INFO]" - } else { - "" - }, + if dc_msg_is_info(msg) { "[INFO]" } else { "" }, statestr, &temp2, ); diff --git a/src/chat.rs b/src/chat.rs index 243f1f88f..4442cb350 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -868,7 +868,7 @@ unsafe fn set_draft_raw(context: &Context, chat_id: u32, mut msg: Option<&mut Me } else if msgtype_has_file(msg.type_0) { if let Some(path_filename) = msg.param.get(Param::File) { let mut path_filename = path_filename.to_string(); - if 0 != dc_msg_is_increation(msg) && !dc_is_blobdir_path(context, &path_filename) { + if dc_msg_is_increation(msg) && !dc_is_blobdir_path(context, &path_filename) { OK_TO_CONTINUE = false; } else if !dc_make_rel_and_copy(context, &mut path_filename) { OK_TO_CONTINUE = false; diff --git a/src/dc_imex.rs b/src/dc_imex.rs index 54d6161ab..06f6c6e87 100644 --- a/src/dc_imex.rs +++ b/src/dc_imex.rs @@ -168,7 +168,7 @@ pub unsafe fn dc_initiate_key_transfer(context: &Context) -> *mut libc::c_char { } std::thread::sleep(std::time::Duration::from_secs(1)); if let Ok(msg) = dc_get_msg(context, msg_id) { - if 0 != dc_msg_is_sent(&msg) { + if dc_msg_is_sent(&msg) { info!(context, "... setup message sent.",); break; } diff --git a/src/dc_mimefactory.rs b/src/dc_mimefactory.rs index 371c55b33..090cc4a00 100644 --- a/src/dc_mimefactory.rs +++ b/src/dc_mimefactory.rs @@ -39,7 +39,7 @@ pub struct dc_mimefactory_t<'a> { pub loaded: dc_mimefactory_loaded_t, pub msg: Message, pub chat: Option, - pub increation: libc::c_int, + pub increation: bool, pub in_reply_to: *mut libc::c_char, pub references: *mut libc::c_char, pub req_mdn: libc::c_int, @@ -102,7 +102,7 @@ pub unsafe fn dc_mimefactory_load_msg( loaded: DC_MF_NOTHING_LOADED, msg, chat: Some(chat), - increation: 0, + increation: false, in_reply_to: ptr::null_mut(), references: ptr::null_mut(), req_mdn: 0, @@ -290,7 +290,7 @@ pub unsafe fn dc_mimefactory_load_mdn<'a>( loaded: DC_MF_NOTHING_LOADED, msg, chat: None, - increation: 0, + increation: false, in_reply_to: ptr::null_mut(), references: ptr::null_mut(), req_mdn: 0, diff --git a/src/message.rs b/src/message.rs index 7b50fb9b5..368a2f83f 100644 --- a/src/message.rs +++ b/src/message.rs @@ -87,7 +87,7 @@ impl Lot { self.text1 = Some(context.stock_str(StockMessage::Draft).to_owned().into()); self.text1_meaning = Meaning::Text1Draft; } else if msg.from_id == DC_CONTACT_ID_SELF { - if 0 != dc_msg_is_info(msg) || chat.is_self_talk() { + if dc_msg_is_info(msg) || chat.is_self_talk() { self.text1 = None; self.text1_meaning = Meaning::None; } else { @@ -95,7 +95,7 @@ impl Lot { self.text1_meaning = Meaning::Text1Self; } } else if chat.typ == Chattype::Group || chat.typ == Chattype::VerifiedGroup { - if 0 != dc_msg_is_info(msg) || contact.is_none() { + if dc_msg_is_info(msg) || contact.is_none() { self.text1 = None; self.text1_meaning = Meaning::None; } else { @@ -820,48 +820,27 @@ pub unsafe fn dc_msg_has_deviating_timestamp(msg: &Message) -> libc::c_int { (sort_timestamp / 86400 != send_timestamp / 86400) as libc::c_int } -// TODO should return bool /rtn -pub fn dc_msg_is_sent(msg: &Message) -> libc::c_int { - if msg.state as i32 >= MessageState::OutDelivered as i32 { - 1 - } else { - 0 - } +pub fn dc_msg_is_sent(msg: &Message) -> bool { + msg.state as i32 >= MessageState::OutDelivered as i32 } pub fn dc_msg_is_starred(msg: &Message) -> bool { msg.starred } -// TODO should return bool /rtn -pub fn dc_msg_is_forwarded(msg: &Message) -> libc::c_int { - if 0 != msg.param.get_int(Param::Forwarded).unwrap_or_default() { - 1 - } else { - 0 - } +pub fn dc_msg_is_forwarded(msg: &Message) -> bool { + 0 != msg.param.get_int(Param::Forwarded).unwrap_or_default() } -// TODO should return bool /rtn -pub fn dc_msg_is_info(msg: &Message) -> libc::c_int { +pub fn dc_msg_is_info(msg: &Message) -> bool { let cmd = msg.param.get_int(Param::Cmd).unwrap_or_default(); - if msg.from_id == 2i32 as libc::c_uint + msg.from_id == 2i32 as libc::c_uint || msg.to_id == 2i32 as libc::c_uint || 0 != cmd && cmd != 6i32 - { - return 1; - } - - 0 } -// TODO should return bool /rtn -pub fn dc_msg_is_increation(msg: &Message) -> libc::c_int { - if chat::msgtype_has_file(msg.type_0) && msg.state == MessageState::OutPreparing { - 1 - } else { - 0 - } +pub fn dc_msg_is_increation(msg: &Message) -> bool { + chat::msgtype_has_file(msg.type_0) && msg.state == MessageState::OutPreparing } pub fn dc_msg_is_setupmessage(msg: &Message) -> bool { From d978a8e0a2d6f24da247124bab1465bcc1e4da5c Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Thu, 12 Sep 2019 12:54:23 +0300 Subject: [PATCH 5/9] Return bool from {import,export}_backup --- src/dc_imex.rs | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/dc_imex.rs b/src/dc_imex.rs index 06f6c6e87..0b189965d 100644 --- a/src/dc_imex.rs +++ b/src/dc_imex.rs @@ -532,13 +532,13 @@ pub unsafe fn dc_job_do_DC_JOB_IMEX_IMAP(context: &Context, job: &Job) { } } 11 => { - if 0 != export_backup(context, param1.as_ptr()) { + if export_backup(context, param1.as_ptr()) { info!(context, "Import/export completed.",); success = 1 } } 12 => { - if 0 != import_backup(context, param1.as_ptr()) { + if import_backup(context, param1.as_ptr()) { info!(context, "Import/export completed.",); success = 1 } @@ -561,9 +561,8 @@ pub unsafe fn dc_job_do_DC_JOB_IMEX_IMAP(context: &Context, job: &Job) { * Import backup ******************************************************************************/ -// TODO should return bool /rtn #[allow(non_snake_case)] -unsafe fn import_backup(context: &Context, backup_to_import: *const libc::c_char) -> libc::c_int { +unsafe fn import_backup(context: &Context, backup_to_import: *const libc::c_char) -> bool { info!( context, "Import \"{}\" to \"{}\".", @@ -576,7 +575,7 @@ unsafe fn import_backup(context: &Context, backup_to_import: *const libc::c_char if dc_is_configured(context) { error!(context, "Cannot import backups to accounts in use."); - return 0; + return false; } &context.sql.close(&context); dc_delete_file(context, context.get_dbfile().unwrap()); @@ -585,7 +584,7 @@ unsafe fn import_backup(context: &Context, backup_to_import: *const libc::c_char context, "Cannot import backups: Cannot delete the old file.", ); - return 0; + return false; } if !dc_copy_file( @@ -593,7 +592,7 @@ unsafe fn import_backup(context: &Context, backup_to_import: *const libc::c_char as_path(backup_to_import), context.get_dbfile().unwrap(), ) { - return 0; + return false; } /* error already logged */ /* re-open copied database file */ @@ -601,7 +600,7 @@ unsafe fn import_backup(context: &Context, backup_to_import: *const libc::c_char .sql .open(&context, &context.get_dbfile().unwrap(), 0) { - return 0; + return false; } let total_files_cnt = context @@ -680,7 +679,7 @@ unsafe fn import_backup(context: &Context, backup_to_import: *const libc::c_char sql::try_execute(context, &context.sql, "VACUUM;").ok(); Ok(()) }) - .is_ok() as libc::c_int + .is_ok() } /******************************************************************************* @@ -688,11 +687,10 @@ unsafe fn import_backup(context: &Context, backup_to_import: *const libc::c_char ******************************************************************************/ /* the FILE_PROGRESS macro calls the callback with the permille of files processed. The macro avoids weird values of 0% or 100% while still working. */ -// TODO should return bool /rtn #[allow(non_snake_case)] -unsafe fn export_backup(context: &Context, dir: *const libc::c_char) -> libc::c_int { +unsafe fn export_backup(context: &Context, dir: *const libc::c_char) -> bool { let mut ok_to_continue: bool; - let mut success: libc::c_int = 0; + let mut success = false; let mut delete_dest_file: libc::c_int = 0; // get a fine backup file name (the name includes the date so that multiple backup instances are possible) @@ -858,7 +856,7 @@ unsafe fn export_backup(context: &Context, dir: *const libc::c_char) -> libc::c_ dest_pathNfilename as uintptr_t, 0, ); - success = 1; + success = true; } } } else { From 3932d8f48f3701734cce9f592830882703482e5c Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Thu, 12 Sep 2019 12:55:48 +0300 Subject: [PATCH 6/9] Return bool from export_self_keys --- src/dc_imex.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/dc_imex.rs b/src/dc_imex.rs index 0b189965d..abe035fbf 100644 --- a/src/dc_imex.rs +++ b/src/dc_imex.rs @@ -520,7 +520,7 @@ pub unsafe fn dc_job_do_DC_JOB_IMEX_IMAP(context: &Context, job: &Job) { if ok_to_continue { match what { 1 => { - if 0 != export_self_keys(context, param1.as_ptr()) { + if export_self_keys(context, param1.as_ptr()) { info!(context, "Import/export completed.",); success = 1 } @@ -1004,8 +1004,7 @@ unsafe fn import_self_keys(context: &Context, dir_name: *const libc::c_char) -> imported_cnt } -// TODO should return bool /rtn -unsafe fn export_self_keys(context: &Context, dir: *const libc::c_char) -> libc::c_int { +unsafe fn export_self_keys(context: &Context, dir: *const libc::c_char) -> bool { let mut export_errors = 0; context @@ -1047,11 +1046,7 @@ unsafe fn export_self_keys(context: &Context, dir: *const libc::c_char) -> libc: ) .unwrap(); - if export_errors == 0 { - 1 - } else { - 0 - } + export_errors == 0 } /******************************************************************************* From 27a4adb9c6d6378a6dd44fb65b7d3efdcf8fa28b Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Thu, 12 Sep 2019 12:56:51 +0300 Subject: [PATCH 7/9] Return bool from export_key_to_asc_file --- src/dc_imex.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/dc_imex.rs b/src/dc_imex.rs index abe035fbf..05aa1f389 100644 --- a/src/dc_imex.rs +++ b/src/dc_imex.rs @@ -1026,14 +1026,14 @@ unsafe fn export_self_keys(context: &Context, dir: *const libc::c_char) -> bool for key_pair in keys { let (id, public_key, private_key, is_default) = key_pair?; if let Some(key) = public_key { - if 0 == export_key_to_asc_file(context, dir, id, &key, is_default) { + if export_key_to_asc_file(context, dir, id, &key, is_default) { export_errors += 1; } } else { export_errors += 1; } if let Some(key) = private_key { - if 0 == export_key_to_asc_file(context, dir, id, &key, is_default) { + if export_key_to_asc_file(context, dir, id, &key, is_default) { export_errors += 1; } } else { @@ -1052,15 +1052,14 @@ unsafe fn export_self_keys(context: &Context, dir: *const libc::c_char) -> bool /******************************************************************************* * Classic key export ******************************************************************************/ -// TODO should return bool /rtn unsafe fn export_key_to_asc_file( context: &Context, dir: *const libc::c_char, id: libc::c_int, key: &Key, is_default: libc::c_int, -) -> libc::c_int { - let mut success: libc::c_int = 0i32; +) -> bool { + let mut success = false; let file_name; if 0 != is_default { file_name = dc_mprintf( @@ -1094,7 +1093,7 @@ unsafe fn export_key_to_asc_file( file_name as uintptr_t, 0i32 as uintptr_t, ); - success = 1i32 + success = true; } free(file_name as *mut libc::c_void); From 50a812ea5e8235e0df2ac65f8006c2932e1627bf Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Thu, 12 Sep 2019 12:58:31 +0300 Subject: [PATCH 8/9] Return bool from mailmime_transfer_decode --- src/dc_mimeparser.rs | 25 +++++++++++-------------- src/dc_receive_imf.rs | 2 +- src/e2ee.rs | 15 ++++++--------- 3 files changed, 18 insertions(+), 24 deletions(-) diff --git a/src/dc_mimeparser.rs b/src/dc_mimeparser.rs index 8ae6a9269..48c180d3d 100644 --- a/src/dc_mimeparser.rs +++ b/src/dc_mimeparser.rs @@ -1033,14 +1033,12 @@ unsafe fn dc_mimeparser_add_single_part_if_known( || (*mime_data).dt_data.dt_text.dt_length <= 0) { /* regard `Content-Transfer-Encoding:` */ - if !(0 - == mailmime_transfer_decode( - mime, - &mut decoded_data, - &mut decoded_data_bytes, - &mut transfer_decoding_buffer, - )) - { + if mailmime_transfer_decode( + mime, + &mut decoded_data, + &mut decoded_data_bytes, + &mut transfer_decoding_buffer, + ) { /* no always error - but no data */ match mime_type { 60 | 70 => { @@ -1352,13 +1350,12 @@ unsafe fn do_add_single_part(parser: &mut dc_mimeparser_t, mut part: dc_mimepart parser.parts.push(part); } -// TODO should return bool /rtn pub unsafe fn mailmime_transfer_decode( mime: *mut mailmime, ret_decoded_data: *mut *const libc::c_char, ret_decoded_data_bytes: *mut size_t, ret_to_mmap_string_unref: *mut *mut libc::c_char, -) -> libc::c_int { +) -> bool { let mut mime_transfer_encoding: libc::c_int = MAILMIME_MECHANISM_BINARY as libc::c_int; let mime_data: *mut mailmime_data; /* must not be free()'d */ @@ -1374,7 +1371,7 @@ pub unsafe fn mailmime_transfer_decode( || *ret_decoded_data_bytes != 0 || !(*ret_to_mmap_string_unref).is_null() { - return 0i32; + return false; } mime_data = (*mime).mm_data.mm_single; if !(*mime).mm_mime_fields.is_null() { @@ -1408,7 +1405,7 @@ pub unsafe fn mailmime_transfer_decode( decoded_data = (*mime_data).dt_data.dt_text.dt_data; decoded_data_bytes = (*mime_data).dt_data.dt_text.dt_length; if decoded_data.is_null() || decoded_data_bytes <= 0 { - return 0i32; + return false; } } else { let r: libc::c_int; @@ -1425,7 +1422,7 @@ pub unsafe fn mailmime_transfer_decode( || transfer_decoding_buffer.is_null() || decoded_data_bytes <= 0 { - return 0i32; + return false; } decoded_data = transfer_decoding_buffer } @@ -1433,7 +1430,7 @@ pub unsafe fn mailmime_transfer_decode( *ret_decoded_data_bytes = decoded_data_bytes; *ret_to_mmap_string_unref = transfer_decoding_buffer; - 1 + true } pub unsafe fn dc_mimeparser_is_mailinglist_message(mimeparser: &dc_mimeparser_t) -> bool { diff --git a/src/dc_receive_imf.rs b/src/dc_receive_imf.rs index 45263d723..0c631c6d8 100644 --- a/src/dc_receive_imf.rs +++ b/src/dc_receive_imf.rs @@ -831,7 +831,7 @@ unsafe fn handle_reports( let mut report_body_bytes = 0; let mut to_mmap_string_unref = std::ptr::null_mut(); - if 0 != mailmime_transfer_decode( + if mailmime_transfer_decode( report_data, &mut report_body, &mut report_body_bytes, diff --git a/src/e2ee.rs b/src/e2ee.rs index 8622957c1..18987f270 100644 --- a/src/e2ee.rs +++ b/src/e2ee.rs @@ -1093,15 +1093,12 @@ Sent with my Delta Chat Messenger: https://delta.chat"; let mut decoded_data_bytes = 0; let mut transfer_decoding_buffer: *mut libc::c_char = ptr::null_mut(); - assert_eq!( - mailmime_transfer_decode( - msg1, - &mut decoded_data, - &mut decoded_data_bytes, - &mut transfer_decoding_buffer, - ), - 1 - ); + assert!(mailmime_transfer_decode( + msg1, + &mut decoded_data, + &mut decoded_data_bytes, + &mut transfer_decoding_buffer, + )); println!( "{:?}", String::from_utf8_lossy(std::slice::from_raw_parts( From e1e02839d1607a77b82021b719f6d569715126b8 Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Thu, 12 Sep 2019 12:59:52 +0300 Subject: [PATCH 9/9] Return bool from dc_mimefactory_render --- src/dc_mimefactory.rs | 10 +++------- src/job.rs | 4 ++-- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/dc_mimefactory.rs b/src/dc_mimefactory.rs index 090cc4a00..9fbeeb376 100644 --- a/src/dc_mimefactory.rs +++ b/src/dc_mimefactory.rs @@ -334,11 +334,7 @@ pub unsafe fn dc_mimefactory_load_mdn<'a>( Ok(factory) } -// TODO should return bool /rtn -pub unsafe fn dc_mimefactory_render( - context: &Context, - factory: &mut dc_mimefactory_t, -) -> libc::c_int { +pub unsafe fn dc_mimefactory_render(context: &Context, factory: &mut dc_mimefactory_t) -> bool { let subject: *mut mailimf_subject; let mut ok_to_continue = true; let imf_fields: *mut mailimf_fields; @@ -348,7 +344,7 @@ pub unsafe fn dc_mimefactory_render( let mut subject_str: *mut libc::c_char = ptr::null_mut(); let mut afwd_email: libc::c_int = 0; let mut col: libc::c_int = 0; - let mut success: libc::c_int = 0; + let mut success = false; let mut parts: libc::c_int = 0; let mut e2ee_guaranteed: libc::c_int = 0; let mut min_verified: libc::c_int = 0; @@ -1046,7 +1042,7 @@ pub unsafe fn dc_mimefactory_render( } factory.out = mmap_string_new(b"\x00" as *const u8 as *const libc::c_char); mailmime_write_mem(factory.out, &mut col, message); - success = 1; + success = true; } } diff --git a/src/job.rs b/src/job.rs index 24904ef9d..2f4e6d399 100644 --- a/src/job.rs +++ b/src/job.rs @@ -680,7 +680,7 @@ pub unsafe fn job_send_msg(context: &Context, msg_id: uint32_t) -> libc::c_int { } } /* create message */ - if 0 == dc_mimefactory_render(context, &mut mimefactory) { + if !dc_mimefactory_render(context, &mut mimefactory) { dc_set_msg_failed(context, msg_id, as_opt_str(mimefactory.error)); } else if 0 != mimefactory @@ -990,7 +990,7 @@ fn connect_to_inbox(context: &Context, inbox: &Imap) -> libc::c_int { fn send_mdn(context: &Context, msg_id: uint32_t) { if let Ok(mut mimefactory) = unsafe { dc_mimefactory_load_mdn(context, msg_id) } { - if 0 != unsafe { dc_mimefactory_render(context, &mut mimefactory) } { + if unsafe { dc_mimefactory_render(context, &mut mimefactory) } { add_smtp_job(context, Action::SendMdn, &mut mimefactory); } }