Skip to content

Instantly share code, notes, and snippets.

@sveitser
Last active August 4, 2018 08:34
Show Gist options
  • Save sveitser/6c1370ce842614abf67df477024d0aaa to your computer and use it in GitHub Desktop.
Save sveitser/6c1370ce842614abf67df477024d0aaa to your computer and use it in GitHub Desktop.
Google app script to remove old forum messages. Paste into https://script.google.com and schedule or whatever.
function cleanUp() {
// I think this refers to the date when the thread was started.
var delayDays = 90;
var max = 200;
var offset = 0;
var query = 'category:forums older_than:' + delayDays + 'd'
while (true) {
var threads = GmailApp.search(query, offset, max);
Logger.log("fetched %s", offset + threads.length);
for (var i = 0; i < threads.length; i++) {
Logger.log("removing %s", offset + i);
threads[i].moveToTrash();
}
if (threads.length < max) {
break;
}
offset += max;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment