Skip to content

Instantly share code, notes, and snippets.

@davenicoll
Created January 17, 2021 13:48
Show Gist options
  • Save davenicoll/5166192c4216a2dc165c9776f7ff9b42 to your computer and use it in GitHub Desktop.
Save davenicoll/5166192c4216a2dc165c9776f7ff9b42 to your computer and use it in GitHub Desktop.
Autoarchive for GMail
function gmailAutoarchive() {
var holdDays = 8;
var maxDate = new Date();
maxDate.setDate(maxDate.getDate()-holdDays);
var threads = GmailApp.getInboxThreads(0,500).filter(function(thread) {
// Return only old threads and without stars
return (thread.getLastMessageDate() < maxDate && thread.hasStarredMessages() == false);
});
var batch_size = 100;
while (threads.length) {
var this_batch_size = Math.min(threads.length, batch_size);
var this_batch = threads.splice(0, this_batch_size);
GmailApp.moveThreadsToArchive(this_batch);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment