From 1bb41f5cc97b4a10c1f653398ac7c2ac29c81167 Mon Sep 17 00:00:00 2001 From: poprhythm Date: Fri, 6 Mar 2026 16:03:20 +0000 Subject: [PATCH] Fix gmail-label-cleanup: use GmailLabel methods instead of GmailApp --- inbox-zero/gmail-label-cleanup.gs | 48 +++++++++++++++---------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/inbox-zero/gmail-label-cleanup.gs b/inbox-zero/gmail-label-cleanup.gs index 52abfcd..8f02698 100644 --- a/inbox-zero/gmail-label-cleanup.gs +++ b/inbox-zero/gmail-label-cleanup.gs @@ -42,8 +42,8 @@ function mergeLabels() { var threads = fromLabel.getThreads(0, 500); var total = 0; while (threads.length > 0) { - GmailApp.addLabelToThreads(threads, toLabel); - GmailApp.removeLabelFromThreads(threads, fromLabel); + toLabel.addToThreads(threads); + fromLabel.removeFromThreads(threads); total += threads.length; Utilities.sleep(1000); threads = fromLabel.getThreads(0, 500); @@ -72,9 +72,9 @@ function archiveCvlp() { var threads = cvlpLabel.getThreads(0, 500); var total = 0; while (threads.length > 0) { - GmailApp.addLabelToThreads(threads, newsletterLabel); - GmailApp.removeLabelFromThreads(threads, cvlpLabel); - GmailApp.moveThreadsToArchive(threads); + newsletterLabel.addToThreads(threads); + cvlpLabel.removeFromThreads(threads); + threads.forEach(function(t) { t.moveToArchive(); }); total += threads.length; Utilities.sleep(1000); threads = cvlpLabel.getThreads(0, 500); @@ -102,8 +102,8 @@ function mergePurchasesIntoReceipt() { var threads = purchasesLabel.getThreads(0, 500); var total = 0; while (threads.length > 0) { - GmailApp.addLabelToThreads(threads, receiptLabel); - GmailApp.removeLabelFromThreads(threads, purchasesLabel); + receiptLabel.addToThreads(threads); + purchasesLabel.removeFromThreads(threads); total += threads.length; Utilities.sleep(1000); threads = purchasesLabel.getThreads(0, 500); @@ -127,8 +127,8 @@ function restructureBusinessLabels() { var threads = bizDonations.getThreads(0, 500); var total = 0; while (threads.length > 0) { - GmailApp.addLabelToThreads(threads, donationsLabel); - GmailApp.removeLabelFromThreads(threads, bizDonations); + donationsLabel.addToThreads(threads); + bizDonations.removeFromThreads(threads); total += threads.length; Utilities.sleep(1000); threads = bizDonations.getThreads(0, 500); @@ -136,8 +136,7 @@ function restructureBusinessLabels() { Logger.log('Moved ' + total + ' threads to top-level donations'); bizDonations.deleteLabel(); } else { - // Try top-level donations label - Logger.log('business/donations not found - checking for top-level donations label'); + Logger.log('business/donations not found - skipping'); } // Move selling under business: rename selling -> business/selling @@ -151,8 +150,8 @@ function restructureBusinessLabels() { var threads = sellingLabel.getThreads(0, 500); var total = 0; while (threads.length > 0) { - GmailApp.addLabelToThreads(threads, bizSelling); - GmailApp.removeLabelFromThreads(threads, sellingLabel); + bizSelling.addToThreads(threads); + sellingLabel.removeFromThreads(threads); total += threads.length; Utilities.sleep(1000); threads = sellingLabel.getThreads(0, 500); @@ -161,7 +160,7 @@ function restructureBusinessLabels() { sellingLabel.deleteLabel(); } - // Delete contract label (threads already have business label, just remove contract) + // Delete contract label (threads already have business label) var contractLabel = GmailApp.getUserLabelByName('business/contract'); if (!contractLabel) { contractLabel = GmailApp.getUserLabelByName('contract'); @@ -171,7 +170,7 @@ function restructureBusinessLabels() { var threads = contractLabel.getThreads(0, 500); var total = 0; while (threads.length > 0) { - GmailApp.removeLabelFromThreads(threads, contractLabel); + contractLabel.removeFromThreads(threads); total += threads.length; Utilities.sleep(1000); threads = contractLabel.getThreads(0, 500); @@ -202,15 +201,16 @@ function deleteUnusedLabels() { Logger.log('Not found (already gone?): ' + name); return; } - var count = label.getThreads(0, 1).length; - if (count > 0) { - Logger.log('WARNING: ' + name + ' still has threads - removing label from them first'); - var threads = label.getThreads(0, 500); - while (threads.length > 0) { - GmailApp.removeLabelFromThreads(threads, label); - Utilities.sleep(500); - threads = label.getThreads(0, 500); - } + var threads = label.getThreads(0, 500); + var total = 0; + while (threads.length > 0) { + label.removeFromThreads(threads); + total += threads.length; + Utilities.sleep(500); + threads = label.getThreads(0, 500); + } + if (total > 0) { + Logger.log('Removed label from ' + total + ' threads: ' + name); } label.deleteLabel(); Logger.log('Deleted: ' + name);