[plasma-mobile/raven] src/ravend/src: Delete non existent folders when syncing

Devin Lin <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 00c9729003d5964f343032a5fa944c9fb6c70ae9 by Devin Lin, on behalf of Alexander Malygin.
Committed on 20/07/2026 at 17:56.
Pushed by devinlin into branch 'master'.

Delete non existent folders when syncing

M  +17   -0    src/ravend/src/db/operations.rs
M  +13   -0    src/ravend/src/imap/worker.rs

https://invent.kde.org/plasma-mobile/raven/-/commit/00c9729003d5964f343032a5fa944c9fb6c70ae9

diff --git a/src/ravend/src/db/operations.rs b/src/ravend/src/db/operations.rs
index 37ce7b8..f13108f 100644
--- a/src/ravend/src/db/operations.rs
+++ b/src/ravend/src/db/operations.rs
@@ -72,6 +72,15 @@ pub fn get_folder_by_id(conn: &Connection, folder_id: &str) -> Result<Option<Fol
     .with_context(|| format!("Failed to query folder '{}'", folder_id))
 }
 
+pub fn get_folders_ids(conn: &Connection) -> Result<Vec<String>> {
+    let mut stmt = conn.prepare(
+        "SELECT id FROM folder"
+    )?;
+
+    let ids = stmt.query_map([], |row| row.get(0))?.collect::<std::result::Result<Vec<_>, _>>()?;
+    return Ok(ids);
+}
+
 pub fn update_folder_sync_state(
     conn: &Connection,
     folder_id: &str,
@@ -187,6 +196,14 @@ pub fn delete_message_by_uid(conn: &Connection, account_id: &str, folder_id: &st
     Ok(false)
 }
 
+pub fn delete_folder_by_uid(conn: &Connection, folder_id: &str) -> Result<bool> {
+    
+    conn.execute("DELETE FROM folder WHERE id = ?1", [&folder_id])?;
+    conn.execute("DELETE FROM thread_folder WHERE folderId = ?1", [&folder_id])?;
+    return Ok(true);
+
+}
+
 pub fn get_folder_message_uids(conn: &Connection, account_id: &str, folder_id: &str) -> Result<Vec<u32>> {
     let mut stmt = conn.prepare(
         "SELECT remoteUID FROM message WHERE accountId = ?1 AND folderId = ?2"
diff --git a/src/ravend/src/imap/worker.rs b/src/ravend/src/imap/worker.rs
index fbdee21..1c611e6 100644
--- a/src/ravend/src/imap/worker.rs
+++ b/src/ravend/src/imap/worker.rs
@@ -349,6 +349,8 @@ impl ImapWorker {
             .map_err(|e| anyhow::anyhow!("Failed to acquire database lock: {}", e))?;
         let mut folders = Vec::new();
 
+        let folders_ids = db::get_folders_ids(db.conn())?;
+
         for mailbox in mailboxes.iter() {
             let path = mailbox.name().to_string();
             let id = format!("{}:{}", self.account.id, path);
@@ -362,6 +364,17 @@ impl ImapWorker {
             folders.push(folder);
         }
 
+        for existing_folder_id in folders_ids.iter() {
+            if !folders.iter().any(|i| &i.id == existing_folder_id) {
+                if !db::delete_folder_by_uid(db.conn(), existing_folder_id)? {
+                    error!("Failed to delete folder: {}", existing_folder_id);
+                }
+                else {
+                    info!("Folder with id: {} is deleted", existing_folder_id);
+                }
+            }
+        }
+
         drop(db);
 
         if !folders.is_empty() {
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.