Skip to content

Commit

Permalink
feat: delete messages on IMAP when deleting chat (#6613)
Browse files Browse the repository at this point in the history
this PR deletes all known messages belonging to a chat when the chat is
deleted.

this may not be an exhaustive list as a client might not know all
message-ids (eg. when using different times for "delete from device").
in this case, other devices may know more IDs. otherwise, the chatmail
server will eventually clean up at some point. for non-chatmail, this is
up to the user then.

the deletion sql commands were inspired by
[`delete_msgs_ex`](https://github.com/chatmail/core/blob/main/src/message.rs#L1743)
(in fact, [a first
try](https://github.com/chatmail/core/compare/r10s/clear-chat-on-delete)
was adapting that part, however, that seems less performant as lots of
sql commands are needed)

successor of #5007
  • Loading branch information
r10s authored Mar 6, 2025
1 parent c4e6823 commit 8e25639
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,7 @@ impl ChatId {
);

let chat = Chat::load_from_db(context, self).await?;
let delete_msgs_target = context.get_delete_msgs_target().await?;
let sync_id = match sync {
Nosync => None,
Sync => chat.get_sync_id(context).await?,
Expand All @@ -792,6 +793,14 @@ impl ChatId {
context
.sql
.transaction(|transaction| {
transaction.execute(
"UPDATE imap SET target=? WHERE rfc724_mid IN (SELECT rfc724_mid FROM msgs WHERE chat_id=?)",
(delete_msgs_target, self,),
)?;
transaction.execute(
"DELETE FROM smtp WHERE msg_id IN (SELECT id FROM msgs WHERE chat_id=?)",
(self,),
)?;
transaction.execute(
"DELETE FROM msgs_mdns WHERE msg_id IN (SELECT id FROM msgs WHERE chat_id=?)",
(self,),
Expand Down

0 comments on commit 8e25639

Please sign in to comment.