[geary/wip/update-duplicate-inbox-hack] Update ImapDb.Account hack to remove duplicate inboxes



commit c6197adce002dd254a44606f2a7aacffbbce1a16
Author: Michael Gratton <mike vee net>
Date:   Sun Aug 25 10:39:24 2019 +1000

    Update ImapDb.Account hack to remove duplicate inboxes
    
    Two of my account's databases had duplicate inboxes which were not being
    removed by the existing workaroud, this updates it so that they are.
    
    I had removed the duplicate from a third account ages ago and it hasn't
    come back since, so maybe the underlying problem is gone, but the
    correct fix would be to move this workaround to a migration and add a
    uniquness constraint on (parent_id, name).

 src/engine/imap-db/imap-db-account.vala | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)
---
diff --git a/src/engine/imap-db/imap-db-account.vala b/src/engine/imap-db/imap-db-account.vala
index c542606f..c50a7b5a 100644
--- a/src/engine/imap-db/imap-db-account.vala
+++ b/src/engine/imap-db/imap-db-account.vala
@@ -93,24 +93,38 @@ private class Geary.ImapDB.Account : BaseObject {
             throw err;
         }
 
-        // have seen cases where multiple "Inbox" folders are created in the root with different
-        // case names, leading to trouble ... this clears out all Inboxes that don't match our
-        // "canonical" name
+        // Have seen cases where multiple "Inbox" folders are created
+        // in the root, leading to trouble ... this clears out all
+        // Inboxes that don't match our "canonical" name and that
+        // appears after the first that does.
+        //
+        // XXX the proper fix for this is of course to move this code
+        // to a migration and add a uniqueness constraint on
+        // (parent_id, name).
         try {
             yield db.exec_transaction_async(Db.TransactionType.RW, (cx) => {
                 Db.Statement stmt = cx.prepare("""
                     SELECT id, name
                     FROM FolderTable
                     WHERE parent_id IS NULL
+                    ORDER BY id
                 """);
 
                 Db.Result results = stmt.exec(cancellable);
+                bool found = false;
                 while (!results.finished) {
                     string name = results.string_for("name");
-                    if (Imap.MailboxSpecifier.is_inbox_name(name)
-                        && !Imap.MailboxSpecifier.is_canonical_inbox_name(name)) {
-                        debug("%s: Removing duplicate INBOX \"%s\"", this.name, name);
-                        do_delete_folder(cx, results.rowid_for("id"), cancellable);
+                    if (Imap.MailboxSpecifier.is_inbox_name(name)) {
+                        if (!found &&
+                            Imap.MailboxSpecifier.is_canonical_inbox_name(name)) {
+                            found = true;
+                        } else {
+                            warning("%s: Removing duplicate INBOX \"%s\"",
+                                    this.name, name);
+                            do_delete_folder(
+                                cx, results.rowid_for("id"), cancellable
+                            );
+                        }
                     }
 
                     results.next(cancellable);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]