mirror of
https://github.com/chatmail/core.git
synced 2026-05-09 01:46:30 +03:00
Fix clippy warnings
This commit is contained in:
24
src/blob.rs
24
src/blob.rs
@@ -483,23 +483,23 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_suffix() {
|
fn test_suffix() {
|
||||||
let t = dummy_context();
|
let t = dummy_context();
|
||||||
let foo = BlobObject::create(&t.ctx, "foo.txt", b"hello").unwrap();
|
let blob = BlobObject::create(&t.ctx, "foo.txt", b"hello").unwrap();
|
||||||
assert_eq!(foo.suffix(), Some("txt"));
|
assert_eq!(blob.suffix(), Some("txt"));
|
||||||
let bar = BlobObject::create(&t.ctx, "bar", b"world").unwrap();
|
let blob = BlobObject::create(&t.ctx, "bar", b"world").unwrap();
|
||||||
assert_eq!(bar.suffix(), None);
|
assert_eq!(blob.suffix(), None);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_create_dup() {
|
fn test_create_dup() {
|
||||||
let t = dummy_context();
|
let t = dummy_context();
|
||||||
BlobObject::create(&t.ctx, "foo.txt", b"hello").unwrap();
|
BlobObject::create(&t.ctx, "foo.txt", b"hello").unwrap();
|
||||||
let foo = t.ctx.get_blobdir().join("foo.txt");
|
let foo_path = t.ctx.get_blobdir().join("foo.txt");
|
||||||
assert!(foo.exists());
|
assert!(foo_path.exists());
|
||||||
BlobObject::create(&t.ctx, "foo.txt", b"world").unwrap();
|
BlobObject::create(&t.ctx, "foo.txt", b"world").unwrap();
|
||||||
for dirent in fs::read_dir(t.ctx.get_blobdir()).unwrap() {
|
for dirent in fs::read_dir(t.ctx.get_blobdir()).unwrap() {
|
||||||
let fname = dirent.unwrap().file_name();
|
let fname = dirent.unwrap().file_name();
|
||||||
if fname == foo.file_name().unwrap() {
|
if fname == foo_path.file_name().unwrap() {
|
||||||
assert_eq!(fs::read(&foo).unwrap(), b"hello");
|
assert_eq!(fs::read(&foo_path).unwrap(), b"hello");
|
||||||
} else {
|
} else {
|
||||||
let name = fname.to_str().unwrap();
|
let name = fname.to_str().unwrap();
|
||||||
assert!(name.starts_with("foo"));
|
assert!(name.starts_with("foo"));
|
||||||
@@ -512,13 +512,13 @@ mod tests {
|
|||||||
fn test_double_ext_preserved() {
|
fn test_double_ext_preserved() {
|
||||||
let t = dummy_context();
|
let t = dummy_context();
|
||||||
BlobObject::create(&t.ctx, "foo.tar.gz", b"hello").unwrap();
|
BlobObject::create(&t.ctx, "foo.tar.gz", b"hello").unwrap();
|
||||||
let foo = t.ctx.get_blobdir().join("foo.tar.gz");
|
let foo_path = t.ctx.get_blobdir().join("foo.tar.gz");
|
||||||
assert!(foo.exists());
|
assert!(foo_path.exists());
|
||||||
BlobObject::create(&t.ctx, "foo.tar.gz", b"world").unwrap();
|
BlobObject::create(&t.ctx, "foo.tar.gz", b"world").unwrap();
|
||||||
for dirent in fs::read_dir(t.ctx.get_blobdir()).unwrap() {
|
for dirent in fs::read_dir(t.ctx.get_blobdir()).unwrap() {
|
||||||
let fname = dirent.unwrap().file_name();
|
let fname = dirent.unwrap().file_name();
|
||||||
if fname == foo.file_name().unwrap() {
|
if fname == foo_path.file_name().unwrap() {
|
||||||
assert_eq!(fs::read(&foo).unwrap(), b"hello");
|
assert_eq!(fs::read(&foo_path).unwrap(), b"hello");
|
||||||
} else {
|
} else {
|
||||||
let name = fname.to_str().unwrap();
|
let name = fname.to_str().unwrap();
|
||||||
println!("{}", name);
|
println!("{}", name);
|
||||||
|
|||||||
31
src/chat.rs
31
src/chat.rs
@@ -311,14 +311,13 @@ impl Chat {
|
|||||||
self.id
|
self.id
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else if self.typ == Chattype::Group
|
||||||
if self.typ == Chattype::Group || self.typ == Chattype::VerifiedGroup {
|
|| self.typ == Chattype::VerifiedGroup
|
||||||
if self.param.get_int(Param::Unpromoted).unwrap_or_default() == 1 {
|
&& self.param.get_int(Param::Unpromoted).unwrap_or_default() == 1
|
||||||
|
{
|
||||||
self.param.remove(Param::Unpromoted);
|
self.param.remove(Param::Unpromoted);
|
||||||
self.update_param(context)?;
|
self.update_param(context)?;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* check if we can guarantee E2EE for this message.
|
/* check if we can guarantee E2EE for this message.
|
||||||
if we guarantee E2EE, and circumstances change
|
if we guarantee E2EE, and circumstances change
|
||||||
@@ -375,12 +374,10 @@ impl Chat {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if can_encrypt {
|
if can_encrypt
|
||||||
if all_mutual {
|
&& (all_mutual || last_msg_in_chat_encrypted(context, &context.sql, self.id))
|
||||||
|
{
|
||||||
do_guarantee_e2ee = true;
|
do_guarantee_e2ee = true;
|
||||||
} else if last_msg_in_chat_encrypted(context, &context.sql, self.id) {
|
|
||||||
do_guarantee_e2ee = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if do_guarantee_e2ee {
|
if do_guarantee_e2ee {
|
||||||
@@ -419,15 +416,15 @@ impl Chat {
|
|||||||
} else if !parent_in_reply_to.is_empty() && !parent_rfc724_mid.is_empty() {
|
} else if !parent_in_reply_to.is_empty() && !parent_rfc724_mid.is_empty() {
|
||||||
new_references = format!("{} {}", parent_in_reply_to, parent_rfc724_mid);
|
new_references = format!("{} {}", parent_in_reply_to, parent_rfc724_mid);
|
||||||
} else if !parent_in_reply_to.is_empty() {
|
} else if !parent_in_reply_to.is_empty() {
|
||||||
new_references = parent_in_reply_to.clone();
|
new_references = parent_in_reply_to;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// add independent location to database
|
// add independent location to database
|
||||||
|
|
||||||
if msg.param.exists(Param::SetLatitude) {
|
if msg.param.exists(Param::SetLatitude)
|
||||||
if sql::execute(
|
&& sql::execute(
|
||||||
context,
|
context,
|
||||||
&context.sql,
|
&context.sql,
|
||||||
"INSERT INTO locations \
|
"INSERT INTO locations \
|
||||||
@@ -453,7 +450,6 @@ impl Chat {
|
|||||||
DC_CONTACT_ID_SELF as i32,
|
DC_CONTACT_ID_SELF as i32,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// add message to the database
|
// add message to the database
|
||||||
|
|
||||||
@@ -874,18 +870,15 @@ pub fn send_msg(context: &Context, chat_id: u32, msg: &mut Message) -> Result<Ms
|
|||||||
let forwards = msg.param.get(Param::PrepForwards);
|
let forwards = msg.param.get(Param::PrepForwards);
|
||||||
if let Some(forwards) = forwards {
|
if let Some(forwards) = forwards {
|
||||||
for forward in forwards.split(' ') {
|
for forward in forwards.split(' ') {
|
||||||
match forward
|
if let Ok(msg_id) = forward
|
||||||
.parse::<u32>()
|
.parse::<u32>()
|
||||||
.map_err(|_| InvalidMsgId)
|
.map_err(|_| InvalidMsgId)
|
||||||
.map(|id| MsgId::new(id))
|
.map(MsgId::new)
|
||||||
{
|
{
|
||||||
Ok(msg_id) => {
|
|
||||||
if let Ok(mut msg) = Message::load_from_db(context, msg_id) {
|
if let Ok(mut msg) = Message::load_from_db(context, msg_id) {
|
||||||
send_msg(context, 0, &mut msg)?;
|
send_msg(context, 0, &mut msg)?;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
Err(_) => (),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
msg.param.remove(Param::PrepForwards);
|
msg.param.remove(Param::PrepForwards);
|
||||||
msg.save_param_to_disk(context);
|
msg.save_param_to_disk(context);
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ fn parse_xml(in_emailaddr: &str, xml_raw: &str) -> Result<LoginParam> {
|
|||||||
// Split address into local part and domain part.
|
// Split address into local part and domain part.
|
||||||
let p = in_emailaddr
|
let p = in_emailaddr
|
||||||
.find('@')
|
.find('@')
|
||||||
.ok_or(Error::InvalidEmailAddress(in_emailaddr.to_string()))?;
|
.ok_or_else(|| Error::InvalidEmailAddress(in_emailaddr.to_string()))?;
|
||||||
let (in_emaillocalpart, in_emaildomain) = in_emailaddr.split_at(p);
|
let (in_emaillocalpart, in_emaildomain) = in_emailaddr.split_at(p);
|
||||||
let in_emaildomain = &in_emaildomain[1..];
|
let in_emaildomain = &in_emaildomain[1..];
|
||||||
|
|
||||||
@@ -130,13 +130,14 @@ pub fn moz_autoconfigure(
|
|||||||
) -> Result<LoginParam> {
|
) -> Result<LoginParam> {
|
||||||
let xml_raw = read_url(context, url)?;
|
let xml_raw = read_url(context, url)?;
|
||||||
|
|
||||||
parse_xml(¶m_in.addr, &xml_raw).map_err(|err| {
|
let res = parse_xml(¶m_in.addr, &xml_raw);
|
||||||
|
if let Err(err) = &res {
|
||||||
warn!(
|
warn!(
|
||||||
context,
|
context,
|
||||||
"Failed to parse Thunderbird autoconfiguration XML: {}", err
|
"Failed to parse Thunderbird autoconfiguration XML: {}", err
|
||||||
);
|
);
|
||||||
err.into()
|
}
|
||||||
})
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
fn moz_autoconfigure_text_cb<B: std::io::BufRead>(
|
fn moz_autoconfigure_text_cb<B: std::io::BufRead>(
|
||||||
|
|||||||
@@ -106,11 +106,6 @@ impl Default for Origin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Origin {
|
impl Origin {
|
||||||
/// Contacts that start a new "normal" chat, defaults to off.
|
|
||||||
pub fn is_start_new_chat(self) -> bool {
|
|
||||||
self as i32 >= 0x7FFFFFFF
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Contacts that are verified and known not to be spam.
|
/// Contacts that are verified and known not to be spam.
|
||||||
pub fn is_verified(self) -> bool {
|
pub fn is_verified(self) -> bool {
|
||||||
self as i32 >= 0x100
|
self as i32 >= 0x100
|
||||||
@@ -906,7 +901,7 @@ impl Contact {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Extracts first name from full name.
|
/// Extracts first name from full name.
|
||||||
fn get_first_name<'a>(full_name: &'a str) -> &'a str {
|
fn get_first_name(full_name: &str) -> &str {
|
||||||
full_name.splitn(2, ' ').next().unwrap_or_default()
|
full_name.splitn(2, ' ').next().unwrap_or_default()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -933,8 +928,8 @@ fn set_block_contact(context: &Context, contact_id: u32, new_blocking: bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let Ok(contact) = Contact::load_from_db(context, contact_id) {
|
if let Ok(contact) = Contact::load_from_db(context, contact_id) {
|
||||||
if contact.blocked != new_blocking {
|
if contact.blocked != new_blocking
|
||||||
if sql::execute(
|
&& sql::execute(
|
||||||
context,
|
context,
|
||||||
&context.sql,
|
&context.sql,
|
||||||
"UPDATE contacts SET blocked=? WHERE id=?;",
|
"UPDATE contacts SET blocked=? WHERE id=?;",
|
||||||
@@ -959,7 +954,6 @@ fn set_block_contact(context: &Context, contact_id: u32, new_blocking: bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// Normalize a name.
|
/// Normalize a name.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ pub fn dc_receive_imf(
|
|||||||
// client that relies in the SMTP server to generate one.
|
// client that relies in the SMTP server to generate one.
|
||||||
// true eg. for the Webmailer used in all-inkl-KAS
|
// true eg. for the Webmailer used in all-inkl-KAS
|
||||||
match dc_create_incoming_rfc724_mid(sent_timestamp, from_id, &to_ids) {
|
match dc_create_incoming_rfc724_mid(sent_timestamp, from_id, &to_ids) {
|
||||||
Some(x) => x.to_string(),
|
Some(x) => x,
|
||||||
None => {
|
None => {
|
||||||
error!(context, "can not create incoming rfc724_mid");
|
error!(context, "can not create incoming rfc724_mid");
|
||||||
cleanup(
|
cleanup(
|
||||||
@@ -407,10 +407,8 @@ fn add_parts(
|
|||||||
// try to create a group
|
// try to create a group
|
||||||
// (groups appear automatically only if the _sender_ is known, see core issue #54)
|
// (groups appear automatically only if the _sender_ is known, see core issue #54)
|
||||||
|
|
||||||
let create_blocked = if 0 != test_normal_chat_id
|
let create_blocked =
|
||||||
&& test_normal_chat_id_blocked == Blocked::Not
|
if 0 != test_normal_chat_id && test_normal_chat_id_blocked == Blocked::Not {
|
||||||
|| incoming_origin.is_start_new_chat()
|
|
||||||
{
|
|
||||||
Blocked::Not
|
Blocked::Not
|
||||||
} else {
|
} else {
|
||||||
Blocked::Deaddrop
|
Blocked::Deaddrop
|
||||||
@@ -442,7 +440,7 @@ fn add_parts(
|
|||||||
|
|
||||||
if *chat_id == 0 {
|
if *chat_id == 0 {
|
||||||
// try to create a normal chat
|
// try to create a normal chat
|
||||||
let create_blocked = if incoming_origin.is_start_new_chat() || *from_id == *to_id {
|
let create_blocked = if *from_id == *to_id {
|
||||||
Blocked::Not
|
Blocked::Not
|
||||||
} else {
|
} else {
|
||||||
Blocked::Deaddrop
|
Blocked::Deaddrop
|
||||||
@@ -545,8 +543,7 @@ fn add_parts(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if *chat_id == 0 {
|
if *chat_id == 0 && to_ids.is_empty() && to_self {
|
||||||
if to_ids.is_empty() && to_self {
|
|
||||||
// from_id==to_id==DC_CONTACT_ID_SELF - this is a self-sent messages,
|
// from_id==to_id==DC_CONTACT_ID_SELF - this is a self-sent messages,
|
||||||
// maybe an Autocrypt Setup Messag
|
// maybe an Autocrypt Setup Messag
|
||||||
let (id, bl) =
|
let (id, bl) =
|
||||||
@@ -560,7 +557,6 @@ fn add_parts(
|
|||||||
chat_id_blocked = Blocked::Not;
|
chat_id_blocked = Blocked::Not;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if *chat_id == 0 {
|
if *chat_id == 0 {
|
||||||
*chat_id = DC_CHAT_ID_TRASH;
|
*chat_id = DC_CHAT_ID_TRASH;
|
||||||
}
|
}
|
||||||
@@ -629,7 +625,7 @@ fn add_parts(
|
|||||||
.subject
|
.subject
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|s| s.to_string())
|
.map(|s| s.to_string())
|
||||||
.unwrap_or("".into());
|
.unwrap_or_else(|| "".into());
|
||||||
txt_raw = Some(format!("{}\n\n{}", subject, msg_raw));
|
txt_raw = Some(format!("{}\n\n{}", subject, msg_raw));
|
||||||
}
|
}
|
||||||
if mime_parser.is_system_message != SystemMessage::Unknown {
|
if mime_parser.is_system_message != SystemMessage::Unknown {
|
||||||
@@ -705,7 +701,7 @@ fn save_locations(
|
|||||||
hidden: i32,
|
hidden: i32,
|
||||||
) {
|
) {
|
||||||
if chat_id <= DC_CHAT_ID_LAST_SPECIAL {
|
if chat_id <= DC_CHAT_ID_LAST_SPECIAL {
|
||||||
return ();
|
return;
|
||||||
}
|
}
|
||||||
let mut location_id_written = false;
|
let mut location_id_written = false;
|
||||||
let mut send_event = false;
|
let mut send_event = false;
|
||||||
@@ -714,13 +710,14 @@ fn save_locations(
|
|||||||
let locations = &mime_parser.message_kml.as_ref().unwrap().locations;
|
let locations = &mime_parser.message_kml.as_ref().unwrap().locations;
|
||||||
let newest_location_id =
|
let newest_location_id =
|
||||||
location::save(context, chat_id, from_id, locations, true).unwrap_or_default();
|
location::save(context, chat_id, from_id, locations, true).unwrap_or_default();
|
||||||
if 0 != newest_location_id && 0 == hidden {
|
if 0 != newest_location_id
|
||||||
if location::set_msg_location_id(context, insert_msg_id, newest_location_id).is_ok() {
|
&& 0 == hidden
|
||||||
|
&& location::set_msg_location_id(context, insert_msg_id, newest_location_id).is_ok()
|
||||||
|
{
|
||||||
location_id_written = true;
|
location_id_written = true;
|
||||||
send_event = true;
|
send_event = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if mime_parser.location_kml.is_some() {
|
if mime_parser.location_kml.is_some() {
|
||||||
if let Some(ref addr) = mime_parser.location_kml.as_ref().unwrap().addr {
|
if let Some(ref addr) = mime_parser.location_kml.as_ref().unwrap().addr {
|
||||||
@@ -772,13 +769,11 @@ fn calc_timestamps(
|
|||||||
params![chat_id as i32, from_id as i32, *sort_timestamp],
|
params![chat_id as i32, from_id as i32, *sort_timestamp],
|
||||||
);
|
);
|
||||||
if let Some(last_msg_time) = last_msg_time {
|
if let Some(last_msg_time) = last_msg_time {
|
||||||
if last_msg_time > 0 {
|
if last_msg_time > 0 && *sort_timestamp <= last_msg_time {
|
||||||
if *sort_timestamp <= last_msg_time {
|
|
||||||
*sort_timestamp = last_msg_time + 1;
|
*sort_timestamp = last_msg_time + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if *sort_timestamp >= dc_smeared_time(context) {
|
if *sort_timestamp >= dc_smeared_time(context) {
|
||||||
*sort_timestamp = dc_create_smeared_timestamp(context);
|
*sort_timestamp = dc_create_smeared_timestamp(context);
|
||||||
}
|
}
|
||||||
@@ -916,11 +911,11 @@ fn create_or_lookup_group(
|
|||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
let field = mime_parser.lookup_field("Chat-Group-Name-Changed");
|
let field = mime_parser.lookup_field("Chat-Group-Name-Changed");
|
||||||
if field.is_some() {
|
if let Some(field) = field {
|
||||||
X_MrGrpNameChanged = 1;
|
X_MrGrpNameChanged = 1;
|
||||||
better_msg = context.stock_system_msg(
|
better_msg = context.stock_system_msg(
|
||||||
StockMessage::MsgGrpName,
|
StockMessage::MsgGrpName,
|
||||||
&field.unwrap(),
|
field,
|
||||||
if let Some(ref name) = grpname {
|
if let Some(ref name) = grpname {
|
||||||
name
|
name
|
||||||
} else {
|
} else {
|
||||||
@@ -930,8 +925,8 @@ fn create_or_lookup_group(
|
|||||||
);
|
);
|
||||||
|
|
||||||
mime_parser.is_system_message = SystemMessage::GroupNameChanged;
|
mime_parser.is_system_message = SystemMessage::GroupNameChanged;
|
||||||
} else {
|
} else if let Some(optional_field) =
|
||||||
if let Some(optional_field) = mime_parser.lookup_field("Chat-Group-Image").cloned()
|
mime_parser.lookup_field("Chat-Group-Image").cloned()
|
||||||
{
|
{
|
||||||
// fld_value is a pointer somewhere into mime_parser, must not be freed
|
// fld_value is a pointer somewhere into mime_parser, must not be freed
|
||||||
X_MrGrpImageChanged = optional_field;
|
X_MrGrpImageChanged = optional_field;
|
||||||
@@ -949,22 +944,17 @@ fn create_or_lookup_group(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
set_better_msg(mime_parser, &better_msg);
|
set_better_msg(mime_parser, &better_msg);
|
||||||
|
|
||||||
// check, if we have a chat with this group ID
|
// check, if we have a chat with this group ID
|
||||||
let (mut chat_id, chat_id_verified, _blocked) = chat::get_chat_id_by_grpid(context, &grpid);
|
let (mut chat_id, chat_id_verified, _blocked) = chat::get_chat_id_by_grpid(context, &grpid);
|
||||||
if chat_id != 0 {
|
if chat_id != 0 && chat_id_verified {
|
||||||
if chat_id_verified {
|
if let Err(err) = check_verified_properties(context, mime_parser, from_id as u32, to_ids) {
|
||||||
if let Err(err) =
|
|
||||||
check_verified_properties(context, mime_parser, from_id as u32, to_ids)
|
|
||||||
{
|
|
||||||
warn!(context, "verification problem: {}", err);
|
warn!(context, "verification problem: {}", err);
|
||||||
let s = format!("{}. See 'Info' for more details", err);
|
let s = format!("{}. See 'Info' for more details", err);
|
||||||
mime_parser.repl_msg_by_error(s);
|
mime_parser.repl_msg_by_error(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// check if the sender is a member of the existing group -
|
// check if the sender is a member of the existing group -
|
||||||
// if not, we'll recreate the group list
|
// if not, we'll recreate the group list
|
||||||
@@ -1115,14 +1105,13 @@ fn create_or_lookup_group(
|
|||||||
if skip.is_none() || !addr_cmp(&self_addr, skip.unwrap()) {
|
if skip.is_none() || !addr_cmp(&self_addr, skip.unwrap()) {
|
||||||
chat::add_to_chat_contacts_table(context, chat_id, DC_CONTACT_ID_SELF);
|
chat::add_to_chat_contacts_table(context, chat_id, DC_CONTACT_ID_SELF);
|
||||||
}
|
}
|
||||||
if from_id > DC_CHAT_ID_LAST_SPECIAL {
|
if from_id > DC_CHAT_ID_LAST_SPECIAL
|
||||||
if !Contact::addr_equals_contact(context, &self_addr, from_id as u32)
|
&& !Contact::addr_equals_contact(context, &self_addr, from_id as u32)
|
||||||
&& (skip.is_none()
|
&& (skip.is_none()
|
||||||
|| !Contact::addr_equals_contact(context, skip.unwrap(), from_id as u32))
|
|| !Contact::addr_equals_contact(context, skip.unwrap(), from_id as u32))
|
||||||
{
|
{
|
||||||
chat::add_to_chat_contacts_table(context, chat_id, from_id as u32);
|
chat::add_to_chat_contacts_table(context, chat_id, from_id as u32);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
for &to_id in to_ids.iter() {
|
for &to_id in to_ids.iter() {
|
||||||
if !Contact::addr_equals_contact(context, &self_addr, to_id)
|
if !Contact::addr_equals_contact(context, &self_addr, to_id)
|
||||||
&& (skip.is_none() || !Contact::addr_equals_contact(context, skip.unwrap(), to_id))
|
&& (skip.is_none() || !Contact::addr_equals_contact(context, skip.unwrap(), to_id))
|
||||||
@@ -1160,7 +1149,7 @@ fn create_or_lookup_group(
|
|||||||
}
|
}
|
||||||
|
|
||||||
cleanup(ret_chat_id, ret_chat_id_blocked, chat_id, chat_id_blocked);
|
cleanup(ret_chat_id, ret_chat_id_blocked, chat_id, chat_id_blocked);
|
||||||
return Ok(());
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handle groups for received messages
|
/// Handle groups for received messages
|
||||||
@@ -1352,7 +1341,7 @@ fn hex_hash(s: impl AsRef<str>) -> String {
|
|||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
fn search_chat_ids_by_contact_ids(
|
fn search_chat_ids_by_contact_ids(
|
||||||
context: &Context,
|
context: &Context,
|
||||||
unsorted_contact_ids: &Vec<u32>,
|
unsorted_contact_ids: &[u32],
|
||||||
) -> Result<Vec<u32>> {
|
) -> Result<Vec<u32>> {
|
||||||
/* searches chat_id's by the given contact IDs, may return zero, one or more chat_id's */
|
/* searches chat_id's by the given contact IDs, may return zero, one or more chat_id's */
|
||||||
let mut contact_ids = Vec::with_capacity(23);
|
let mut contact_ids = Vec::with_capacity(23);
|
||||||
@@ -1508,7 +1497,7 @@ fn check_verified_properties(
|
|||||||
|
|
||||||
fn set_better_msg(mime_parser: &mut MimeParser, better_msg: impl AsRef<str>) {
|
fn set_better_msg(mime_parser: &mut MimeParser, better_msg: impl AsRef<str>) {
|
||||||
let msg = better_msg.as_ref();
|
let msg = better_msg.as_ref();
|
||||||
if msg.len() > 0 && !mime_parser.parts.is_empty() {
|
if !msg.is_empty() && !mime_parser.parts.is_empty() {
|
||||||
let part = &mut mime_parser.parts[0];
|
let part = &mut mime_parser.parts[0];
|
||||||
if part.typ == Viewtype::Text {
|
if part.typ == Viewtype::Text {
|
||||||
part.msg = msg.to_string();
|
part.msg = msg.to_string();
|
||||||
@@ -1535,12 +1524,12 @@ fn dc_is_reply_to_known_message(context: &Context, mime_parser: &MimeParser) ->
|
|||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_known_rfc724_mid_in_list(context: &Context, mid_list: &String) -> bool {
|
fn is_known_rfc724_mid_in_list(context: &Context, mid_list: &str) -> bool {
|
||||||
if mid_list.is_empty() {
|
if mid_list.is_empty() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Ok(ids) = mailparse::addrparse(mid_list.as_str()) {
|
if let Ok(ids) = mailparse::addrparse(mid_list) {
|
||||||
for id in ids.iter() {
|
for id in ids.iter() {
|
||||||
if is_known_rfc724_mid(context, id) {
|
if is_known_rfc724_mid(context, id) {
|
||||||
return true;
|
return true;
|
||||||
@@ -1588,8 +1577,8 @@ fn dc_is_reply_to_messenger_message(context: &Context, mime_parser: &MimeParser)
|
|||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_msgrmsg_rfc724_mid_in_list(context: &Context, mid_list: &String) -> bool {
|
fn is_msgrmsg_rfc724_mid_in_list(context: &Context, mid_list: &str) -> bool {
|
||||||
if let Ok(ids) = mailparse::addrparse(mid_list.as_str()) {
|
if let Ok(ids) = mailparse::addrparse(mid_list) {
|
||||||
for id in ids.iter() {
|
for id in ids.iter() {
|
||||||
if is_msgrmsg_rfc724_mid(context, id) {
|
if is_msgrmsg_rfc724_mid(context, id) {
|
||||||
return true;
|
return true;
|
||||||
@@ -1661,7 +1650,7 @@ fn dc_add_or_lookup_contacts_by_address_list(
|
|||||||
fn add_or_lookup_contact_by_addr(
|
fn add_or_lookup_contact_by_addr(
|
||||||
context: &Context,
|
context: &Context,
|
||||||
display_name: &Option<String>,
|
display_name: &Option<String>,
|
||||||
addr: &String,
|
addr: &str,
|
||||||
origin: Origin,
|
origin: Origin,
|
||||||
ids: &mut Vec<u32>,
|
ids: &mut Vec<u32>,
|
||||||
check_self: &mut bool,
|
check_self: &mut bool,
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ impl Simplify {
|
|||||||
/**
|
/**
|
||||||
* Simplify Plain Text
|
* Simplify Plain Text
|
||||||
*/
|
*/
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case, clippy::mut_range_bound)]
|
||||||
fn simplify_plain_text(&mut self, buf_terminated: &str, is_msgrmsg: bool) -> String {
|
fn simplify_plain_text(&mut self, buf_terminated: &str, is_msgrmsg: bool) -> String {
|
||||||
/* This function ...
|
/* This function ...
|
||||||
... removes all text after the line `-- ` (footer mark)
|
... removes all text after the line `-- ` (footer mark)
|
||||||
|
|||||||
@@ -63,12 +63,6 @@ pub fn dc_needs_ext_header(to_check: impl AsRef<str>) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
to_check.chars().any(|c| {
|
to_check.chars().any(|c| {
|
||||||
!(c.is_ascii_alphanumeric()
|
!c.is_ascii_alphanumeric() && c != '-' && c != '_' && c != '.' && c != '~' && c != '%'
|
||||||
|| c == '-'
|
|
||||||
|| c == '_'
|
|
||||||
|| c == '_'
|
|
||||||
|| c == '.'
|
|
||||||
|| c == '~'
|
|
||||||
|| c == '%')
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -778,9 +778,9 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_dc_create_incoming_rfc724_mid() {
|
fn test_dc_create_incoming_rfc724_mid() {
|
||||||
let res = dc_create_incoming_rfc724_mid(123, 45, &vec![6, 7]);
|
let res = dc_create_incoming_rfc724_mid(123, 45, &[6, 7]);
|
||||||
assert_eq!(res, Some("123-45-7@stub".into()));
|
assert_eq!(res, Some("123-45-7@stub".into()));
|
||||||
let res = dc_create_incoming_rfc724_mid(123, 45, &vec![]);
|
let res = dc_create_incoming_rfc724_mid(123, 45, &[]);
|
||||||
assert_eq!(res, Some("123-45-0@stub".into()));
|
assert_eq!(res, Some("123-45-0@stub".into()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -859,15 +859,15 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_listflags_has() {
|
fn test_listflags_has() {
|
||||||
let listflags: u32 = 0x1101;
|
let listflags: u32 = 0x1101;
|
||||||
assert!(listflags_has(listflags, 0x1) == true);
|
assert!(listflags_has(listflags, 0x1));
|
||||||
assert!(listflags_has(listflags, 0x10) == false);
|
assert!(!listflags_has(listflags, 0x10));
|
||||||
assert!(listflags_has(listflags, 0x100) == true);
|
assert!(listflags_has(listflags, 0x100));
|
||||||
assert!(listflags_has(listflags, 0x1000) == true);
|
assert!(listflags_has(listflags, 0x1000));
|
||||||
let listflags: u32 = (DC_GCL_ADD_SELF | DC_GCL_VERIFIED_ONLY).try_into().unwrap();
|
let listflags: u32 = (DC_GCL_ADD_SELF | DC_GCL_VERIFIED_ONLY).try_into().unwrap();
|
||||||
assert!(listflags_has(listflags, DC_GCL_VERIFIED_ONLY) == true);
|
assert!(listflags_has(listflags, DC_GCL_VERIFIED_ONLY));
|
||||||
assert!(listflags_has(listflags, DC_GCL_ADD_SELF) == true);
|
assert!(listflags_has(listflags, DC_GCL_ADD_SELF));
|
||||||
let listflags: u32 = DC_GCL_VERIFIED_ONLY.try_into().unwrap();
|
let listflags: u32 = DC_GCL_VERIFIED_ONLY.try_into().unwrap();
|
||||||
assert!(listflags_has(listflags, DC_GCL_ADD_SELF) == false);
|
assert!(!listflags_has(listflags, DC_GCL_ADD_SELF));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -213,7 +213,7 @@ fn load_or_generate_self_public_key(context: &Context, self_addr: impl AsRef<str
|
|||||||
);
|
);
|
||||||
match pgp::create_keypair(&self_addr) {
|
match pgp::create_keypair(&self_addr) {
|
||||||
Some((public_key, private_key)) => {
|
Some((public_key, private_key)) => {
|
||||||
match dc_key_save_self_keypair(
|
if dc_key_save_self_keypair(
|
||||||
context,
|
context,
|
||||||
&public_key,
|
&public_key,
|
||||||
&private_key,
|
&private_key,
|
||||||
@@ -221,15 +221,14 @@ fn load_or_generate_self_public_key(context: &Context, self_addr: impl AsRef<str
|
|||||||
true,
|
true,
|
||||||
&context.sql,
|
&context.sql,
|
||||||
) {
|
) {
|
||||||
true => {
|
|
||||||
info!(
|
info!(
|
||||||
context,
|
context,
|
||||||
"Keypair generated in {:.3}s.",
|
"Keypair generated in {:.3}s.",
|
||||||
start.elapsed().as_secs()
|
start.elapsed().as_secs()
|
||||||
);
|
);
|
||||||
Ok(public_key)
|
Ok(public_key)
|
||||||
}
|
} else {
|
||||||
false => Err(format_err!("Failed to save keypair")),
|
Err(format_err!("Failed to save keypair"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => Err(format_err!("Failed to generate keypair")),
|
None => Err(format_err!("Failed to generate keypair")),
|
||||||
|
|||||||
38
src/imap.rs
38
src/imap.rs
@@ -114,7 +114,7 @@ const JUST_UID: &str = "(UID)";
|
|||||||
const BODY_FLAGS: &str = "(FLAGS BODY.PEEK[])";
|
const BODY_FLAGS: &str = "(FLAGS BODY.PEEK[])";
|
||||||
const SELECT_ALL: &str = "1:*";
|
const SELECT_ALL: &str = "1:*";
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Default)]
|
||||||
pub struct Imap {
|
pub struct Imap {
|
||||||
config: RwLock<ImapConfig>,
|
config: RwLock<ImapConfig>,
|
||||||
session: Mutex<Option<Session>>,
|
session: Mutex<Option<Session>>,
|
||||||
@@ -187,14 +187,7 @@ impl Default for ImapConfig {
|
|||||||
|
|
||||||
impl Imap {
|
impl Imap {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Imap {
|
Default::default()
|
||||||
session: Mutex::new(None),
|
|
||||||
config: RwLock::new(ImapConfig::default()),
|
|
||||||
interrupt: Mutex::new(None),
|
|
||||||
connected: Mutex::new(false),
|
|
||||||
skip_next_idle_wait: AtomicBool::new(false),
|
|
||||||
should_reconnect: AtomicBool::new(false),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn is_connected(&self) -> bool {
|
pub async fn is_connected(&self) -> bool {
|
||||||
@@ -233,9 +226,7 @@ impl Imap {
|
|||||||
match Client::connect_insecure((imap_server, imap_port)).await {
|
match Client::connect_insecure((imap_server, imap_port)).await {
|
||||||
Ok(client) => {
|
Ok(client) => {
|
||||||
if (server_flags & DC_LP_IMAP_SOCKET_STARTTLS) != 0 {
|
if (server_flags & DC_LP_IMAP_SOCKET_STARTTLS) != 0 {
|
||||||
let res =
|
client.secure(imap_server, config.certificate_checks).await
|
||||||
client.secure(imap_server, config.certificate_checks).await;
|
|
||||||
res
|
|
||||||
} else {
|
} else {
|
||||||
Ok(client)
|
Ok(client)
|
||||||
}
|
}
|
||||||
@@ -271,14 +262,12 @@ impl Imap {
|
|||||||
user: imap_user.into(),
|
user: imap_user.into(),
|
||||||
access_token: token,
|
access_token: token,
|
||||||
};
|
};
|
||||||
let res = client.authenticate("XOAUTH2", &auth).await;
|
client.authenticate("XOAUTH2", &auth).await
|
||||||
res
|
|
||||||
} else {
|
} else {
|
||||||
return Err(Error::OauthError);
|
return Err(Error::OauthError);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let res = client.login(imap_user, imap_pw).await;
|
client.login(imap_user, imap_pw).await
|
||||||
res
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@@ -369,7 +358,7 @@ impl Imap {
|
|||||||
if self.connect(context, ¶m) {
|
if self.connect(context, ¶m) {
|
||||||
self.ensure_configured_folders(context, true)
|
self.ensure_configured_folders(context, true)
|
||||||
} else {
|
} else {
|
||||||
Err(Error::ConnectionFailed(format!("{}", param).to_string()))
|
Err(Error::ConnectionFailed(format!("{}", param)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1398,11 +1387,7 @@ impl Imap {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn list_folders<'a>(
|
async fn list_folders(&self, session: &mut Session, context: &Context) -> Option<Vec<Name>> {
|
||||||
&self,
|
|
||||||
session: &'a mut Session,
|
|
||||||
context: &Context,
|
|
||||||
) -> Option<Vec<Name>> {
|
|
||||||
// TODO: use xlist when available
|
// TODO: use xlist when available
|
||||||
match session.list(Some(""), Some("*")).await {
|
match session.list(Some(""), Some("*")).await {
|
||||||
Ok(list) => {
|
Ok(list) => {
|
||||||
@@ -1470,7 +1455,7 @@ fn get_folder_meaning_by_name(folder_name: &Name) -> FolderMeaning {
|
|||||||
let sent_names = vec!["sent", "sent objects", "gesendet"];
|
let sent_names = vec!["sent", "sent objects", "gesendet"];
|
||||||
let lower = folder_name.name().to_lowercase();
|
let lower = folder_name.name().to_lowercase();
|
||||||
|
|
||||||
if sent_names.into_iter().find(|s| *s == lower).is_some() {
|
if sent_names.into_iter().any(|s| s == lower) {
|
||||||
FolderMeaning::SentObjects
|
FolderMeaning::SentObjects
|
||||||
} else {
|
} else {
|
||||||
FolderMeaning::Unknown
|
FolderMeaning::Unknown
|
||||||
@@ -1486,16 +1471,13 @@ fn get_folder_meaning(folder_name: &Name) -> FolderMeaning {
|
|||||||
let special_names = vec!["\\Spam", "\\Trash", "\\Drafts", "\\Junk"];
|
let special_names = vec!["\\Spam", "\\Trash", "\\Drafts", "\\Junk"];
|
||||||
|
|
||||||
for attr in folder_name.attributes() {
|
for attr in folder_name.attributes() {
|
||||||
match attr {
|
if let NameAttribute::Custom(ref label) = attr {
|
||||||
NameAttribute::Custom(ref label) => {
|
if special_names.iter().any(|s| *s == label) {
|
||||||
if special_names.iter().find(|s| *s == label).is_some() {
|
|
||||||
res = FolderMeaning::Other;
|
res = FolderMeaning::Other;
|
||||||
} else if label == "\\Sent" {
|
} else if label == "\\Sent" {
|
||||||
res = FolderMeaning::SentObjects
|
res = FolderMeaning::SentObjects
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
match res {
|
match res {
|
||||||
|
|||||||
11
src/imex.rs
11
src/imex.rs
@@ -84,8 +84,7 @@ pub fn has_backup(context: &Context, dir_name: impl AsRef<Path>) -> Result<Strin
|
|||||||
let mut newest_backup_time = 0;
|
let mut newest_backup_time = 0;
|
||||||
let mut newest_backup_path: Option<std::path::PathBuf> = None;
|
let mut newest_backup_path: Option<std::path::PathBuf> = None;
|
||||||
for dirent in dir_iter {
|
for dirent in dir_iter {
|
||||||
match dirent {
|
if let Ok(dirent) = dirent {
|
||||||
Ok(dirent) => {
|
|
||||||
let path = dirent.path();
|
let path = dirent.path();
|
||||||
let name = dirent.file_name();
|
let name = dirent.file_name();
|
||||||
let name = name.to_string_lossy();
|
let name = name.to_string_lossy();
|
||||||
@@ -104,8 +103,6 @@ pub fn has_backup(context: &Context, dir_name: impl AsRef<Path>) -> Result<Strin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(_) => (),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
match newest_backup_path {
|
match newest_backup_path {
|
||||||
Some(path) => Ok(path.to_string_lossy().into_owned()),
|
Some(path) => Ok(path.to_string_lossy().into_owned()),
|
||||||
@@ -175,7 +172,7 @@ pub fn render_setup_file(context: &Context, passphrase: &str) -> Result<String>
|
|||||||
);
|
);
|
||||||
let self_addr = e2ee::ensure_secret_key_exists(context)?;
|
let self_addr = e2ee::ensure_secret_key_exists(context)?;
|
||||||
let private_key = Key::from_self_private(context, self_addr, &context.sql)
|
let private_key = Key::from_self_private(context, self_addr, &context.sql)
|
||||||
.ok_or(format_err!("Failed to get private key."))?;
|
.ok_or_else(|| format_err!("Failed to get private key."))?;
|
||||||
let ac_headers = match context.get_config_bool(Config::E2eeEnabled) {
|
let ac_headers = match context.get_config_bool(Config::E2eeEnabled) {
|
||||||
false => None,
|
false => None,
|
||||||
true => Some(("Autocrypt-Prefer-Encrypt", "mutual")),
|
true => Some(("Autocrypt-Prefer-Encrypt", "mutual")),
|
||||||
@@ -222,7 +219,7 @@ pub fn create_setup_code(_context: &Context) -> String {
|
|||||||
for i in 0..9 {
|
for i in 0..9 {
|
||||||
loop {
|
loop {
|
||||||
random_val = rng.gen();
|
random_val = rng.gen();
|
||||||
if !(random_val as usize > 60000) {
|
if random_val as usize <= 60000 {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -548,7 +545,7 @@ fn export_backup(context: &Context, dir: impl AsRef<Path>) -> Result<()> {
|
|||||||
}
|
}
|
||||||
Ok(()) => {
|
Ok(()) => {
|
||||||
dest_sql.set_raw_config_int(context, "backup_time", now as i32)?;
|
dest_sql.set_raw_config_int(context, "backup_time", now as i32)?;
|
||||||
context.call_cb(Event::ImexFileWritten(dest_path_filename.clone()));
|
context.call_cb(Event::ImexFileWritten(dest_path_filename));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -597,7 +597,7 @@ fn set_delivered(context: &Context, msg_id: MsgId) {
|
|||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
context.call_cb(Event::MsgDelivered {
|
context.call_cb(Event::MsgDelivered {
|
||||||
chat_id: chat_id as u32,
|
chat_id: chat_id as u32,
|
||||||
msg_id: msg_id,
|
msg_id,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -192,7 +192,6 @@ impl Key {
|
|||||||
res.push(c);
|
res.push(c);
|
||||||
res
|
res
|
||||||
})
|
})
|
||||||
.to_string()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_armored_string(
|
pub fn to_armored_string(
|
||||||
|
|||||||
18
src/lib.rs
18
src/lib.rs
@@ -1,8 +1,16 @@
|
|||||||
#![deny(clippy::correctness, missing_debug_implementations)]
|
#![deny(clippy::correctness, missing_debug_implementations, clippy::all)]
|
||||||
// TODO: make all of these errors, such that clippy actually passes.
|
#![warn(
|
||||||
#![warn(clippy::all, clippy::perf, clippy::not_unsafe_ptr_arg_deref)]
|
clippy::type_complexity,
|
||||||
// This is nice, but for now just annoying.
|
clippy::cognitive_complexity,
|
||||||
#![allow(clippy::unreadable_literal)]
|
clippy::too_many_arguments,
|
||||||
|
clippy::block_in_if_condition_stmt,
|
||||||
|
clippy::large_enum_variant
|
||||||
|
)]
|
||||||
|
#![allow(
|
||||||
|
clippy::unreadable_literal,
|
||||||
|
clippy::needless_range_loop,
|
||||||
|
clippy::match_bool
|
||||||
|
)]
|
||||||
#![feature(ptr_wrapping_offset_from)]
|
#![feature(ptr_wrapping_offset_from)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ impl LoginParam {
|
|||||||
let server_flags = sql.get_raw_config_int(context, key).unwrap_or_default();
|
let server_flags = sql.get_raw_config_int(context, key).unwrap_or_default();
|
||||||
|
|
||||||
LoginParam {
|
LoginParam {
|
||||||
addr: addr.to_string(),
|
addr,
|
||||||
mail_server,
|
mail_server,
|
||||||
mail_user,
|
mail_user,
|
||||||
mail_pw,
|
mail_pw,
|
||||||
@@ -198,6 +198,7 @@ impl fmt::Display for LoginParam {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::ptr_arg)]
|
||||||
fn unset_empty(s: &String) -> Cow<String> {
|
fn unset_empty(s: &String) -> Cow<String> {
|
||||||
if s.is_empty() {
|
if s.is_empty() {
|
||||||
Cow::Owned("unset".to_string())
|
Cow::Owned("unset".to_string())
|
||||||
@@ -206,44 +207,45 @@ fn unset_empty(s: &String) -> Cow<String> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::useless_let_if_seq)]
|
||||||
fn get_readable_flags(flags: i32) -> String {
|
fn get_readable_flags(flags: i32) -> String {
|
||||||
let mut res = String::new();
|
let mut res = String::new();
|
||||||
for bit in 0..31 {
|
for bit in 0..31 {
|
||||||
if 0 != flags & 1 << bit {
|
if 0 != flags & 1 << bit {
|
||||||
let mut flag_added = 0;
|
let mut flag_added = false;
|
||||||
if 1 << bit == 0x2 {
|
if 1 << bit == 0x2 {
|
||||||
res += "OAUTH2 ";
|
res += "OAUTH2 ";
|
||||||
flag_added = 1;
|
flag_added = true;
|
||||||
}
|
}
|
||||||
if 1 << bit == 0x4 {
|
if 1 << bit == 0x4 {
|
||||||
res += "AUTH_NORMAL ";
|
res += "AUTH_NORMAL ";
|
||||||
flag_added = 1;
|
flag_added = true;
|
||||||
}
|
}
|
||||||
if 1 << bit == 0x100 {
|
if 1 << bit == 0x100 {
|
||||||
res += "IMAP_STARTTLS ";
|
res += "IMAP_STARTTLS ";
|
||||||
flag_added = 1;
|
flag_added = true;
|
||||||
}
|
}
|
||||||
if 1 << bit == 0x200 {
|
if 1 << bit == 0x200 {
|
||||||
res += "IMAP_SSL ";
|
res += "IMAP_SSL ";
|
||||||
flag_added = 1;
|
flag_added = true;
|
||||||
}
|
}
|
||||||
if 1 << bit == 0x400 {
|
if 1 << bit == 0x400 {
|
||||||
res += "IMAP_PLAIN ";
|
res += "IMAP_PLAIN ";
|
||||||
flag_added = 1;
|
flag_added = true;
|
||||||
}
|
}
|
||||||
if 1 << bit == 0x10000 {
|
if 1 << bit == 0x10000 {
|
||||||
res += "SMTP_STARTTLS ";
|
res += "SMTP_STARTTLS ";
|
||||||
flag_added = 1
|
flag_added = true;
|
||||||
}
|
}
|
||||||
if 1 << bit == 0x20000 {
|
if 1 << bit == 0x20000 {
|
||||||
res += "SMTP_SSL ";
|
res += "SMTP_SSL ";
|
||||||
flag_added = 1
|
flag_added = true;
|
||||||
}
|
}
|
||||||
if 1 << bit == 0x40000 {
|
if 1 << bit == 0x40000 {
|
||||||
res += "SMTP_PLAIN ";
|
res += "SMTP_PLAIN ";
|
||||||
flag_added = 1
|
flag_added = true;
|
||||||
}
|
}
|
||||||
if 0 == flag_added {
|
if flag_added {
|
||||||
res += &format!("{:#0x}", 1 << bit);
|
res += &format!("{:#0x}", 1 << bit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ impl MsgId {
|
|||||||
/// Whether the message ID signifies a special message.
|
/// Whether the message ID signifies a special message.
|
||||||
///
|
///
|
||||||
/// This kind of message ID can not be used for real messages.
|
/// This kind of message ID can not be used for real messages.
|
||||||
pub fn is_special(&self) -> bool {
|
pub fn is_special(self) -> bool {
|
||||||
match self.0 {
|
match self.0 {
|
||||||
0..=DC_MSG_ID_LAST_SPECIAL => true,
|
0..=DC_MSG_ID_LAST_SPECIAL => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
@@ -60,21 +60,21 @@ impl MsgId {
|
|||||||
///
|
///
|
||||||
/// When this is `true`, [MsgId::is_special] will also always be
|
/// When this is `true`, [MsgId::is_special] will also always be
|
||||||
/// `true`.
|
/// `true`.
|
||||||
pub fn is_unset(&self) -> bool {
|
pub fn is_unset(self) -> bool {
|
||||||
self.0 == 0
|
self.0 == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether the message ID is the special marker1 marker.
|
/// Whether the message ID is the special marker1 marker.
|
||||||
///
|
///
|
||||||
/// See the docs of the `dc_get_chat_msgs` C API for details.
|
/// See the docs of the `dc_get_chat_msgs` C API for details.
|
||||||
pub fn is_marker1(&self) -> bool {
|
pub fn is_marker1(self) -> bool {
|
||||||
self.0 == DC_MSG_ID_MARKER1
|
self.0 == DC_MSG_ID_MARKER1
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether the message ID is the special day marker.
|
/// Whether the message ID is the special day marker.
|
||||||
///
|
///
|
||||||
/// See the docs of the `dc_get_chat_msgs` C API for details.
|
/// See the docs of the `dc_get_chat_msgs` C API for details.
|
||||||
pub fn is_daymarker(&self) -> bool {
|
pub fn is_daymarker(self) -> bool {
|
||||||
self.0 == DC_MSG_ID_DAYMARKER
|
self.0 == DC_MSG_ID_DAYMARKER
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,7 +82,7 @@ impl MsgId {
|
|||||||
///
|
///
|
||||||
/// Avoid using this, eventually types should be cleaned up enough
|
/// Avoid using this, eventually types should be cleaned up enough
|
||||||
/// that it is no longer necessary.
|
/// that it is no longer necessary.
|
||||||
pub fn to_u32(&self) -> u32 {
|
pub fn to_u32(self) -> u32 {
|
||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -687,7 +687,7 @@ impl Lot {
|
|||||||
self.text2 = Some(get_summarytext_by_raw(
|
self.text2 = Some(get_summarytext_by_raw(
|
||||||
msg.type_0,
|
msg.type_0,
|
||||||
msg.text.as_ref(),
|
msg.text.as_ref(),
|
||||||
&mut msg.param,
|
&msg.param,
|
||||||
SUMMARY_CHARACTERS,
|
SUMMARY_CHARACTERS,
|
||||||
context,
|
context,
|
||||||
));
|
));
|
||||||
@@ -1218,9 +1218,10 @@ pub fn mdn_from_ext(
|
|||||||
} // else wait for more receipts
|
} // else wait for more receipts
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return match read_by_all {
|
return if read_by_all {
|
||||||
true => Some((chat_id, msg_id)),
|
Some((chat_id, msg_id))
|
||||||
false => None,
|
} else {
|
||||||
|
None
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
@@ -1368,50 +1369,32 @@ mod tests {
|
|||||||
some_file.set(Param::File, "foo.bar");
|
some_file.set(Param::File, "foo.bar");
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
get_summarytext_by_raw(
|
get_summarytext_by_raw(Viewtype::Text, some_text.as_ref(), &Params::new(), 50, &ctx),
|
||||||
Viewtype::Text,
|
|
||||||
some_text.as_ref(),
|
|
||||||
&mut Params::new(),
|
|
||||||
50,
|
|
||||||
&ctx
|
|
||||||
),
|
|
||||||
"bla bla" // for simple text, the type is not added to the summary
|
"bla bla" // for simple text, the type is not added to the summary
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
get_summarytext_by_raw(Viewtype::Image, no_text.as_ref(), &mut some_file, 50, &ctx,),
|
get_summarytext_by_raw(Viewtype::Image, no_text.as_ref(), &some_file, 50, &ctx,),
|
||||||
"Image" // file names are not added for images
|
"Image" // file names are not added for images
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
get_summarytext_by_raw(Viewtype::Video, no_text.as_ref(), &mut some_file, 50, &ctx,),
|
get_summarytext_by_raw(Viewtype::Video, no_text.as_ref(), &some_file, 50, &ctx,),
|
||||||
"Video" // file names are not added for videos
|
"Video" // file names are not added for videos
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
get_summarytext_by_raw(Viewtype::Gif, no_text.as_ref(), &mut some_file, 50, &ctx,),
|
get_summarytext_by_raw(Viewtype::Gif, no_text.as_ref(), &some_file, 50, &ctx,),
|
||||||
"GIF" // file names are not added for GIFs
|
"GIF" // file names are not added for GIFs
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
get_summarytext_by_raw(
|
get_summarytext_by_raw(Viewtype::Sticker, no_text.as_ref(), &some_file, 50, &ctx,),
|
||||||
Viewtype::Sticker,
|
|
||||||
no_text.as_ref(),
|
|
||||||
&mut some_file,
|
|
||||||
50,
|
|
||||||
&ctx,
|
|
||||||
),
|
|
||||||
"Sticker" // file names are not added for stickers
|
"Sticker" // file names are not added for stickers
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
get_summarytext_by_raw(
|
get_summarytext_by_raw(Viewtype::Voice, empty_text.as_ref(), &some_file, 50, &ctx,),
|
||||||
Viewtype::Voice,
|
|
||||||
empty_text.as_ref(),
|
|
||||||
&mut some_file,
|
|
||||||
50,
|
|
||||||
&ctx,
|
|
||||||
),
|
|
||||||
"Voice message" // file names are not added for voice messages, empty text is skipped
|
"Voice message" // file names are not added for voice messages, empty text is skipped
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -1421,13 +1404,7 @@ mod tests {
|
|||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
get_summarytext_by_raw(
|
get_summarytext_by_raw(Viewtype::Voice, some_text.as_ref(), &some_file, 50, &ctx),
|
||||||
Viewtype::Voice,
|
|
||||||
some_text.as_ref(),
|
|
||||||
&mut some_file,
|
|
||||||
50,
|
|
||||||
&ctx
|
|
||||||
),
|
|
||||||
"Voice message \u{2013} bla bla" // `\u{2013}` explicitly checks for "EN DASH"
|
"Voice message \u{2013} bla bla" // `\u{2013}` explicitly checks for "EN DASH"
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -1437,24 +1414,12 @@ mod tests {
|
|||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
get_summarytext_by_raw(
|
get_summarytext_by_raw(Viewtype::Audio, empty_text.as_ref(), &some_file, 50, &ctx,),
|
||||||
Viewtype::Audio,
|
|
||||||
empty_text.as_ref(),
|
|
||||||
&mut some_file,
|
|
||||||
50,
|
|
||||||
&ctx,
|
|
||||||
),
|
|
||||||
"Audio \u{2013} foo.bar" // file name is added for audio, empty text is not added
|
"Audio \u{2013} foo.bar" // file name is added for audio, empty text is not added
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
get_summarytext_by_raw(
|
get_summarytext_by_raw(Viewtype::Audio, some_text.as_ref(), &some_file, 50, &ctx),
|
||||||
Viewtype::Audio,
|
|
||||||
some_text.as_ref(),
|
|
||||||
&mut some_file,
|
|
||||||
50,
|
|
||||||
&ctx
|
|
||||||
),
|
|
||||||
"Audio \u{2013} foo.bar \u{2013} bla bla" // file name and text added for audio
|
"Audio \u{2013} foo.bar \u{2013} bla bla" // file name and text added for audio
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -131,13 +131,14 @@ impl<'a, 'b> MimeFactory<'a, 'b> {
|
|||||||
.get_config(Config::ConfiguredAddr)
|
.get_config(Config::ConfiguredAddr)
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
if !email_to_remove.is_empty() && !addr_cmp(email_to_remove, self_addr) {
|
if !email_to_remove.is_empty()
|
||||||
if !vec_contains_lowercase(&factory.recipients_addr, &email_to_remove) {
|
&& !addr_cmp(email_to_remove, self_addr)
|
||||||
|
&& !vec_contains_lowercase(&factory.recipients_addr, &email_to_remove)
|
||||||
|
{
|
||||||
factory.recipients_names.push("".to_string());
|
factory.recipients_names.push("".to_string());
|
||||||
factory.recipients_addr.push(email_to_remove.to_string());
|
factory.recipients_addr.push(email_to_remove.to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if command != SystemMessage::AutocryptSetupMessage
|
if command != SystemMessage::AutocryptSetupMessage
|
||||||
&& command != SystemMessage::SecurejoinMessage
|
&& command != SystemMessage::SecurejoinMessage
|
||||||
&& context.get_config_bool(Config::MdnsEnabled)
|
&& context.get_config_bool(Config::MdnsEnabled)
|
||||||
@@ -299,14 +300,7 @@ impl<'a, 'b> MimeFactory<'a, 'b> {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
match self.msg.param.get_cmd() {
|
self.msg.param.get_cmd() == SystemMessage::MemberAddedToGroup
|
||||||
SystemMessage::MemberAddedToGroup => {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
Loaded::MDN => false,
|
Loaded::MDN => false,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -148,11 +148,11 @@ impl<'a> MimeParser<'a> {
|
|||||||
self.subject = Some(field.clone());
|
self.subject = Some(field.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(_) = self.lookup_field("Chat-Version") {
|
if self.lookup_field("Chat-Version").is_some() {
|
||||||
self.is_send_by_messenger = true
|
self.is_send_by_messenger = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(_) = self.lookup_field("Autocrypt-Setup-Message") {
|
if self.lookup_field("Autocrypt-Setup-Message").is_some() {
|
||||||
let has_setup_file = self.parts.iter().any(|p| {
|
let has_setup_file = self.parts.iter().any(|p| {
|
||||||
p.mimetype.is_some() && p.mimetype.as_ref().unwrap().as_ref() == MIME_AC_SETUP_FILE
|
p.mimetype.is_some() && p.mimetype.as_ref().unwrap().as_ref() == MIME_AC_SETUP_FILE
|
||||||
});
|
});
|
||||||
@@ -188,8 +188,7 @@ impl<'a> MimeParser<'a> {
|
|||||||
self.is_system_message = SystemMessage::LocationStreamingEnabled;
|
self.is_system_message = SystemMessage::LocationStreamingEnabled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(_) = self.lookup_field("Chat-Group-Image") {
|
if self.lookup_field("Chat-Group-Image").is_some() && !self.parts.is_empty() {
|
||||||
if !self.parts.is_empty() {
|
|
||||||
let textpart = &self.parts[0];
|
let textpart = &self.parts[0];
|
||||||
if textpart.typ == Viewtype::Text && self.parts.len() >= 2 {
|
if textpart.typ == Viewtype::Text && self.parts.len() >= 2 {
|
||||||
let imgpart = &mut self.parts[1];
|
let imgpart = &mut self.parts[1];
|
||||||
@@ -198,7 +197,6 @@ impl<'a> MimeParser<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if self.is_send_by_messenger && self.parts.len() == 2 {
|
if self.is_send_by_messenger && self.parts.len() == 2 {
|
||||||
let need_drop = {
|
let need_drop = {
|
||||||
@@ -264,12 +262,12 @@ impl<'a> MimeParser<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if self.parts.len() == 1 {
|
if self.parts.len() == 1 {
|
||||||
if self.parts[0].typ == Viewtype::Audio {
|
if self.parts[0].typ == Viewtype::Audio
|
||||||
if let Some(_) = self.lookup_field("Chat-Voice-Message") {
|
&& self.lookup_field("Chat-Voice-Message").is_some()
|
||||||
|
{
|
||||||
let part_mut = &mut self.parts[0];
|
let part_mut = &mut self.parts[0];
|
||||||
part_mut.typ = Viewtype::Voice;
|
part_mut.typ = Viewtype::Voice;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if self.parts[0].typ == Viewtype::Image {
|
if self.parts[0].typ == Viewtype::Image {
|
||||||
if let Some(value) = self.lookup_field("Chat-Content") {
|
if let Some(value) = self.lookup_field("Chat-Content") {
|
||||||
if value == "sticker" {
|
if value == "sticker" {
|
||||||
@@ -601,7 +599,7 @@ impl<'a> MimeParser<'a> {
|
|||||||
|
|
||||||
// if there is still no filename, guess one
|
// if there is still no filename, guess one
|
||||||
if desired_filename.is_empty() {
|
if desired_filename.is_empty() {
|
||||||
if let Some(subtype) = mail.ctype.mimetype.split('/').skip(1).next() {
|
if let Some(subtype) = mail.ctype.mimetype.split('/').nth(1) {
|
||||||
desired_filename = format!("file.{}", subtype,);
|
desired_filename = format!("file.{}", subtype,);
|
||||||
} else {
|
} else {
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
@@ -626,7 +624,7 @@ impl<'a> MimeParser<'a> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
msg_type: Viewtype,
|
msg_type: Viewtype,
|
||||||
mime_type: Mime,
|
mime_type: Mime,
|
||||||
raw_mime: &String,
|
raw_mime: &str,
|
||||||
decoded_data: &[u8],
|
decoded_data: &[u8],
|
||||||
filename: &str,
|
filename: &str,
|
||||||
) {
|
) {
|
||||||
@@ -685,7 +683,7 @@ impl<'a> MimeParser<'a> {
|
|||||||
|
|
||||||
fn do_add_single_part(&mut self, mut part: Part) {
|
fn do_add_single_part(&mut self, mut part: Part) {
|
||||||
if self.encrypted {
|
if self.encrypted {
|
||||||
if self.signatures.len() > 0 {
|
if !self.signatures.is_empty() {
|
||||||
part.param.set_int(Param::GuaranteeE2ee, 1);
|
part.param.set_int(Param::GuaranteeE2ee, 1);
|
||||||
} else {
|
} else {
|
||||||
// XXX if the message was encrypted but not signed
|
// XXX if the message was encrypted but not signed
|
||||||
@@ -698,18 +696,16 @@ impl<'a> MimeParser<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_mailinglist_message(&self) -> bool {
|
pub fn is_mailinglist_message(&self) -> bool {
|
||||||
if let Some(_) = self.lookup_field("List-Id") {
|
if self.lookup_field("List-Id").is_some() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(precedence) = self.lookup_field("Precedence") {
|
if let Some(precedence) = self.lookup_field("Precedence") {
|
||||||
if precedence == "list" || precedence == "bulk" {
|
precedence == "list" || precedence == "bulk"
|
||||||
return true;
|
} else {
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn sender_equals_recipient(&self) -> bool {
|
pub fn sender_equals_recipient(&self) -> bool {
|
||||||
/* get From: and check there is exactly one sender */
|
/* get From: and check there is exactly one sender */
|
||||||
@@ -965,7 +961,7 @@ fn mailmime_is_attachment_disposition(mail: &mailparse::ParsedMail<'_>) -> bool
|
|||||||
}
|
}
|
||||||
|
|
||||||
// returned addresses are normalized.
|
// returned addresses are normalized.
|
||||||
fn get_recipients<'a, S: AsRef<str>, T: Iterator<Item = (S, S)>>(headers: T) -> HashSet<String> {
|
fn get_recipients<S: AsRef<str>, T: Iterator<Item = (S, S)>>(headers: T) -> HashSet<String> {
|
||||||
let mut recipients: HashSet<String> = Default::default();
|
let mut recipients: HashSet<String> = Default::default();
|
||||||
|
|
||||||
for (hkey, hvalue) in headers {
|
for (hkey, hvalue) in headers {
|
||||||
|
|||||||
@@ -222,7 +222,7 @@ impl Params {
|
|||||||
Some(val) => val,
|
Some(val) => val,
|
||||||
None => return Ok(None),
|
None => return Ok(None),
|
||||||
};
|
};
|
||||||
ParamsFile::from_param(context, val).map(|file| Some(file))
|
ParamsFile::from_param(context, val).map(Some)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the parameter and returns a [BlobObject] for it.
|
/// Gets the parameter and returns a [BlobObject] for it.
|
||||||
@@ -373,7 +373,7 @@ mod tests {
|
|||||||
if let ParamsFile::FsPath(p) = ParamsFile::from_param(&t.ctx, "/foo/bar/baz").unwrap() {
|
if let ParamsFile::FsPath(p) = ParamsFile::from_param(&t.ctx, "/foo/bar/baz").unwrap() {
|
||||||
assert_eq!(p, Path::new("/foo/bar/baz"));
|
assert_eq!(p, Path::new("/foo/bar/baz"));
|
||||||
} else {
|
} else {
|
||||||
assert!(false, "Wrong enum variant");
|
panic!("Wrong enum variant");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -383,7 +383,7 @@ mod tests {
|
|||||||
if let ParamsFile::Blob(b) = ParamsFile::from_param(&t.ctx, "$BLOBDIR/foo").unwrap() {
|
if let ParamsFile::Blob(b) = ParamsFile::from_param(&t.ctx, "$BLOBDIR/foo").unwrap() {
|
||||||
assert_eq!(b.as_name(), "$BLOBDIR/foo");
|
assert_eq!(b.as_name(), "$BLOBDIR/foo");
|
||||||
} else {
|
} else {
|
||||||
assert!(false, "Wrong enum variant");
|
panic!("Wrong enum variant");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -230,6 +230,7 @@ pub fn pk_encrypt(
|
|||||||
Ok(encoded_msg)
|
Ok(encoded_msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::implicit_hasher)]
|
||||||
pub fn pk_decrypt(
|
pub fn pk_decrypt(
|
||||||
ctext: &[u8],
|
ctext: &[u8],
|
||||||
private_keys_for_decryption: &Keyring,
|
private_keys_for_decryption: &Keyring,
|
||||||
|
|||||||
@@ -533,13 +533,11 @@ pub(crate) fn handle_securejoin_handshake(
|
|||||||
if group_chat_id == 0 {
|
if group_chat_id == 0 {
|
||||||
error!(context, "Chat {} not found.", &field_grpid);
|
error!(context, "Chat {} not found.", &field_grpid);
|
||||||
return Ok(ret);
|
return Ok(ret);
|
||||||
} else {
|
} else if let Err(err) =
|
||||||
if let Err(err) =
|
|
||||||
chat::add_contact_to_chat_ex(context, group_chat_id, contact_id, true)
|
chat::add_contact_to_chat_ex(context, group_chat_id, contact_id, true)
|
||||||
{
|
{
|
||||||
error!(context, "failed to add contact: {}", err);
|
error!(context, "failed to add contact: {}", err);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
send_handshake_msg(context, contact_chat_id, "vc-contact-confirm", "", None, "");
|
send_handshake_msg(context, contact_chat_id, "vc-contact-confirm", "", None, "");
|
||||||
inviter_progress!(context, contact_id, 1000);
|
inviter_progress!(context, contact_id, 1000);
|
||||||
@@ -643,7 +641,7 @@ pub(crate) fn handle_securejoin_handshake(
|
|||||||
let (group_chat_id, _, _) = chat::get_chat_id_by_grpid(context, &field_grpid);
|
let (group_chat_id, _, _) = chat::get_chat_id_by_grpid(context, &field_grpid);
|
||||||
context.call_cb(Event::SecurejoinMemberAdded {
|
context.call_cb(Event::SecurejoinMemberAdded {
|
||||||
chat_id: group_chat_id,
|
chat_id: group_chat_id,
|
||||||
contact_id: contact_id,
|
contact_id,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
warn!(context, "vg-member-added-received invalid.",);
|
warn!(context, "vg-member-added-received invalid.",);
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ pub enum Error {
|
|||||||
|
|
||||||
pub type Result<T> = std::result::Result<T, Error>;
|
pub type Result<T> = std::result::Result<T, Error>;
|
||||||
|
|
||||||
#[derive(DebugStub)]
|
#[derive(Default, DebugStub)]
|
||||||
pub struct Smtp {
|
pub struct Smtp {
|
||||||
#[debug_stub(some = "SmtpTransport")]
|
#[debug_stub(some = "SmtpTransport")]
|
||||||
transport: Option<lettre::smtp::SmtpTransport>,
|
transport: Option<lettre::smtp::SmtpTransport>,
|
||||||
@@ -45,11 +45,7 @@ pub struct Smtp {
|
|||||||
impl Smtp {
|
impl Smtp {
|
||||||
/// Create a new Smtp instances.
|
/// Create a new Smtp instances.
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Smtp {
|
Default::default()
|
||||||
transport: None,
|
|
||||||
transport_connected: false,
|
|
||||||
from: None,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Disconnect the SMTP transport and drop it entirely.
|
/// Disconnect the SMTP transport and drop it entirely.
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ impl Smtp {
|
|||||||
context,
|
context,
|
||||||
"uh? SMTP has no transport, failed to send to {}", recipients_display
|
"uh? SMTP has no transport, failed to send to {}", recipients_display
|
||||||
);
|
);
|
||||||
return Err(Error::NoTransport);
|
Err(Error::NoTransport)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
21
src/sql.rs
21
src/sql.rs
@@ -68,13 +68,19 @@ pub struct Sql {
|
|||||||
in_use: Arc<ThreadLocal<String>>,
|
in_use: Arc<ThreadLocal<String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Sql {
|
impl Default for Sql {
|
||||||
pub fn new() -> Sql {
|
fn default() -> Self {
|
||||||
Sql {
|
Self {
|
||||||
pool: RwLock::new(None),
|
pool: RwLock::new(None),
|
||||||
in_use: Arc::new(ThreadLocal::new()),
|
in_use: Arc::new(ThreadLocal::new()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Sql {
|
||||||
|
pub fn new() -> Sql {
|
||||||
|
Self::default()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn is_open(&self) -> bool {
|
pub fn is_open(&self) -> bool {
|
||||||
self.pool.read().unwrap().is_some()
|
self.pool.read().unwrap().is_some()
|
||||||
@@ -1140,10 +1146,9 @@ pub fn housekeeping(context: &Context) {
|
|||||||
|
|
||||||
unreferenced_count += 1;
|
unreferenced_count += 1;
|
||||||
|
|
||||||
match std::fs::metadata(entry.path()) {
|
if let Ok(stats) = std::fs::metadata(entry.path()) {
|
||||||
Ok(stats) => {
|
let recently_created =
|
||||||
let recently_created = stats.created().is_ok()
|
stats.created().is_ok() && stats.created().unwrap() > keep_files_newer_than;
|
||||||
&& stats.created().unwrap() > keep_files_newer_than;
|
|
||||||
let recently_modified = stats.modified().is_ok()
|
let recently_modified = stats.modified().is_ok()
|
||||||
&& stats.modified().unwrap() > keep_files_newer_than;
|
&& stats.modified().unwrap() > keep_files_newer_than;
|
||||||
let recently_accessed = stats.accessed().is_ok()
|
let recently_accessed = stats.accessed().is_ok()
|
||||||
@@ -1159,8 +1164,6 @@ pub fn housekeeping(context: &Context) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(_) => {}
|
|
||||||
}
|
|
||||||
info!(
|
info!(
|
||||||
context,
|
context,
|
||||||
"Housekeeping: Deleting unreferenced file #{}: {:?}",
|
"Housekeeping: Deleting unreferenced file #{}: {:?}",
|
||||||
|
|||||||
@@ -193,7 +193,7 @@ impl StockMessage {
|
|||||||
/// Default untranslated strings for stock messages.
|
/// Default untranslated strings for stock messages.
|
||||||
///
|
///
|
||||||
/// These could be used in logging calls, so no logging here.
|
/// These could be used in logging calls, so no logging here.
|
||||||
fn fallback(&self) -> &'static str {
|
fn fallback(self) -> &'static str {
|
||||||
self.get_str("fallback").unwrap_or_default()
|
self.get_str("fallback").unwrap_or_default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -238,7 +238,7 @@ impl Context {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.get(&(id as usize))
|
.get(&(id as usize))
|
||||||
{
|
{
|
||||||
Some(ref x) => Cow::Owned(x.to_string()),
|
Some(ref x) => Cow::Owned((*x).to_string()),
|
||||||
None => Cow::Borrowed(id.fallback()),
|
None => Cow::Borrowed(id.fallback()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ pub fn test_context(callback: Option<Box<ContextCallback>>) -> TestContext {
|
|||||||
None => Box::new(|_, _| 0),
|
None => Box::new(|_, _| 0),
|
||||||
};
|
};
|
||||||
let ctx = Context::new(cb, "FakeOs".into(), dbfile).unwrap();
|
let ctx = Context::new(cb, "FakeOs".into(), dbfile).unwrap();
|
||||||
TestContext { ctx: ctx, dir: dir }
|
TestContext { ctx, dir }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return a dummy [TestContext].
|
/// Return a dummy [TestContext].
|
||||||
|
|||||||
Reference in New Issue
Block a user