Skip to content

Instantly share code, notes, and snippets.

@zoernert
Created May 28, 2015 12:51
Show Gist options
  • Select an option

  • Save zoernert/9b7f22a3e456dbe9c6ab to your computer and use it in GitHub Desktop.

Select an option

Save zoernert/9b7f22a3e456dbe9c6ab to your computer and use it in GitHub Desktop.
GoogleApps Script: Label all old Gmails
// Use at: https://script.google.com/
function findOldMails() {
// Find UserLabel (Needs to exist)
var label = GmailApp.getUserLabelByName("old");
// Setting our query
var query="older_than:1y -label:old";
var numThreads=400;
var lastStart=-1;
while(numThreads>0) {
var threads=GmailApp.search(query);
for(var i=0;i<threads.length;i++) {
threads[i].addLabel(label);
}
numThreads=threads.length;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment