Skip to content

Instantly share code, notes, and snippets.

@leslie-alldridge
Forked from akamyshanov/gmail-auto-archive.js
Created November 12, 2018 23:08
Show Gist options
  • Save leslie-alldridge/0a427c50a807ead73380c9b71c42188a to your computer and use it in GitHub Desktop.
Save leslie-alldridge/0a427c50a807ead73380c9b71c42188a to your computer and use it in GitHub Desktop.
GMail Auto Archive script for Google Scripts
function gmailAutoarchive() {
var threads = GmailApp.search("in:inbox label:auto-archive older_than:2d");
Logger.log("found " + threads.length + " threads:");
for(var i = 0; i < threads.length; i++) {
var thread = threads[i];
Logger.log((i+1) + ". " + thread.getFirstMessageSubject());
}
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