Skip to content

Instantly share code, notes, and snippets.

@schlos
Created June 18, 2017 11:11
Show Gist options
  • Save schlos/befaea02ca0b39e72d9f54be24a596b6 to your computer and use it in GitHub Desktop.
Save schlos/befaea02ca0b39e72d9f54be24a596b6 to your computer and use it in GitHub Desktop.
Clean GMail
// This script retrieves contents of Gmail Inbox and leaves only
// predefined amount of last messages. Old messages will be
// moved to archive.
function cleanOld(){
var old_threads = GmailApp.getInboxThreads();
var leave = 30;
if (old_threads.length>=leave){
for (var i=leave; i<old_threads.length; i++){
if (!old_threads[i].isImportant()){
old_threads[i].moveToArchive();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment