-
-
Save luckyshot/81607745be7d3a8a229305af3987f55d to your computer and use it in GitHub Desktop.
Google Apps Script for cleaning up Gmail
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
/** | |
* Scripts: https://script.google.com/u/0/home/my | |
* Triggers: https://script.google.com/u/0/home/triggers | |
*/ | |
function cleanUpGmail() { | |
var queries = [ | |
'from:([email protected]) in:inbox subject:(from your Steam wishlist on sale) older_than:7d', | |
'from:([email protected]) in:inbox subject:(is live) older_than:1d', | |
'from:ebay.com subject:("is live!" OR "has been relisted") older_than:7d', | |
// Security alerts | |
'from:([email protected]) in:inbox subject:("Security alert" OR "New sign-in from") older_than:1m', | |
// 2FA | |
'from:([email protected]) in:inbox older_than:1d subject:("two-step authentication" )' | |
] | |
var threads = Array(); | |
for(var query of queries){ | |
threads.push(...GmailApp.search(query)); | |
} | |
Logger.log("Cleaning up %s threads", threads.length); | |
var chunkSize = 100; | |
for (var i = 0; i < threads.length; i += chunkSize) { | |
var chunk = threads.slice(i, i + chunkSize); | |
// Mark as read | |
// Logger.log("Cleaning up chunk %s", i); | |
// GmailApp.markThreadsRead(chunk); | |
// Delete | |
// GmailApp.moveThreadsToTrash(chunk); | |
// Archive | |
for (var i = 0; i < chunk.length; i++) { | |
Logger.log("Archiving chunk %s: %s", i, chunk[i].getFirstMessageSubject()); | |
chunk[i].moveToArchive(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment