mirror of
https://github.com/chatmail/core.git
synced 2026-05-05 22:36:30 +03:00
Merge pull request #498 from deltachat/return_bool
Resolve "should return bool" TODOs
This commit is contained in:
@@ -848,7 +848,7 @@ pub unsafe extern "C" fn dc_add_contact_to_chat(
|
|||||||
|
|
||||||
let context = &*context;
|
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]
|
#[no_mangle]
|
||||||
@@ -2085,7 +2085,7 @@ pub unsafe extern "C" fn dc_msg_get_showpadlock(msg: *mut dc_msg_t) -> libc::c_i
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
let ffi_msg = &*msg;
|
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]
|
#[no_mangle]
|
||||||
@@ -2152,7 +2152,7 @@ pub unsafe extern "C" fn dc_msg_is_sent(msg: *mut dc_msg_t) -> libc::c_int {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
let ffi_msg = &*msg;
|
let ffi_msg = &*msg;
|
||||||
message::dc_msg_is_sent(&ffi_msg.message)
|
message::dc_msg_is_sent(&ffi_msg.message).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[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;
|
return 0;
|
||||||
}
|
}
|
||||||
let ffi_msg = &*msg;
|
let ffi_msg = &*msg;
|
||||||
message::dc_msg_is_forwarded(&ffi_msg.message)
|
message::dc_msg_is_forwarded(&ffi_msg.message).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[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;
|
return 0;
|
||||||
}
|
}
|
||||||
let ffi_msg = &*msg;
|
let ffi_msg = &*msg;
|
||||||
message::dc_msg_is_info(&ffi_msg.message)
|
message::dc_msg_is_info(&ffi_msg.message).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[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;
|
return 0;
|
||||||
}
|
}
|
||||||
let ffi_msg = &*msg;
|
let ffi_msg = &*msg;
|
||||||
message::dc_msg_is_increation(&ffi_msg.message)
|
message::dc_msg_is_increation(&ffi_msg.message).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[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;
|
return 0;
|
||||||
}
|
}
|
||||||
let ffi_msg = &*msg;
|
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]
|
#[no_mangle]
|
||||||
|
|||||||
@@ -229,7 +229,7 @@ unsafe fn log_msg(context: &Context, prefix: impl AsRef<str>, msg: &Message) {
|
|||||||
"{}#{}{}{}: {} (Contact#{}): {} {}{}{}{} [{}]",
|
"{}#{}{}{}: {} (Contact#{}): {} {}{}{}{} [{}]",
|
||||||
prefix.as_ref(),
|
prefix.as_ref(),
|
||||||
dc_msg_get_id(msg) as libc::c_int,
|
dc_msg_get_id(msg) as libc::c_int,
|
||||||
if 0 != dc_msg_get_showpadlock(msg) {
|
if dc_msg_get_showpadlock(msg) {
|
||||||
"🔒"
|
"🔒"
|
||||||
} else {
|
} else {
|
||||||
""
|
""
|
||||||
@@ -248,11 +248,7 @@ unsafe fn log_msg(context: &Context, prefix: impl AsRef<str>, msg: &Message) {
|
|||||||
} else {
|
} else {
|
||||||
"[FRESH]"
|
"[FRESH]"
|
||||||
},
|
},
|
||||||
if 0 != dc_msg_is_info(msg) {
|
if dc_msg_is_info(msg) { "[INFO]" } else { "" },
|
||||||
"[INFO]"
|
|
||||||
} else {
|
|
||||||
""
|
|
||||||
},
|
|
||||||
statestr,
|
statestr,
|
||||||
&temp2,
|
&temp2,
|
||||||
);
|
);
|
||||||
@@ -705,7 +701,7 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E
|
|||||||
ensure!(!arg1.is_empty(), "Argument <contact-id> missing.");
|
ensure!(!arg1.is_empty(), "Argument <contact-id> missing.");
|
||||||
|
|
||||||
let contact_id_0: libc::c_int = arg1.parse()?;
|
let contact_id_0: libc::c_int = arg1.parse()?;
|
||||||
if 0 != chat::add_contact_to_chat(
|
if chat::add_contact_to_chat(
|
||||||
context,
|
context,
|
||||||
sel_chat.as_ref().unwrap().get_id(),
|
sel_chat.as_ref().unwrap().get_id(),
|
||||||
contact_id_0 as uint32_t,
|
contact_id_0 as uint32_t,
|
||||||
|
|||||||
24
src/chat.rs
24
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) {
|
} else if msgtype_has_file(msg.type_0) {
|
||||||
if let Some(path_filename) = msg.param.get(Param::File) {
|
if let Some(path_filename) = msg.param.get(Param::File) {
|
||||||
let mut path_filename = path_filename.to_string();
|
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;
|
OK_TO_CONTINUE = false;
|
||||||
} else if !dc_make_rel_and_copy(context, &mut path_filename) {
|
} else if !dc_make_rel_and_copy(context, &mut path_filename) {
|
||||||
OK_TO_CONTINUE = false;
|
OK_TO_CONTINUE = false;
|
||||||
@@ -1271,7 +1271,7 @@ pub unsafe fn create_group_chat(
|
|||||||
let chat_id = sql::get_rowid(context, &context.sql, "chats", "grpid", grpid);
|
let chat_id = sql::get_rowid(context, &context.sql, "chats", "grpid", grpid);
|
||||||
|
|
||||||
if chat_id != 0 {
|
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);
|
let mut draft_msg = dc_msg_new(Viewtype::Text);
|
||||||
dc_msg_set_text(&mut draft_msg, draft_txt.as_ptr());
|
dc_msg_set_text(&mut draft_msg, draft_txt.as_ptr());
|
||||||
set_draft_raw(context, chat_id, Some(&mut draft_msg));
|
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 */
|
/* you MUST NOT modify this or the following strings */
|
||||||
// Context functions to work with chats
|
// 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) -> bool {
|
||||||
pub fn add_to_chat_contacts_table(context: &Context, chat_id: u32, contact_id: u32) -> libc::c_int {
|
|
||||||
// add a contact to a chat; the function does not check the type or if any of the record exist or are already
|
// 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!
|
// added to the chat!
|
||||||
sql::execute(
|
sql::execute(
|
||||||
@@ -1295,27 +1294,26 @@ pub fn add_to_chat_contacts_table(context: &Context, chat_id: u32, contact_id: u
|
|||||||
"INSERT INTO chats_contacts (chat_id, contact_id) VALUES(?, ?)",
|
"INSERT INTO chats_contacts (chat_id, contact_id) VALUES(?, ?)",
|
||||||
params![chat_id as i32, contact_id as i32],
|
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 {
|
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)
|
add_contact_to_chat_ex(context, chat_id, contact_id, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO should return bool /rtn
|
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
pub fn add_contact_to_chat_ex(
|
pub fn add_contact_to_chat_ex(
|
||||||
context: &Context,
|
context: &Context,
|
||||||
chat_id: u32,
|
chat_id: u32,
|
||||||
contact_id: u32,
|
contact_id: u32,
|
||||||
flags: libc::c_int,
|
flags: libc::c_int,
|
||||||
) -> libc::c_int {
|
) -> bool {
|
||||||
let mut OK_TO_CONTINUE = true;
|
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);
|
let contact = Contact::get_by_id(context, contact_id);
|
||||||
|
|
||||||
if contact.is_err() || chat_id <= DC_CHAT_ID_LAST_SPECIAL {
|
if contact.is_err() || chat_id <= DC_CHAT_ID_LAST_SPECIAL {
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
let mut msg = dc_msg_new_untyped();
|
let mut msg = dc_msg_new_untyped();
|
||||||
|
|
||||||
@@ -1352,7 +1350,7 @@ pub fn add_contact_to_chat_ex(
|
|||||||
|
|
||||||
if 0 != is_contact_in_chat(context, chat_id, contact_id) {
|
if 0 != is_contact_in_chat(context, chat_id, contact_id) {
|
||||||
if 0 == flags & 0x1 {
|
if 0 == flags & 0x1 {
|
||||||
success = 1;
|
success = true;
|
||||||
OK_TO_CONTINUE = false;
|
OK_TO_CONTINUE = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -1367,7 +1365,7 @@ pub fn add_contact_to_chat_ex(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if OK_TO_CONTINUE {
|
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;
|
OK_TO_CONTINUE = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1392,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);
|
context.call_cb(Event::MSGS_CHANGED, chat_id as uintptr_t, 0 as uintptr_t);
|
||||||
success = 1;
|
success = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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));
|
std::thread::sleep(std::time::Duration::from_secs(1));
|
||||||
if let Ok(msg) = dc_get_msg(context, msg_id) {
|
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.",);
|
info!(context, "... setup message sent.",);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -520,7 +520,7 @@ pub unsafe fn dc_job_do_DC_JOB_IMEX_IMAP(context: &Context, job: &Job) {
|
|||||||
if ok_to_continue {
|
if ok_to_continue {
|
||||||
match what {
|
match what {
|
||||||
1 => {
|
1 => {
|
||||||
if 0 != export_self_keys(context, param1.as_ptr()) {
|
if export_self_keys(context, param1.as_ptr()) {
|
||||||
info!(context, "Import/export completed.",);
|
info!(context, "Import/export completed.",);
|
||||||
success = 1
|
success = 1
|
||||||
}
|
}
|
||||||
@@ -532,13 +532,13 @@ pub unsafe fn dc_job_do_DC_JOB_IMEX_IMAP(context: &Context, job: &Job) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
11 => {
|
11 => {
|
||||||
if 0 != export_backup(context, param1.as_ptr()) {
|
if export_backup(context, param1.as_ptr()) {
|
||||||
info!(context, "Import/export completed.",);
|
info!(context, "Import/export completed.",);
|
||||||
success = 1
|
success = 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
12 => {
|
12 => {
|
||||||
if 0 != import_backup(context, param1.as_ptr()) {
|
if import_backup(context, param1.as_ptr()) {
|
||||||
info!(context, "Import/export completed.",);
|
info!(context, "Import/export completed.",);
|
||||||
success = 1
|
success = 1
|
||||||
}
|
}
|
||||||
@@ -561,9 +561,8 @@ pub unsafe fn dc_job_do_DC_JOB_IMEX_IMAP(context: &Context, job: &Job) {
|
|||||||
* Import backup
|
* Import backup
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
// TODO should return bool /rtn
|
|
||||||
#[allow(non_snake_case)]
|
#[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!(
|
info!(
|
||||||
context,
|
context,
|
||||||
"Import \"{}\" to \"{}\".",
|
"Import \"{}\" to \"{}\".",
|
||||||
@@ -576,7 +575,7 @@ unsafe fn import_backup(context: &Context, backup_to_import: *const libc::c_char
|
|||||||
|
|
||||||
if dc_is_configured(context) {
|
if dc_is_configured(context) {
|
||||||
error!(context, "Cannot import backups to accounts in use.");
|
error!(context, "Cannot import backups to accounts in use.");
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
&context.sql.close(&context);
|
&context.sql.close(&context);
|
||||||
dc_delete_file(context, context.get_dbfile().unwrap());
|
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,
|
context,
|
||||||
"Cannot import backups: Cannot delete the old file.",
|
"Cannot import backups: Cannot delete the old file.",
|
||||||
);
|
);
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if !dc_copy_file(
|
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),
|
as_path(backup_to_import),
|
||||||
context.get_dbfile().unwrap(),
|
context.get_dbfile().unwrap(),
|
||||||
) {
|
) {
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
/* error already logged */
|
/* error already logged */
|
||||||
/* re-open copied database file */
|
/* re-open copied database file */
|
||||||
@@ -601,7 +600,7 @@ unsafe fn import_backup(context: &Context, backup_to_import: *const libc::c_char
|
|||||||
.sql
|
.sql
|
||||||
.open(&context, &context.get_dbfile().unwrap(), 0)
|
.open(&context, &context.get_dbfile().unwrap(), 0)
|
||||||
{
|
{
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
let total_files_cnt = context
|
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();
|
sql::try_execute(context, &context.sql, "VACUUM;").ok();
|
||||||
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 FILE_PROGRESS macro calls the callback with the permille of files processed.
|
||||||
The macro avoids weird values of 0% or 100% while still working. */
|
The macro avoids weird values of 0% or 100% while still working. */
|
||||||
// TODO should return bool /rtn
|
|
||||||
#[allow(non_snake_case)]
|
#[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 ok_to_continue: bool;
|
||||||
let mut success: libc::c_int = 0;
|
let mut success = false;
|
||||||
|
|
||||||
let mut delete_dest_file: libc::c_int = 0;
|
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)
|
// 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,
|
dest_pathNfilename as uintptr_t,
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
success = 1;
|
success = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -1006,8 +1004,7 @@ unsafe fn import_self_keys(context: &Context, dir_name: *const libc::c_char) ->
|
|||||||
imported_cnt
|
imported_cnt
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO should return bool /rtn
|
unsafe fn export_self_keys(context: &Context, dir: *const libc::c_char) -> bool {
|
||||||
unsafe fn export_self_keys(context: &Context, dir: *const libc::c_char) -> libc::c_int {
|
|
||||||
let mut export_errors = 0;
|
let mut export_errors = 0;
|
||||||
|
|
||||||
context
|
context
|
||||||
@@ -1029,14 +1026,14 @@ unsafe fn export_self_keys(context: &Context, dir: *const libc::c_char) -> libc:
|
|||||||
for key_pair in keys {
|
for key_pair in keys {
|
||||||
let (id, public_key, private_key, is_default) = key_pair?;
|
let (id, public_key, private_key, is_default) = key_pair?;
|
||||||
if let Some(key) = public_key {
|
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;
|
export_errors += 1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
export_errors += 1;
|
export_errors += 1;
|
||||||
}
|
}
|
||||||
if let Some(key) = private_key {
|
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;
|
export_errors += 1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -1049,25 +1046,20 @@ unsafe fn export_self_keys(context: &Context, dir: *const libc::c_char) -> libc:
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
if export_errors == 0 {
|
export_errors == 0
|
||||||
1
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Classic key export
|
* Classic key export
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
// TODO should return bool /rtn
|
|
||||||
unsafe fn export_key_to_asc_file(
|
unsafe fn export_key_to_asc_file(
|
||||||
context: &Context,
|
context: &Context,
|
||||||
dir: *const libc::c_char,
|
dir: *const libc::c_char,
|
||||||
id: libc::c_int,
|
id: libc::c_int,
|
||||||
key: &Key,
|
key: &Key,
|
||||||
is_default: libc::c_int,
|
is_default: libc::c_int,
|
||||||
) -> libc::c_int {
|
) -> bool {
|
||||||
let mut success: libc::c_int = 0i32;
|
let mut success = false;
|
||||||
let file_name;
|
let file_name;
|
||||||
if 0 != is_default {
|
if 0 != is_default {
|
||||||
file_name = dc_mprintf(
|
file_name = dc_mprintf(
|
||||||
@@ -1101,7 +1093,7 @@ unsafe fn export_key_to_asc_file(
|
|||||||
file_name as uintptr_t,
|
file_name as uintptr_t,
|
||||||
0i32 as uintptr_t,
|
0i32 as uintptr_t,
|
||||||
);
|
);
|
||||||
success = 1i32
|
success = true;
|
||||||
}
|
}
|
||||||
free(file_name as *mut libc::c_void);
|
free(file_name as *mut libc::c_void);
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ pub struct dc_mimefactory_t<'a> {
|
|||||||
pub loaded: dc_mimefactory_loaded_t,
|
pub loaded: dc_mimefactory_loaded_t,
|
||||||
pub msg: Message,
|
pub msg: Message,
|
||||||
pub chat: Option<Chat>,
|
pub chat: Option<Chat>,
|
||||||
pub increation: libc::c_int,
|
pub increation: bool,
|
||||||
pub in_reply_to: *mut libc::c_char,
|
pub in_reply_to: *mut libc::c_char,
|
||||||
pub references: *mut libc::c_char,
|
pub references: *mut libc::c_char,
|
||||||
pub req_mdn: libc::c_int,
|
pub req_mdn: libc::c_int,
|
||||||
@@ -102,7 +102,7 @@ pub unsafe fn dc_mimefactory_load_msg(
|
|||||||
loaded: DC_MF_NOTHING_LOADED,
|
loaded: DC_MF_NOTHING_LOADED,
|
||||||
msg,
|
msg,
|
||||||
chat: Some(chat),
|
chat: Some(chat),
|
||||||
increation: 0,
|
increation: false,
|
||||||
in_reply_to: ptr::null_mut(),
|
in_reply_to: ptr::null_mut(),
|
||||||
references: ptr::null_mut(),
|
references: ptr::null_mut(),
|
||||||
req_mdn: 0,
|
req_mdn: 0,
|
||||||
@@ -290,7 +290,7 @@ pub unsafe fn dc_mimefactory_load_mdn<'a>(
|
|||||||
loaded: DC_MF_NOTHING_LOADED,
|
loaded: DC_MF_NOTHING_LOADED,
|
||||||
msg,
|
msg,
|
||||||
chat: None,
|
chat: None,
|
||||||
increation: 0,
|
increation: false,
|
||||||
in_reply_to: ptr::null_mut(),
|
in_reply_to: ptr::null_mut(),
|
||||||
references: ptr::null_mut(),
|
references: ptr::null_mut(),
|
||||||
req_mdn: 0,
|
req_mdn: 0,
|
||||||
@@ -334,11 +334,7 @@ pub unsafe fn dc_mimefactory_load_mdn<'a>(
|
|||||||
Ok(factory)
|
Ok(factory)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO should return bool /rtn
|
pub unsafe fn dc_mimefactory_render(context: &Context, factory: &mut dc_mimefactory_t) -> bool {
|
||||||
pub unsafe fn dc_mimefactory_render(
|
|
||||||
context: &Context,
|
|
||||||
factory: &mut dc_mimefactory_t,
|
|
||||||
) -> libc::c_int {
|
|
||||||
let subject: *mut mailimf_subject;
|
let subject: *mut mailimf_subject;
|
||||||
let mut ok_to_continue = true;
|
let mut ok_to_continue = true;
|
||||||
let imf_fields: *mut mailimf_fields;
|
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 subject_str: *mut libc::c_char = ptr::null_mut();
|
||||||
let mut afwd_email: libc::c_int = 0;
|
let mut afwd_email: libc::c_int = 0;
|
||||||
let mut col: 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 parts: libc::c_int = 0;
|
||||||
let mut e2ee_guaranteed: libc::c_int = 0;
|
let mut e2ee_guaranteed: libc::c_int = 0;
|
||||||
let mut min_verified: 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);
|
factory.out = mmap_string_new(b"\x00" as *const u8 as *const libc::c_char);
|
||||||
mailmime_write_mem(factory.out, &mut col, message);
|
mailmime_write_mem(factory.out, &mut col, message);
|
||||||
success = 1;
|
success = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1033,14 +1033,12 @@ unsafe fn dc_mimeparser_add_single_part_if_known(
|
|||||||
|| (*mime_data).dt_data.dt_text.dt_length <= 0)
|
|| (*mime_data).dt_data.dt_text.dt_length <= 0)
|
||||||
{
|
{
|
||||||
/* regard `Content-Transfer-Encoding:` */
|
/* regard `Content-Transfer-Encoding:` */
|
||||||
if !(0
|
if mailmime_transfer_decode(
|
||||||
== mailmime_transfer_decode(
|
|
||||||
mime,
|
mime,
|
||||||
&mut decoded_data,
|
&mut decoded_data,
|
||||||
&mut decoded_data_bytes,
|
&mut decoded_data_bytes,
|
||||||
&mut transfer_decoding_buffer,
|
&mut transfer_decoding_buffer,
|
||||||
))
|
) {
|
||||||
{
|
|
||||||
/* no always error - but no data */
|
/* no always error - but no data */
|
||||||
match mime_type {
|
match mime_type {
|
||||||
60 | 70 => {
|
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);
|
parser.parts.push(part);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO should return bool /rtn
|
|
||||||
pub unsafe fn mailmime_transfer_decode(
|
pub unsafe fn mailmime_transfer_decode(
|
||||||
mime: *mut mailmime,
|
mime: *mut mailmime,
|
||||||
ret_decoded_data: *mut *const libc::c_char,
|
ret_decoded_data: *mut *const libc::c_char,
|
||||||
ret_decoded_data_bytes: *mut size_t,
|
ret_decoded_data_bytes: *mut size_t,
|
||||||
ret_to_mmap_string_unref: *mut *mut libc::c_char,
|
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 mut mime_transfer_encoding: libc::c_int = MAILMIME_MECHANISM_BINARY as libc::c_int;
|
||||||
let mime_data: *mut mailmime_data;
|
let mime_data: *mut mailmime_data;
|
||||||
/* must not be free()'d */
|
/* must not be free()'d */
|
||||||
@@ -1374,7 +1371,7 @@ pub unsafe fn mailmime_transfer_decode(
|
|||||||
|| *ret_decoded_data_bytes != 0
|
|| *ret_decoded_data_bytes != 0
|
||||||
|| !(*ret_to_mmap_string_unref).is_null()
|
|| !(*ret_to_mmap_string_unref).is_null()
|
||||||
{
|
{
|
||||||
return 0i32;
|
return false;
|
||||||
}
|
}
|
||||||
mime_data = (*mime).mm_data.mm_single;
|
mime_data = (*mime).mm_data.mm_single;
|
||||||
if !(*mime).mm_mime_fields.is_null() {
|
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 = (*mime_data).dt_data.dt_text.dt_data;
|
||||||
decoded_data_bytes = (*mime_data).dt_data.dt_text.dt_length;
|
decoded_data_bytes = (*mime_data).dt_data.dt_text.dt_length;
|
||||||
if decoded_data.is_null() || decoded_data_bytes <= 0 {
|
if decoded_data.is_null() || decoded_data_bytes <= 0 {
|
||||||
return 0i32;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let r: libc::c_int;
|
let r: libc::c_int;
|
||||||
@@ -1425,7 +1422,7 @@ pub unsafe fn mailmime_transfer_decode(
|
|||||||
|| transfer_decoding_buffer.is_null()
|
|| transfer_decoding_buffer.is_null()
|
||||||
|| decoded_data_bytes <= 0
|
|| decoded_data_bytes <= 0
|
||||||
{
|
{
|
||||||
return 0i32;
|
return false;
|
||||||
}
|
}
|
||||||
decoded_data = transfer_decoding_buffer
|
decoded_data = transfer_decoding_buffer
|
||||||
}
|
}
|
||||||
@@ -1433,7 +1430,7 @@ pub unsafe fn mailmime_transfer_decode(
|
|||||||
*ret_decoded_data_bytes = decoded_data_bytes;
|
*ret_decoded_data_bytes = decoded_data_bytes;
|
||||||
*ret_to_mmap_string_unref = transfer_decoding_buffer;
|
*ret_to_mmap_string_unref = transfer_decoding_buffer;
|
||||||
|
|
||||||
1
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn dc_mimeparser_is_mailinglist_message(mimeparser: &dc_mimeparser_t) -> bool {
|
pub unsafe fn dc_mimeparser_is_mailinglist_message(mimeparser: &dc_mimeparser_t) -> bool {
|
||||||
|
|||||||
@@ -831,7 +831,7 @@ unsafe fn handle_reports(
|
|||||||
let mut report_body_bytes = 0;
|
let mut report_body_bytes = 0;
|
||||||
let mut to_mmap_string_unref = std::ptr::null_mut();
|
let mut to_mmap_string_unref = std::ptr::null_mut();
|
||||||
|
|
||||||
if 0 != mailmime_transfer_decode(
|
if mailmime_transfer_decode(
|
||||||
report_data,
|
report_data,
|
||||||
&mut report_body,
|
&mut report_body,
|
||||||
&mut report_body_bytes,
|
&mut report_body_bytes,
|
||||||
|
|||||||
@@ -1093,15 +1093,12 @@ Sent with my Delta Chat Messenger: https://delta.chat";
|
|||||||
let mut decoded_data_bytes = 0;
|
let mut decoded_data_bytes = 0;
|
||||||
let mut transfer_decoding_buffer: *mut libc::c_char = ptr::null_mut();
|
let mut transfer_decoding_buffer: *mut libc::c_char = ptr::null_mut();
|
||||||
|
|
||||||
assert_eq!(
|
assert!(mailmime_transfer_decode(
|
||||||
mailmime_transfer_decode(
|
|
||||||
msg1,
|
msg1,
|
||||||
&mut decoded_data,
|
&mut decoded_data,
|
||||||
&mut decoded_data_bytes,
|
&mut decoded_data_bytes,
|
||||||
&mut transfer_decoding_buffer,
|
&mut transfer_decoding_buffer,
|
||||||
),
|
));
|
||||||
1
|
|
||||||
);
|
|
||||||
println!(
|
println!(
|
||||||
"{:?}",
|
"{:?}",
|
||||||
String::from_utf8_lossy(std::slice::from_raw_parts(
|
String::from_utf8_lossy(std::slice::from_raw_parts(
|
||||||
|
|||||||
@@ -680,7 +680,7 @@ pub unsafe fn job_send_msg(context: &Context, msg_id: uint32_t) -> libc::c_int {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* create message */
|
/* 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));
|
dc_set_msg_failed(context, msg_id, as_opt_str(mimefactory.error));
|
||||||
} else if 0
|
} else if 0
|
||||||
!= mimefactory
|
!= 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) {
|
fn send_mdn(context: &Context, msg_id: uint32_t) {
|
||||||
if let Ok(mut mimefactory) = unsafe { dc_mimefactory_load_mdn(context, msg_id) } {
|
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);
|
add_smtp_job(context, Action::SendMdn, &mut mimefactory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ impl Lot {
|
|||||||
self.text1 = Some(context.stock_str(StockMessage::Draft).to_owned().into());
|
self.text1 = Some(context.stock_str(StockMessage::Draft).to_owned().into());
|
||||||
self.text1_meaning = Meaning::Text1Draft;
|
self.text1_meaning = Meaning::Text1Draft;
|
||||||
} else if msg.from_id == DC_CONTACT_ID_SELF {
|
} 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 = None;
|
||||||
self.text1_meaning = Meaning::None;
|
self.text1_meaning = Meaning::None;
|
||||||
} else {
|
} else {
|
||||||
@@ -95,7 +95,7 @@ impl Lot {
|
|||||||
self.text1_meaning = Meaning::Text1Self;
|
self.text1_meaning = Meaning::Text1Self;
|
||||||
}
|
}
|
||||||
} else if chat.typ == Chattype::Group || chat.typ == Chattype::VerifiedGroup {
|
} 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 = None;
|
||||||
self.text1_meaning = Meaning::None;
|
self.text1_meaning = Meaning::None;
|
||||||
} else {
|
} else {
|
||||||
@@ -699,13 +699,8 @@ pub fn dc_msg_get_duration(msg: &Message) -> libc::c_int {
|
|||||||
msg.param.get_int(Param::Duration).unwrap_or_default()
|
msg.param.get_int(Param::Duration).unwrap_or_default()
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO should return bool /rtn
|
pub fn dc_msg_get_showpadlock(msg: &Message) -> bool {
|
||||||
pub fn dc_msg_get_showpadlock(msg: &Message) -> libc::c_int {
|
msg.param.get_int(Param::GuranteeE2ee).unwrap_or_default() != 0
|
||||||
if msg.param.get_int(Param::GuranteeE2ee).unwrap_or_default() != 0 {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dc_msg_get_summary(context: &Context, msg: &mut Message, chat: Option<&Chat>) -> Lot {
|
pub fn dc_msg_get_summary(context: &Context, msg: &mut Message, chat: Option<&Chat>) -> Lot {
|
||||||
@@ -825,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
|
(sort_timestamp / 86400 != send_timestamp / 86400) as libc::c_int
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO should return bool /rtn
|
pub fn dc_msg_is_sent(msg: &Message) -> bool {
|
||||||
pub fn dc_msg_is_sent(msg: &Message) -> libc::c_int {
|
msg.state as i32 >= MessageState::OutDelivered as i32
|
||||||
if msg.state as i32 >= MessageState::OutDelivered as i32 {
|
|
||||||
1
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dc_msg_is_starred(msg: &Message) -> bool {
|
pub fn dc_msg_is_starred(msg: &Message) -> bool {
|
||||||
msg.starred
|
msg.starred
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO should return bool /rtn
|
pub fn dc_msg_is_forwarded(msg: &Message) -> bool {
|
||||||
pub fn dc_msg_is_forwarded(msg: &Message) -> libc::c_int {
|
0 != msg.param.get_int(Param::Forwarded).unwrap_or_default()
|
||||||
if 0 != msg.param.get_int(Param::Forwarded).unwrap_or_default() {
|
|
||||||
1
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO should return bool /rtn
|
pub fn dc_msg_is_info(msg: &Message) -> bool {
|
||||||
pub fn dc_msg_is_info(msg: &Message) -> libc::c_int {
|
|
||||||
let cmd = msg.param.get_int(Param::Cmd).unwrap_or_default();
|
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
|
|| msg.to_id == 2i32 as libc::c_uint
|
||||||
|| 0 != cmd && cmd != 6i32
|
|| 0 != cmd && cmd != 6i32
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO should return bool /rtn
|
pub fn dc_msg_is_increation(msg: &Message) -> bool {
|
||||||
pub fn dc_msg_is_increation(msg: &Message) -> libc::c_int {
|
chat::msgtype_has_file(msg.type_0) && msg.state == MessageState::OutPreparing
|
||||||
if chat::msgtype_has_file(msg.type_0) && msg.state == MessageState::OutPreparing {
|
|
||||||
1
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dc_msg_is_setupmessage(msg: &Message) -> bool {
|
pub fn dc_msg_is_setupmessage(msg: &Message) -> bool {
|
||||||
|
|||||||
Reference in New Issue
Block a user