Skip to content

Instantly share code, notes, and snippets.

@patoroco
Created December 30, 2019 14:46
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patoroco/21bba84ab0f751ff2e34cf4e08d0cba5 to your computer and use it in GitHub Desktop.
Save patoroco/21bba84ab0f751ff2e34cf4e08d0cba5 to your computer and use it in GitHub Desktop.
function main() {
deleteOldMessages('notifications-jenkins');
deleteOldMessages('notifications-sentry');
}
function deleteOldMessages(label_to_delete) {
var search = 'label:' + label_to_delete + ' -{label:Trash} older_than:6m';
var threads = GmailApp.search(search, 0, 120);
console.log("Search: `" + search + "` (" + threads.length + " threads)");
for (var i in threads) {
var thread = threads[i];
var subject = thread.getFirstMessageSubject();
thread.moveToTrash();
console.log("Moving to the trash: " + subject);
}
}
@patoroco
Copy link
Author

patoroco commented Dec 30, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment