Last active
January 28, 2018 06:05
-
-
Save dgibbs64/bfbe0cd41486535771b1 to your computer and use it in GitHub Desktop.
GmailAutoTrash.gscript
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
// Gmail/Inbox Email Trash Script | |
// Using Google Script | |
// Clears out all emails older than X days | |
// Labels | |
function multipleLabels() { | |
var myLabels = { | |
'"Updates"': "7d", | |
'"Forums"': "7d", | |
'"Promotions"': "7d", | |
}; | |
var batchSize = 100; // Process up to 100 threads at once | |
for(aLabel in myLabels) | |
{ | |
var threads = GmailApp.search('label:'+aLabel+' older_than:'+myLabels[aLabel]+''); | |
Logger.log("Purged " + threads.length + " threads from" + aLabel); | |
for (j = 0; j < threads.length; j+=batchSize) { | |
GmailApp.moveThreadsToTrash(threads.slice(j, j+batchSize)); | |
} | |
} | |
} | |
// Categories | |
function multipleCategories() { | |
var myCategories = { | |
'"Updates"': "4d", | |
'"Forums"': "7d", | |
'"Promotions"': "7d", | |
'"Social"': "7d", | |
}; | |
var batchSize = 100; // Process up to 100 threads at once | |
for(aCategory in myCategories) | |
{ | |
var threads = GmailApp.search('category:'+aCategory+' older_than:'+myCategories[aCategory]+''); | |
Logger.log("Purged " + threads.length + " threads from" + aCategory); | |
for (j = 0; j < threads.length; j+=batchSize) { | |
GmailApp.moveThreadsToTrash(threads.slice(j, j+batchSize)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment