Skip to content

Instantly share code, notes, and snippets.

@imjma
Created December 5, 2013 03:32
Show Gist options
  • Save imjma/7799698 to your computer and use it in GitHub Desktop.
Save imjma/7799698 to your computer and use it in GitHub Desktop.
Google Scripts for Gmail to archive inbox emails and delete old emails
function archiveInbox() {
var batchSize = 100; // Process up to 100 threads at once
// Every thread in your Inbox that is older than two days.
var threads = GmailApp.search('in:inbox older_than:5d');
for (var i = 0; i < threads.length; i+=batchSize) {
GmailApp.moveThreadsToArchive(threads.slice(i, i+batchSize));
}
}
function cleanUp() {
var batchSize = 100; // Process up to 100 threads at once
var threads = GmailApp.search('older_than:1y');
for (var i = 0; i < threads.length; i+=batchSize) {
GmailApp.moveThreadsToTrash(threads.slice(i, i+batchSize));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment