mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
New version of clippy has a lot of new lints
Lots of new clippy lints due to toolchain upgrade. Made the Message::error field pub(crate) again, it was the odd one out and it seemed a reasonable way to shut up clippy.
This commit is contained in:
@@ -1555,10 +1555,9 @@ pub unsafe extern "C" fn dc_create_contact(
|
||||
let name = to_string_lossy(name);
|
||||
|
||||
block_on(async move {
|
||||
match Contact::create(&ctx, name, to_string_lossy(addr)).await {
|
||||
Ok(id) => id,
|
||||
Err(_) => 0,
|
||||
}
|
||||
Contact::create(&ctx, name, to_string_lossy(addr))
|
||||
.await
|
||||
.unwrap_or(0)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -256,9 +256,11 @@ impl ChatId {
|
||||
};
|
||||
|
||||
if promote {
|
||||
let mut msg = Message::default();
|
||||
msg.viewtype = Viewtype::Text;
|
||||
msg.text = Some(msg_text);
|
||||
let mut msg = Message {
|
||||
viewtype: Viewtype::Text,
|
||||
text: Some(msg_text),
|
||||
..Default::default()
|
||||
};
|
||||
msg.param.set_cmd(cmd);
|
||||
send_msg(context, self, &mut msg).await?;
|
||||
} else {
|
||||
|
||||
@@ -428,7 +428,7 @@ async fn decrypt_setup_file<T: std::io::Read + std::io::Seek>(
|
||||
pub fn normalize_setup_code(s: &str) -> String {
|
||||
let mut out = String::new();
|
||||
for c in s.chars() {
|
||||
if c >= '0' && c <= '9' {
|
||||
if ('0'..='9').contains(&c) {
|
||||
out.push(c);
|
||||
if let 4 | 9 | 14 | 19 | 24 | 29 | 34 | 39 = out.len() {
|
||||
out += "-"
|
||||
|
||||
@@ -407,7 +407,7 @@ impl std::str::FromStr for Fingerprint {
|
||||
let hex_repr: String = input
|
||||
.to_uppercase()
|
||||
.chars()
|
||||
.filter(|&c| c >= '0' && c <= '9' || c >= 'A' && c <= 'F')
|
||||
.filter(|&c| ('0'..='9').contains(&c) || ('A'..='F').contains(&c))
|
||||
.collect();
|
||||
let v: Vec<u8> = hex::decode(hex_repr)?;
|
||||
let fp = Fingerprint::new(v)?;
|
||||
|
||||
106
src/message.rs
106
src/message.rs
@@ -310,16 +310,16 @@ pub struct Message {
|
||||
pub(crate) mime_modified: bool,
|
||||
pub(crate) chat_blocked: Blocked,
|
||||
pub(crate) location_id: u32,
|
||||
error: Option<String>,
|
||||
pub(crate) error: Option<String>,
|
||||
pub(crate) param: Params,
|
||||
}
|
||||
|
||||
impl Message {
|
||||
pub fn new(viewtype: Viewtype) -> Self {
|
||||
let mut msg = Message::default();
|
||||
msg.viewtype = viewtype;
|
||||
|
||||
msg
|
||||
Message {
|
||||
viewtype,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn load_from_db(context: &Context, id: MsgId) -> Result<Message, Error> {
|
||||
@@ -360,55 +360,53 @@ impl Message {
|
||||
),
|
||||
paramsv![id],
|
||||
|row| {
|
||||
let mut msg = Message::default();
|
||||
// msg.id = row.get::<_, AnyMsgId>("id")?;
|
||||
msg.id = row.get("id")?;
|
||||
msg.rfc724_mid = row.get::<_, String>("rfc724mid")?;
|
||||
msg.in_reply_to = row.get::<_, Option<String>>("mime_in_reply_to")?;
|
||||
msg.server_folder = row.get::<_, Option<String>>("server_folder")?;
|
||||
msg.server_uid = row.get("server_uid")?;
|
||||
msg.chat_id = row.get("chat_id")?;
|
||||
msg.from_id = row.get("from_id")?;
|
||||
msg.to_id = row.get("to_id")?;
|
||||
msg.timestamp_sort = row.get("timestamp")?;
|
||||
msg.timestamp_sent = row.get("timestamp_sent")?;
|
||||
msg.timestamp_rcvd = row.get("timestamp_rcvd")?;
|
||||
msg.ephemeral_timer = row.get("ephemeral_timer")?;
|
||||
msg.ephemeral_timestamp = row.get("ephemeral_timestamp")?;
|
||||
msg.viewtype = row.get("type")?;
|
||||
msg.state = row.get("state")?;
|
||||
let error: String = row.get("error")?;
|
||||
msg.error = Some(error).filter(|error| !error.is_empty());
|
||||
msg.is_dc_message = row.get("msgrmsg")?;
|
||||
msg.mime_modified = row.get("mime_modified")?;
|
||||
|
||||
let text;
|
||||
if let rusqlite::types::ValueRef::Text(buf) = row.get_raw("txt") {
|
||||
if let Ok(t) = String::from_utf8(buf.to_vec()) {
|
||||
text = t;
|
||||
} else {
|
||||
warn!(
|
||||
context,
|
||||
concat!(
|
||||
"dc_msg_load_from_db: could not get ",
|
||||
"text column as non-lossy utf8 id {}"
|
||||
),
|
||||
id
|
||||
);
|
||||
text = String::from_utf8_lossy(buf).into_owned();
|
||||
let text = match row.get_raw("txt") {
|
||||
rusqlite::types::ValueRef::Text(buf) => {
|
||||
match String::from_utf8(buf.to_vec()) {
|
||||
Ok(t) => t,
|
||||
Err(_) => {
|
||||
warn!(
|
||||
context,
|
||||
concat!(
|
||||
"dc_msg_load_from_db: could not get ",
|
||||
"text column as non-lossy utf8 id {}"
|
||||
),
|
||||
id
|
||||
);
|
||||
String::from_utf8_lossy(buf).into_owned()
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
text = "".to_string();
|
||||
}
|
||||
msg.text = Some(text);
|
||||
|
||||
msg.param = row.get::<_, String>("param")?.parse().unwrap_or_default();
|
||||
msg.hidden = row.get("hidden")?;
|
||||
msg.location_id = row.get("location")?;
|
||||
msg.chat_blocked = row
|
||||
.get::<_, Option<Blocked>>("blocked")?
|
||||
.unwrap_or_default();
|
||||
|
||||
_ => String::new(),
|
||||
};
|
||||
let msg = Message {
|
||||
id: row.get("id")?,
|
||||
rfc724_mid: row.get::<_, String>("rfc724mid")?,
|
||||
in_reply_to: row.get::<_, Option<String>>("mime_in_reply_to")?,
|
||||
server_folder: row.get::<_, Option<String>>("server_folder")?,
|
||||
server_uid: row.get("server_uid")?,
|
||||
chat_id: row.get("chat_id")?,
|
||||
from_id: row.get("from_id")?,
|
||||
to_id: row.get("to_id")?,
|
||||
timestamp_sort: row.get("timestamp")?,
|
||||
timestamp_sent: row.get("timestamp_sent")?,
|
||||
timestamp_rcvd: row.get("timestamp_rcvd")?,
|
||||
ephemeral_timer: row.get("ephemeral_timer")?,
|
||||
ephemeral_timestamp: row.get("ephemeral_timestamp")?,
|
||||
viewtype: row.get("type")?,
|
||||
state: row.get("state")?,
|
||||
error: Some(row.get::<_, String>("error")?)
|
||||
.filter(|error| !error.is_empty()),
|
||||
is_dc_message: row.get("msgrmsg")?,
|
||||
mime_modified: row.get("mime_modified")?,
|
||||
text: Some(text),
|
||||
param: row.get::<_, String>("param")?.parse().unwrap_or_default(),
|
||||
hidden: row.get("hidden")?,
|
||||
location_id: row.get("location")?,
|
||||
chat_blocked: row
|
||||
.get::<_, Option<Blocked>>("blocked")?
|
||||
.unwrap_or_default(),
|
||||
};
|
||||
Ok(msg)
|
||||
},
|
||||
)
|
||||
@@ -1205,7 +1203,7 @@ pub async fn get_msg_info(context: &Context, msg_id: MsgId) -> String {
|
||||
ret += &format!("\nMessage-ID: {}", msg.rfc724_mid);
|
||||
}
|
||||
if let Some(ref server_folder) = msg.server_folder {
|
||||
if server_folder != "" {
|
||||
if !server_folder.is_empty() {
|
||||
ret += &format!("\nLast seen as: {}/{}", server_folder, msg.server_uid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -864,8 +864,10 @@ impl<'a, 'b> MimeFactory<'a, 'b> {
|
||||
|
||||
if let Some(grpimage) = grpimage {
|
||||
info!(self.context, "setting group image '{}'", grpimage);
|
||||
let mut meta = Message::default();
|
||||
meta.viewtype = Viewtype::Image;
|
||||
let mut meta = Message {
|
||||
viewtype: Viewtype::Image,
|
||||
..Default::default()
|
||||
};
|
||||
meta.param.set(Param::File, grpimage);
|
||||
|
||||
let (mail, filename_as_sent) = build_body_file(context, &meta, "group-image").await?;
|
||||
|
||||
@@ -438,8 +438,10 @@ impl MimeMessage {
|
||||
// Besides, we want to show something in case our incoming-processing
|
||||
// failed to properly handle an incoming message.
|
||||
if self.parts.is_empty() && self.mdn_reports.is_empty() {
|
||||
let mut part = Part::default();
|
||||
part.typ = Viewtype::Text;
|
||||
let mut part = Part {
|
||||
typ: Viewtype::Text,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
if let Some(ref subject) = self.get_subject() {
|
||||
if !self.has_chat_version() {
|
||||
@@ -617,12 +619,13 @@ impl MimeMessage {
|
||||
let msg_body = context.stock_str(StockMessage::CantDecryptMsgBody).await;
|
||||
let txt = format!("[{}]", msg_body);
|
||||
|
||||
let mut part = Part::default();
|
||||
part.typ = Viewtype::Text;
|
||||
part.msg_raw = Some(txt.clone());
|
||||
part.msg = txt;
|
||||
part.error = Some("Decryption failed".to_string());
|
||||
|
||||
let part = Part {
|
||||
typ: Viewtype::Text,
|
||||
msg_raw: Some(txt.clone()),
|
||||
msg: txt,
|
||||
error: Some("Decryption failed".to_string()),
|
||||
..Default::default()
|
||||
};
|
||||
self.parts.push(part);
|
||||
|
||||
any_part_added = true;
|
||||
@@ -654,8 +657,10 @@ impl MimeMessage {
|
||||
// downloading the message again and
|
||||
// delete if automatic message deletion is
|
||||
// enabled.
|
||||
let mut part = Part::default();
|
||||
part.typ = Viewtype::Unknown;
|
||||
let part = Part {
|
||||
typ: Viewtype::Unknown,
|
||||
..Default::default()
|
||||
};
|
||||
self.parts.push(part);
|
||||
|
||||
any_part_added = true;
|
||||
@@ -783,11 +788,13 @@ impl MimeMessage {
|
||||
};
|
||||
|
||||
if !simplified_txt.is_empty() || simplified_quote.is_some() {
|
||||
let mut part = Part::default();
|
||||
part.dehtml_failed = dehtml_failed;
|
||||
part.typ = Viewtype::Text;
|
||||
part.mimetype = Some(mime_type);
|
||||
part.msg = simplified_txt;
|
||||
let mut part = Part {
|
||||
dehtml_failed,
|
||||
typ: Viewtype::Text,
|
||||
mimetype: Some(mime_type),
|
||||
msg: simplified_txt,
|
||||
..Default::default()
|
||||
};
|
||||
if let Some(quote) = simplified_quote {
|
||||
part.param.set(Param::Quote, quote);
|
||||
}
|
||||
|
||||
@@ -385,10 +385,12 @@ async fn send_handshake_msg(
|
||||
fingerprint: Option<Fingerprint>,
|
||||
grpid: impl AsRef<str>,
|
||||
) -> Result<(), SendMsgError> {
|
||||
let mut msg = Message::default();
|
||||
msg.viewtype = Viewtype::Text;
|
||||
msg.text = Some(format!("Secure-Join: {}", step));
|
||||
msg.hidden = true;
|
||||
let mut msg = Message {
|
||||
viewtype: Viewtype::Text,
|
||||
text: Some(format!("Secure-Join: {}", step)),
|
||||
hidden: true,
|
||||
..Default::default()
|
||||
};
|
||||
msg.param.set_cmd(SystemMessage::SecurejoinMessage);
|
||||
if step.is_empty() {
|
||||
msg.param.remove(Param::Arg);
|
||||
|
||||
@@ -31,7 +31,9 @@ fn remove_message_footer<'a>(lines: &'a [&str]) -> (&'a [&'a str], bool) {
|
||||
// use that only when no other footer is found
|
||||
// and if the line before is empty and the line after is not empty
|
||||
"--" => {
|
||||
if (ix == 0 || lines[ix - 1] == "") && ix != lines.len() - 1 && lines[ix + 1] != ""
|
||||
if (ix == 0 || lines[ix - 1].is_empty())
|
||||
&& ix != lines.len() - 1
|
||||
&& !lines[ix + 1].is_empty()
|
||||
{
|
||||
nearly_standard_footer = Some(ix);
|
||||
}
|
||||
|
||||
@@ -504,7 +504,7 @@ async fn log_msg(context: &Context, prefix: impl AsRef<str>, msg: &Message) {
|
||||
&contact_name,
|
||||
contact_id,
|
||||
msgtext.unwrap_or_default(),
|
||||
if msg.get_from_id() == 1 as libc::c_uint {
|
||||
if msg.get_from_id() == 1u32 {
|
||||
""
|
||||
} else if msg.get_state() == MessageState::InSeen {
|
||||
"[SEEN]"
|
||||
|
||||
Reference in New Issue
Block a user