-
-
Save schlos/73f2f83922ec190c537234a6165f2d2d to your computer and use it in GitHub Desktop.
Gmail/Inbox Email Purge Script
This file contains hidden or 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 Purge 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