mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
@@ -131,7 +131,7 @@ impl ContextWrapper {
|
||||
| Event::Error(msg)
|
||||
| Event::ErrorNetwork(msg)
|
||||
| Event::ErrorSelfNotInGroup(msg) => {
|
||||
let data2 = CString::new(msg).unwrap();
|
||||
let data2 = CString::new(msg).unwrap_or_default();
|
||||
ffi_cb(self, event_id, 0, data2.as_ptr() as uintptr_t)
|
||||
}
|
||||
Event::MsgsChanged { chat_id, msg_id }
|
||||
@@ -150,7 +150,7 @@ impl ContextWrapper {
|
||||
ffi_cb(self, event_id, progress as uintptr_t, 0)
|
||||
}
|
||||
Event::ImexFileWritten(file) => {
|
||||
let data1 = file.to_c_string().unwrap();
|
||||
let data1 = file.to_c_string().unwrap_or_default();
|
||||
ffi_cb(self, event_id, data1.as_ptr() as uintptr_t, 0)
|
||||
}
|
||||
Event::SecurejoinInviterProgress {
|
||||
@@ -2136,7 +2136,7 @@ pub unsafe extern "C" fn dc_chat_get_profile_image(chat: *mut dc_chat_t) -> *mut
|
||||
let ffi_context = &*ffi_chat.context;
|
||||
ffi_context
|
||||
.with_inner(|ctx| match ffi_chat.chat.get_profile_image(ctx) {
|
||||
Some(p) => p.to_str().unwrap().to_string().strdup(),
|
||||
Some(p) => p.to_str().unwrap_or_default().to_string().strdup(),
|
||||
None => ptr::null_mut(),
|
||||
})
|
||||
.unwrap_or_else(|_| ptr::null_mut())
|
||||
@@ -2481,7 +2481,7 @@ pub unsafe extern "C" fn dc_msg_get_summarytext(
|
||||
.with_inner(|ctx| {
|
||||
ffi_msg
|
||||
.message
|
||||
.get_summarytext(ctx, approx_characters.try_into().unwrap())
|
||||
.get_summarytext(ctx, approx_characters.try_into().unwrap_or_default())
|
||||
})
|
||||
.unwrap_or_default()
|
||||
.strdup()
|
||||
@@ -2773,7 +2773,7 @@ pub unsafe extern "C" fn dc_contact_get_profile_image(
|
||||
ffi_contact
|
||||
.contact
|
||||
.get_profile_image(ctx)
|
||||
.map(|p| p.to_str().unwrap().to_string().strdup())
|
||||
.map(|p| p.to_str().unwrap_or_default().to_string().strdup())
|
||||
.unwrap_or_else(|| std::ptr::null_mut())
|
||||
})
|
||||
.unwrap_or_else(|_| ptr::null_mut())
|
||||
|
||||
@@ -16,13 +16,16 @@ pub unsafe fn charconv(
|
||||
) -> libc::c_int {
|
||||
assert!(!fromcode.is_null(), "invalid fromcode");
|
||||
assert!(!s.is_null(), "invalid input string");
|
||||
if let Some(encoding) =
|
||||
charset::Charset::for_label(CStr::from_ptr(fromcode).to_str().unwrap().as_bytes())
|
||||
{
|
||||
if let Some(encoding) = charset::Charset::for_label(
|
||||
CStr::from_ptr(fromcode)
|
||||
.to_str()
|
||||
.unwrap_or_default()
|
||||
.as_bytes(),
|
||||
) {
|
||||
let data = std::slice::from_raw_parts(s as *const u8, strlen(s));
|
||||
|
||||
let (res, _, _) = encoding.decode(data);
|
||||
let res_c = CString::new(res.as_bytes()).unwrap();
|
||||
let res_c = CString::new(res.as_bytes()).unwrap_or_default();
|
||||
*result = strdup(res_c.as_ptr()) as *mut _;
|
||||
|
||||
MAIL_CHARCONV_NO_ERROR as libc::c_int
|
||||
|
||||
@@ -1598,7 +1598,7 @@ unsafe fn mailimf_date_time_write_driver(
|
||||
(*date_time).dt_sec,
|
||||
(*date_time).dt_zone,
|
||||
);
|
||||
let date_str_c = std::ffi::CString::new(date_str).unwrap();
|
||||
let date_str_c = std::ffi::CString::new(date_str).unwrap_or_default();
|
||||
let r = mailimf_string_write_driver(
|
||||
do_write,
|
||||
data,
|
||||
|
||||
@@ -848,7 +848,7 @@ pub unsafe fn mailmime_generate_boundary() -> *mut libc::c_char {
|
||||
hex::encode(&std::process::id().to_le_bytes()[..2])
|
||||
);
|
||||
|
||||
let c = std::ffi::CString::new(raw).unwrap();
|
||||
let c = std::ffi::CString::new(raw).unwrap_or_default();
|
||||
strdup(c.as_ptr())
|
||||
}
|
||||
|
||||
|
||||
@@ -338,7 +338,7 @@ unsafe fn mailmime_disposition_param_write_driver(
|
||||
4 => {
|
||||
let value = (*param).pa_data.pa_size as u32;
|
||||
let raw = format!("{}", value);
|
||||
let raw_c = std::ffi::CString::new(raw).unwrap();
|
||||
let raw_c = std::ffi::CString::new(raw).unwrap_or_default();
|
||||
sizestr = strdup(raw_c.as_ptr());
|
||||
len = strlen(b"size=\x00" as *const u8 as *const libc::c_char)
|
||||
.wrapping_add(strlen(sizestr))
|
||||
@@ -542,7 +542,7 @@ unsafe fn mailmime_version_write_driver(
|
||||
}
|
||||
|
||||
let raw = format!("{}.{}", (version >> 16) as i32, (version & 0xffff) as i32);
|
||||
let raw_c = std::ffi::CString::new(raw).unwrap();
|
||||
let raw_c = std::ffi::CString::new(raw).unwrap_or_default();
|
||||
let mut versionstr = strdup(raw_c.as_ptr());
|
||||
r = mailimf_string_write_driver(do_write, data, col, versionstr, strlen(versionstr));
|
||||
if r != MAILIMF_NO_ERROR as libc::c_int {
|
||||
@@ -1516,7 +1516,7 @@ pub unsafe fn mailmime_data_write_driver(
|
||||
1 => {
|
||||
let filename = CStr::from_ptr((*mime_data).dt_data.dt_filename)
|
||||
.to_str()
|
||||
.unwrap();
|
||||
.unwrap_or_default();
|
||||
if let Ok(file) = std::fs::File::open(filename) {
|
||||
if let Ok(mut text) = memmap::MmapOptions::new().map_copy(&file) {
|
||||
if 0 != (*mime_data).dt_encoded {
|
||||
@@ -1797,7 +1797,7 @@ pub unsafe fn mailmime_quoted_printable_write_driver(
|
||||
start = text.offset(i as isize).offset(1isize);
|
||||
|
||||
let raw = format!("={:02X}", (ch as libc::c_int));
|
||||
let raw_c = std::ffi::CString::new(raw).unwrap();
|
||||
let raw_c = std::ffi::CString::new(raw).unwrap_or_default();
|
||||
let mut hexstr = strdup(raw_c.as_ptr());
|
||||
r = mailimf_string_write_driver(
|
||||
do_write,
|
||||
@@ -1822,7 +1822,7 @@ pub unsafe fn mailmime_quoted_printable_write_driver(
|
||||
}
|
||||
start = text.offset(i as isize).offset(1isize);
|
||||
let raw = format!("={:02X}", ch as libc::c_int);
|
||||
let raw_c = std::ffi::CString::new(raw).unwrap();
|
||||
let raw_c = std::ffi::CString::new(raw).unwrap_or_default();
|
||||
let mut hexstr = strdup(raw_c.as_ptr());
|
||||
r = mailimf_string_write_driver(
|
||||
do_write,
|
||||
@@ -1866,7 +1866,7 @@ pub unsafe fn mailmime_quoted_printable_write_driver(
|
||||
}
|
||||
start = text.offset(i as isize);
|
||||
let raw = format!("={:02X}", b'\r' as i32);
|
||||
let raw_c = std::ffi::CString::new(raw).unwrap();
|
||||
let raw_c = std::ffi::CString::new(raw).unwrap_or_default();
|
||||
let mut hexstr = strdup(raw_c.as_ptr());
|
||||
r = mailimf_string_write_driver(do_write, data, col, hexstr, 3i32 as size_t);
|
||||
if r != MAILIMF_NO_ERROR as libc::c_int {
|
||||
@@ -1890,7 +1890,7 @@ pub unsafe fn mailmime_quoted_printable_write_driver(
|
||||
"={:02X}\r\n",
|
||||
*text.offset(i.wrapping_sub(1i32 as libc::size_t) as isize) as libc::c_int
|
||||
);
|
||||
let raw_c = std::ffi::CString::new(raw).unwrap();
|
||||
let raw_c = std::ffi::CString::new(raw).unwrap_or_default();
|
||||
let mut hexstr = strdup(raw_c.as_ptr());
|
||||
|
||||
r = mailimf_string_write_driver(do_write, data, col, hexstr, strlen(hexstr));
|
||||
@@ -1917,7 +1917,7 @@ pub unsafe fn mailmime_quoted_printable_write_driver(
|
||||
"={:02X}\r\n",
|
||||
*text.offset(i.wrapping_sub(2i32 as libc::size_t) as isize) as libc::c_int
|
||||
);
|
||||
let raw_c = std::ffi::CString::new(raw).unwrap();
|
||||
let raw_c = std::ffi::CString::new(raw).unwrap_or_default();
|
||||
let mut hexstr = strdup(raw_c.as_ptr());
|
||||
|
||||
r = mailimf_string_write_driver(do_write, data, col, hexstr, strlen(hexstr));
|
||||
@@ -1938,7 +1938,7 @@ pub unsafe fn mailmime_quoted_printable_write_driver(
|
||||
(*text.offset(i.wrapping_sub(2i32 as libc::size_t) as isize) as u8 as char),
|
||||
b'\r' as i32
|
||||
);
|
||||
let raw_c = std::ffi::CString::new(raw).unwrap();
|
||||
let raw_c = std::ffi::CString::new(raw).unwrap_or_default();
|
||||
let mut hexstr = strdup(raw_c.as_ptr());
|
||||
|
||||
r = mailimf_string_write_driver(do_write, data, col, hexstr, strlen(hexstr));
|
||||
|
||||
@@ -79,13 +79,16 @@ impl Aheader {
|
||||
let optional_field = unsafe { (*field).fld_data.fld_optional_field };
|
||||
if !optional_field.is_null()
|
||||
&& unsafe { !(*optional_field).fld_name.is_null() }
|
||||
&& unsafe { CStr::from_ptr((*optional_field).fld_name).to_str().unwrap() }
|
||||
== "Autocrypt"
|
||||
&& unsafe {
|
||||
CStr::from_ptr((*optional_field).fld_name)
|
||||
.to_str()
|
||||
.unwrap_or_default()
|
||||
} == "Autocrypt"
|
||||
{
|
||||
let value = unsafe {
|
||||
CStr::from_ptr((*optional_field).fld_value)
|
||||
.to_str()
|
||||
.unwrap()
|
||||
.unwrap_or_default()
|
||||
};
|
||||
|
||||
if let Ok(test) = Self::from_str(value) {
|
||||
|
||||
29
src/chat.rs
29
src/chat.rs
@@ -287,7 +287,7 @@ impl Chat {
|
||||
if self.typ == Chattype::Group || self.typ == Chattype::VerifiedGroup {
|
||||
if self.param.get_int(Param::Unpromoted).unwrap_or_default() == 1 {
|
||||
self.param.remove(Param::Unpromoted);
|
||||
self.update_param(context).unwrap();
|
||||
self.update_param(context)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1368,7 +1368,7 @@ pub(crate) fn add_contact_to_chat_ex(
|
||||
}
|
||||
if from_handshake && chat.param.get_int(Param::Unpromoted).unwrap_or_default() == 1 {
|
||||
chat.param.remove(Param::Unpromoted);
|
||||
chat.update_param(context).unwrap();
|
||||
chat.update_param(context)?;
|
||||
}
|
||||
let self_addr = context
|
||||
.get_config(Config::ConfiguredAddr)
|
||||
@@ -1503,7 +1503,7 @@ pub fn remove_contact_from_chat(
|
||||
if chat.is_promoted() {
|
||||
msg.type_0 = Viewtype::Text;
|
||||
if contact.id == DC_CONTACT_ID_SELF {
|
||||
set_group_explicitly_left(context, chat.grpid).unwrap();
|
||||
set_group_explicitly_left(context, chat.grpid)?;
|
||||
msg.text = Some(context.stock_system_msg(
|
||||
StockMessage::MsgGroupLeft,
|
||||
"",
|
||||
@@ -1712,7 +1712,7 @@ pub fn forward_msgs(context: &Context, msg_ids: &[u32], chat_id: u32) -> Result<
|
||||
let mut created_db_entries = Vec::new();
|
||||
let mut curr_timestamp: i64;
|
||||
|
||||
unarchive(context, chat_id).unwrap();
|
||||
unarchive(context, chat_id)?;
|
||||
if let Ok(mut chat) = Chat::load_from_db(context, chat_id) {
|
||||
curr_timestamp = dc_create_smeared_timestamps(context, msg_ids.len());
|
||||
let idsstr = msg_ids
|
||||
@@ -1722,18 +1722,15 @@ pub fn forward_msgs(context: &Context, msg_ids: &[u32], chat_id: u32) -> Result<
|
||||
(if i == 0 { acc } else { acc + "," }) + &n.to_string()
|
||||
});
|
||||
|
||||
let ids = context
|
||||
.sql
|
||||
.query_map(
|
||||
format!(
|
||||
"SELECT id FROM msgs WHERE id IN({}) ORDER BY timestamp,id",
|
||||
idsstr
|
||||
),
|
||||
params![],
|
||||
|row| row.get::<_, i32>(0),
|
||||
|ids| ids.collect::<Result<Vec<_>, _>>().map_err(Into::into),
|
||||
)
|
||||
.unwrap(); // TODO: better error handling
|
||||
let ids = context.sql.query_map(
|
||||
format!(
|
||||
"SELECT id FROM msgs WHERE id IN({}) ORDER BY timestamp,id",
|
||||
idsstr
|
||||
),
|
||||
params![],
|
||||
|row| row.get::<_, i32>(0),
|
||||
|ids| ids.collect::<Result<Vec<_>, _>>().map_err(Into::into),
|
||||
)?;
|
||||
|
||||
for id in ids {
|
||||
let src_msg_id = id;
|
||||
|
||||
@@ -79,7 +79,7 @@ impl Context {
|
||||
let value = match key {
|
||||
Config::Selfavatar => {
|
||||
let rel_path = self.sql.get_raw_config(self, key);
|
||||
rel_path.map(|p| dc_get_abs_path(self, &p).to_str().unwrap().to_string())
|
||||
rel_path.map(|p| dc_get_abs_path(self, &p).to_string_lossy().into_owned())
|
||||
}
|
||||
Config::SysVersion => Some((&*DC_VERSION_STR).clone()),
|
||||
Config::SysMsgsizeMaxRecommended => Some(format!("{}", 24 * 1024 * 1024 / 4 * 3)),
|
||||
|
||||
@@ -330,7 +330,7 @@ impl Context {
|
||||
Ok(ret)
|
||||
},
|
||||
)
|
||||
.unwrap()
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
|
||||
@@ -282,7 +282,7 @@ impl<'a> MimeParser<'a> {
|
||||
if self.get_last_nonmeta().is_some() {
|
||||
let mut mb_list: *mut mailimf_mailbox_list = ptr::null_mut();
|
||||
let mut index_0 = 0;
|
||||
let dn_field_c = CString::new(dn_field).unwrap();
|
||||
let dn_field_c = CString::new(dn_field).unwrap_or_default();
|
||||
|
||||
if mailimf_mailbox_list_parse(
|
||||
dn_field_c.as_ptr(),
|
||||
@@ -620,9 +620,12 @@ impl<'a> MimeParser<'a> {
|
||||
&& strcmp(charset, b"utf-8\x00" as *const u8 as *const libc::c_char) != 0i32
|
||||
&& strcmp(charset, b"UTF-8\x00" as *const u8 as *const libc::c_char) != 0i32
|
||||
{
|
||||
if let Some(encoding) =
|
||||
Charset::for_label(CStr::from_ptr(charset).to_str().unwrap().as_bytes())
|
||||
{
|
||||
if let Some(encoding) = Charset::for_label(
|
||||
CStr::from_ptr(charset)
|
||||
.to_str()
|
||||
.unwrap_or_default()
|
||||
.as_bytes(),
|
||||
) {
|
||||
let (res, _, _) = encoding.decode(&decoded_data);
|
||||
if res.is_empty() {
|
||||
/* no error - but nothing to add */
|
||||
|
||||
@@ -581,7 +581,7 @@ unsafe fn add_parts(
|
||||
);
|
||||
|
||||
// unarchive chat
|
||||
chat::unarchive(context, *chat_id).unwrap();
|
||||
chat::unarchive(context, *chat_id)?;
|
||||
|
||||
// if the mime-headers should be saved, find out its size
|
||||
// (the mime-header ends with an empty line)
|
||||
@@ -1264,7 +1264,7 @@ unsafe fn create_or_lookup_group(
|
||||
} else {
|
||||
chat.param.set(Param::ProfileImage, grpimage);
|
||||
}
|
||||
chat.update_param(context).unwrap();
|
||||
chat.update_param(context).unwrap_or_default();
|
||||
send_EVENT_CHAT_MODIFIED = 1;
|
||||
}
|
||||
}
|
||||
@@ -1575,7 +1575,7 @@ fn search_chat_ids_by_contact_ids(context: &Context, unsorted_contact_ids: &Vec<
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
).unwrap(); // TODO: better error handling
|
||||
).unwrap_or_default(); // TODO: better error handling
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1683,7 +1683,7 @@ unsafe fn dc_is_reply_to_known_message(context: &Context, mime_parser: &MimePars
|
||||
/* check if the message is a reply to a known message; the replies are identified by the Message-ID from
|
||||
`In-Reply-To`/`References:` (to support non-Delta-Clients) or from `Chat-Predecessor:` (Delta clients, see comment in dc_chat.c) */
|
||||
if let Some(optional_field) = mime_parser.lookup_optional_field("Chat-Predecessor") {
|
||||
let optional_field_c = CString::new(optional_field).unwrap();
|
||||
let optional_field_c = CString::new(optional_field).unwrap_or_default();
|
||||
if 0 != is_known_rfc724_mid(context, optional_field_c.as_ptr()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -637,7 +637,10 @@ fn dc_make_rel_path(context: &Context, path: &mut String) {
|
||||
.map(|s| path.starts_with(s))
|
||||
.unwrap_or_default()
|
||||
{
|
||||
*path = path.replace(context.get_blobdir().to_str().unwrap(), "$BLOBDIR");
|
||||
*path = path.replace(
|
||||
context.get_blobdir().to_str().unwrap_or_default(),
|
||||
"$BLOBDIR",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,8 @@ pub struct EncryptHelper {
|
||||
impl EncryptHelper {
|
||||
pub fn new(context: &Context) -> Result<EncryptHelper> {
|
||||
let prefer_encrypt =
|
||||
EncryptPreference::from_i32(context.get_config_int(Config::E2eeEnabled)).unwrap();
|
||||
EncryptPreference::from_i32(context.get_config_int(Config::E2eeEnabled))
|
||||
.unwrap_or_default();
|
||||
let addr = match context.get_config(Config::ConfiguredAddr) {
|
||||
None => {
|
||||
bail!("addr not configured!");
|
||||
|
||||
40
src/imap.rs
40
src/imap.rs
@@ -697,8 +697,16 @@ impl Imap {
|
||||
// the entry has the format `imap.mailbox.<folder>=<uidvalidity>:<lastseenuid>`
|
||||
let mut parts = entry.split(':');
|
||||
(
|
||||
parts.next().unwrap().parse().unwrap_or_else(|_| 0),
|
||||
parts.next().unwrap().parse().unwrap_or_else(|_| 0),
|
||||
parts
|
||||
.next()
|
||||
.unwrap_or_default()
|
||||
.parse()
|
||||
.unwrap_or_else(|_| 0),
|
||||
parts
|
||||
.next()
|
||||
.unwrap_or_default()
|
||||
.parse()
|
||||
.unwrap_or_else(|_| 0),
|
||||
)
|
||||
} else {
|
||||
(0, 0)
|
||||
@@ -742,7 +750,7 @@ impl Imap {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if mailbox.uid_validity.unwrap() != uid_validity {
|
||||
if mailbox.uid_validity.unwrap_or_default() != uid_validity {
|
||||
// first time this folder is selected or UIDVALIDITY has changed, init lastseenuid and save it to config
|
||||
|
||||
if mailbox.exists == 0 {
|
||||
@@ -752,7 +760,12 @@ impl Imap {
|
||||
// id we do not do this here, we'll miss the first message
|
||||
// as we will get in here again and fetch from lastseenuid+1 then
|
||||
|
||||
self.set_config_last_seen_uid(context, &folder, mailbox.uid_validity.unwrap(), 0);
|
||||
self.set_config_last_seen_uid(
|
||||
context,
|
||||
&folder,
|
||||
mailbox.uid_validity.unwrap_or_default(),
|
||||
0,
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -783,7 +796,7 @@ impl Imap {
|
||||
last_seen_uid -= 1;
|
||||
}
|
||||
|
||||
uid_validity = mailbox.uid_validity.unwrap();
|
||||
uid_validity = mailbox.uid_validity.unwrap_or_default();
|
||||
self.set_config_last_seen_uid(context, &folder, uid_validity, last_seen_uid);
|
||||
info!(
|
||||
context,
|
||||
@@ -945,7 +958,7 @@ impl Imap {
|
||||
let flags = if is_seen { DC_IMAP_SEEN } else { 0 };
|
||||
|
||||
if !is_deleted && msg.body().is_some() {
|
||||
let body = msg.body().unwrap();
|
||||
let body = msg.body().unwrap_or_default();
|
||||
unsafe {
|
||||
dc_receive_imf(context, &body, folder.as_ref(), server_uid, flags as u32);
|
||||
}
|
||||
@@ -1056,13 +1069,14 @@ impl Imap {
|
||||
let mut do_fake_idle = true;
|
||||
while do_fake_idle {
|
||||
// wait a moment: every 5 seconds in the first 3 minutes after a new message, after that every 60 seconds.
|
||||
let seconds_to_wait =
|
||||
if fake_idle_start_time.elapsed().unwrap() < Duration::new(3 * 60, 0) && !wait_long
|
||||
{
|
||||
Duration::new(5, 0)
|
||||
} else {
|
||||
Duration::new(60, 0)
|
||||
};
|
||||
let seconds_to_wait = if fake_idle_start_time.elapsed().unwrap_or_default()
|
||||
< Duration::new(3 * 60, 0)
|
||||
&& !wait_long
|
||||
{
|
||||
Duration::new(5, 0)
|
||||
} else {
|
||||
Duration::new(60, 0)
|
||||
};
|
||||
|
||||
let &(ref lock, ref cvar) = &*self.watch.clone();
|
||||
let mut watch = lock.lock().unwrap();
|
||||
|
||||
@@ -263,7 +263,7 @@ pub fn continue_key_transfer(context: &Context, msg_id: u32, setup_code: &str) -
|
||||
if msg.is_err() {
|
||||
bail!("Message is no Autocrypt Setup Message.");
|
||||
}
|
||||
let msg = msg.unwrap();
|
||||
let msg = msg.unwrap_or_default();
|
||||
ensure!(
|
||||
msg.is_setupmessage(),
|
||||
"Message is no Autocrypt Setup Message."
|
||||
@@ -346,7 +346,7 @@ fn set_self_key(
|
||||
context,
|
||||
&public_key,
|
||||
&private_key,
|
||||
self_addr.unwrap(),
|
||||
self_addr.unwrap_or_default(),
|
||||
set_default,
|
||||
&context.sql,
|
||||
) {
|
||||
@@ -682,7 +682,7 @@ fn export_backup(context: &Context, dir: impl AsRef<Path>) -> Result<()> {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
).unwrap();
|
||||
).unwrap_or_default();
|
||||
} else {
|
||||
error!(
|
||||
context,
|
||||
@@ -763,7 +763,7 @@ fn import_self_keys(context: &Context, dir: impl AsRef<Path>) -> Result<()> {
|
||||
}
|
||||
let ccontent = if let Ok(content) = dc_read_file(context, &path_plus_name) {
|
||||
key = String::from_utf8_lossy(&content).to_string();
|
||||
CString::new(content).unwrap()
|
||||
CString::new(content).unwrap_or_default()
|
||||
} else {
|
||||
continue;
|
||||
};
|
||||
|
||||
@@ -163,8 +163,8 @@ impl Key {
|
||||
|
||||
pub fn to_bytes(&self) -> Vec<u8> {
|
||||
match self {
|
||||
Key::Public(k) => k.to_bytes().unwrap(),
|
||||
Key::Secret(k) => k.to_bytes().unwrap(),
|
||||
Key::Public(k) => k.to_bytes().unwrap_or_default(),
|
||||
Key::Secret(k) => k.to_bytes().unwrap_or_default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -219,7 +219,7 @@ pub fn send_locations_to_chat(context: &Context, chat_id: u32, seconds: i64) {
|
||||
msg.text =
|
||||
Some(context.stock_system_msg(StockMessage::MsgLocationEnabled, "", "", 0));
|
||||
msg.param.set_int(Param::Cmd, 8);
|
||||
chat::send_msg(context, chat_id, &mut msg).unwrap();
|
||||
chat::send_msg(context, chat_id, &mut msg).unwrap_or_default();
|
||||
} else if 0 == seconds && is_sending_locations_before {
|
||||
let stock_str =
|
||||
context.stock_system_msg(StockMessage::MsgLocationDisabled, "", "", 0);
|
||||
@@ -615,7 +615,7 @@ pub fn job_do_DC_JOB_MAYBE_SEND_LOCATIONS(context: &Context, _job: &Job) {
|
||||
|
||||
for (chat_id, mut msg) in msgs.into_iter() {
|
||||
// TODO: better error handling
|
||||
chat::send_msg(context, chat_id as u32, &mut msg).unwrap();
|
||||
chat::send_msg(context, chat_id as u32, &mut msg).unwrap_or_default();
|
||||
}
|
||||
}
|
||||
if 0 != continue_streaming {
|
||||
|
||||
@@ -71,7 +71,7 @@ impl LoginParam {
|
||||
let key = format!("{}imap_certificate_checks", prefix);
|
||||
let imap_certificate_checks =
|
||||
if let Some(certificate_checks) = sql.get_raw_config_int(context, key) {
|
||||
num_traits::FromPrimitive::from_i32(certificate_checks).unwrap_or_default()
|
||||
num_traits::FromPrimitive::from_i32(certificate_checks).unwrap()
|
||||
} else {
|
||||
Default::default()
|
||||
};
|
||||
@@ -91,7 +91,7 @@ impl LoginParam {
|
||||
let key = format!("{}smtp_certificate_checks", prefix);
|
||||
let smtp_certificate_checks =
|
||||
if let Some(certificate_checks) = sql.get_raw_config_int(context, key) {
|
||||
num_traits::FromPrimitive::from_i32(certificate_checks).unwrap_or_default()
|
||||
num_traits::FromPrimitive::from_i32(certificate_checks).unwrap()
|
||||
} else {
|
||||
Default::default()
|
||||
};
|
||||
|
||||
@@ -524,7 +524,7 @@ pub fn get_msg_info(context: &Context, msg_id: u32) -> String {
|
||||
return ret;
|
||||
}
|
||||
|
||||
let msg = msg.unwrap();
|
||||
let msg = msg.unwrap_or_default();
|
||||
|
||||
let rawtxt: Option<String> = context.sql.query_get_value(
|
||||
context,
|
||||
@@ -536,7 +536,7 @@ pub fn get_msg_info(context: &Context, msg_id: u32) -> String {
|
||||
ret += &format!("Cannot load message #{}.", msg_id as usize);
|
||||
return ret;
|
||||
}
|
||||
let rawtxt = rawtxt.unwrap();
|
||||
let rawtxt = rawtxt.unwrap_or_default();
|
||||
let rawtxt = dc_truncate(rawtxt.trim(), 100000, false);
|
||||
|
||||
let fts = dc_timestamp_to_str(msg.get_timestamp());
|
||||
@@ -745,7 +745,7 @@ pub fn markseen_msgs(context: &Context, msg_ids: &[u32]) -> bool {
|
||||
return false;
|
||||
}
|
||||
let mut send_event = false;
|
||||
let msgs = msgs.unwrap();
|
||||
let msgs = msgs.unwrap_or_default();
|
||||
|
||||
for (id, curr_state, curr_blocked) in msgs.into_iter() {
|
||||
if curr_blocked == Blocked::Not {
|
||||
@@ -982,7 +982,7 @@ pub fn mdn_from_ext(
|
||||
context.sql.execute(
|
||||
"INSERT INTO msgs_mdns (msg_id, contact_id, timestamp_sent) VALUES (?, ?, ?);",
|
||||
params![*ret_msg_id as i32, from_id as i32, timestamp_sent],
|
||||
).unwrap(); // TODO: better error handling
|
||||
).unwrap_or_default(); // TODO: better error handling
|
||||
}
|
||||
|
||||
// Normal chat? that's quite easy.
|
||||
|
||||
@@ -695,7 +695,7 @@ impl<'a> MimeFactory<'a> {
|
||||
Ok(())
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
.unwrap_or_default();
|
||||
|
||||
let command = factory.msg.param.get_cmd();
|
||||
let msg = &factory.msg;
|
||||
@@ -900,7 +900,7 @@ fn build_body_file(
|
||||
let mime_sub = mailmime_new_empty(content, mime_fields);
|
||||
let abs_path = dc_get_abs_path(context, path_filename)
|
||||
.to_c_string()
|
||||
.unwrap();
|
||||
.unwrap_or_default();
|
||||
mailmime_set_body_file(mime_sub, dc_strdup(abs_path.as_ptr()));
|
||||
Ok((mime_sub, filename_to_send))
|
||||
}
|
||||
|
||||
@@ -122,8 +122,8 @@ impl str::FromStr for Params {
|
||||
ensure!(key.is_some(), "Missing key");
|
||||
ensure!(value.is_some(), "Missing value");
|
||||
|
||||
let key = key.unwrap().trim();
|
||||
let value = value.unwrap().trim();
|
||||
let key = key.unwrap_or_default().trim();
|
||||
let value = value.unwrap_or_default().trim();
|
||||
|
||||
if let Some(key) = Param::from_u8(key.as_bytes()[0]) {
|
||||
inner.insert(key, value.to_string());
|
||||
|
||||
@@ -210,7 +210,7 @@ pub fn dc_join_securejoin(context: &Context, qr: &str) -> u32 {
|
||||
info!(context, "Taking protocol shortcut.");
|
||||
context.bob.write().unwrap().expects = DC_VC_CONTACT_CONFIRM;
|
||||
joiner_progress!(context, chat_id_2_contact_id(context, contact_chat_id), 400);
|
||||
let own_fingerprint = get_self_fingerprint(context).unwrap();
|
||||
let own_fingerprint = get_self_fingerprint(context).unwrap_or_default();
|
||||
send_handshake_msg(
|
||||
context,
|
||||
contact_chat_id,
|
||||
@@ -291,7 +291,7 @@ fn send_handshake_msg(
|
||||
msg.param.set_int(Param::GuranteeE2ee, 1);
|
||||
}
|
||||
// TODO. handle cleanup on error
|
||||
chat::send_msg(context, contact_chat_id, &mut msg).unwrap();
|
||||
chat::send_msg(context, contact_chat_id, &mut msg).unwrap_or_default();
|
||||
}
|
||||
|
||||
fn chat_id_2_contact_id(context: &Context, contact_chat_id: u32) -> u32 {
|
||||
@@ -675,7 +675,9 @@ fn mark_peer_as_verified(context: &Context, fingerprint: impl AsRef<str>) -> Res
|
||||
if peerstate.set_verified(1, fingerprint.as_ref(), 2) {
|
||||
peerstate.prefer_encrypt = EncryptPreference::Mutual;
|
||||
peerstate.to_save = Some(ToSave::All);
|
||||
peerstate.save_to_db(&context.sql, false).unwrap();
|
||||
peerstate
|
||||
.save_to_db(&context.sql, false)
|
||||
.unwrap_or_default();
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +81,10 @@ impl Smtp {
|
||||
}
|
||||
let user = &lp.send_user;
|
||||
|
||||
lettre::smtp::authentication::Credentials::new(user.to_string(), access_token.unwrap())
|
||||
lettre::smtp::authentication::Credentials::new(
|
||||
user.to_string(),
|
||||
access_token.unwrap_or_default(),
|
||||
)
|
||||
} else {
|
||||
// plain
|
||||
let user = lp.send_user.clone();
|
||||
|
||||
@@ -118,7 +118,7 @@ impl StockMessage {
|
||||
///
|
||||
/// These could be used in logging calls, so no logging here.
|
||||
fn fallback(&self) -> &'static str {
|
||||
self.get_str("fallback").unwrap()
|
||||
self.get_str("fallback").unwrap_or_default()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ pub fn get_ct_subtype(mime: *mut Mailmime) -> Option<String> {
|
||||
|
||||
pub fn parse_message_id(message_id: &str) -> Result<String, Error> {
|
||||
let mut dummy = 0;
|
||||
let c_message_id = CString::new(message_id).unwrap();
|
||||
let c_message_id = CString::new(message_id).unwrap_or_default();
|
||||
let c_ptr = c_message_id.as_ptr();
|
||||
let mut rfc724_mid_c = std::ptr::null_mut();
|
||||
if unsafe { mailimf_msg_id_parse(c_ptr, libc::strlen(c_ptr), &mut dummy, &mut rfc724_mid_c) }
|
||||
@@ -448,8 +448,8 @@ pub fn append_ct_param(
|
||||
value: &str,
|
||||
) -> Result<(), Error> {
|
||||
unsafe {
|
||||
let name_c = CString::new(name).unwrap();
|
||||
let value_c = CString::new(value).unwrap();
|
||||
let name_c = CString::new(name).unwrap_or_default();
|
||||
let value_c = CString::new(value).unwrap_or_default();
|
||||
|
||||
clist_append!(
|
||||
(*content).ct_parameters,
|
||||
@@ -463,7 +463,7 @@ pub fn append_ct_param(
|
||||
}
|
||||
|
||||
pub fn new_content_type(content_type: &str) -> Result<*mut mailmime_content, Error> {
|
||||
let ct = CString::new(content_type).unwrap();
|
||||
let ct = CString::new(content_type).unwrap_or_default();
|
||||
let content: *mut mailmime_content;
|
||||
// mailmime_content_new_with_str only parses but does not retain/own ct
|
||||
unsafe {
|
||||
|
||||
Reference in New Issue
Block a user