From 476e613377e8efd3528a8cfddb23c9a01b3efb3a Mon Sep 17 00:00:00 2001 From: Hocuri Date: Tue, 2 Mar 2021 12:04:53 +0100 Subject: [PATCH] Trash messages more thoroughly (#2273) Esp. remove some information for newly-arriving messages --- src/dc_receive_imf.rs | 20 ++++++++++++++------ src/ephemeral.rs | 4 +++- src/message.rs | 8 ++++++-- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/dc_receive_imf.rs b/src/dc_receive_imf.rs index b664ba80a..20e293402 100644 --- a/src/dc_receive_imf.rs +++ b/src/dc_receive_imf.rs @@ -954,26 +954,34 @@ async fn add_parts( } }; + // If you change which information is skipped if the message is trashed, + // also change `MsgId::trash()` and `delete_expired_messages()` + let trash = chat_id.is_trash(); + stmt.execute(paramsv![ rfc724_mid, server_folder, server_uid as i32, chat_id, - from_id as i32, - to_id as i32, + if trash { 0 } else { from_id as i32 }, + if trash { 0 } else { to_id as i32 }, sort_timestamp, sent_timestamp, rcvd_timestamp, part.typ, state, is_dc_message, - part.msg, + if trash { "" } else { &part.msg }, // txt_raw might contain invalid utf8 - txt_raw, - part.param.to_string(), + if trash { "" } else { &txt_raw }, + if trash { + "".to_string() + } else { + part.param.to_string() + }, part.bytes as isize, is_hidden, - if save_mime_headers || mime_modified { + if (save_mime_headers || mime_modified) && !trash { mime_headers.clone() } else { None diff --git a/src/ephemeral.rs b/src/ephemeral.rs index 47457ba94..58f82e6c5 100644 --- a/src/ephemeral.rs +++ b/src/ephemeral.rs @@ -308,8 +308,10 @@ pub(crate) async fn delete_expired_messages(context: &Context) -> Result crate::sql::Result<()> { let chat_id = ChatId::new(DC_CHAT_ID_TRASH); context .sql .execute( + // If you change which information is removed here, also change delete_expired_messages() and + // which information dc_receive_imf::add_parts() still adds to the db if the chat_id is TRASH "UPDATE msgs SET chat_id=?, txt='', txt_raw='', mime_headers='', from_id=0, to_id=0, param='' WHERE id=?", paramsv![chat_id, self], )