Last active
November 4, 2021 13:46
-
-
Save apostololeg/6b7af65e50f778e5b878a916dc238b02 to your computer and use it in GitHub Desktop.
Gmail remove batch messages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let count = 1500; | |
const batchSize = 100; | |
async function purgeGmail(query) { | |
const items = GmailApp.search("label:github", 0, batchSize); | |
console.log(count, items.length); | |
await GmailApp.moveThreadsToTrash(items); | |
count -= batchSize; | |
if (count > 0) purgeGmail(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let count = 32000; | |
const step = 1500; | |
const delay = 1000; | |
const getRunBtn = () => document.querySelector('[aria-label="Run the selected function"]'); | |
function resolveWhenBtnEnables(resolve) { | |
function check() { | |
if (getRunBtn().disabled) setTimeout(check, delay); | |
else resolve(); | |
} | |
setTimeout(check, delay); | |
} | |
function waitForRunBtn() { | |
return new Promise(resolveWhenBtnEnables); | |
} | |
function run() { | |
console.log('run', count); | |
getRunBtn().click(); | |
count -= step; | |
if (count > 0) waitForRunBtn().then(run); | |
} | |
run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Gmail has limitations for batch operations, so i wrote a little script for it:
Code.gs
(update search filter)devTool_console.js
(update variablecount
)Enter