Created
March 6, 2015 07:25
-
-
Save DaikiSuganuma/e8ad208e7b5a664a59e1 to your computer and use it in GitHub Desktop.
Gmail Auto Clean Up (http://se-suganuma.blogspot.jp/2013/10/google-apps-scriptgmail.html)
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
function cleanUp() { | |
// | |
// Settings | |
// | |
// Enter # of days before messages are moved to trash | |
var days = 7; | |
// List of labels which you want to remove | |
var filters = []; | |
filters.push('label:notification-mailmagazine'); | |
filters.push('label:notification-facebook'); | |
filters.push('label:notification-google+'); | |
filters.push('label:notification-schedule'); | |
filters.push('label:notification-twitter'); | |
// If it found many threads, | |
// the loop method will be stop at around 250. | |
var max = 200; | |
// | |
// Generate Search Query | |
// | |
var query = []; | |
query.push('('); | |
query.push(filters.join(' OR ')); | |
query.push(')'); | |
query.push('is:read'); | |
query.push('older_than:' + days + 'd'); | |
query = query.join(' '); | |
// Excute | |
//Logger.log(query); // for Debug | |
var threads = GmailApp.search(query); | |
if (!threads) {return false;} | |
for (var i = 0; i < max; i++) { | |
if (threads[i]) { | |
threads[i].moveToTrash(); | |
// for Debug | |
//messages = threads[i].getMessages(); | |
//for (var j = 0; j < messages.length; j++) { | |
// Logger.log(messages[j].getSubject()); | |
//} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment