Skip to content

Instantly share code, notes, and snippets.

@EmmanuelDemey
Created August 10, 2014 16:57
Show Gist options
  • Select an option

  • Save EmmanuelDemey/f2aab0179425a7a1722e to your computer and use it in GitHub Desktop.

Select an option

Save EmmanuelDemey/f2aab0179425a7a1722e to your computer and use it in GitHub Desktop.
Move to trash read email labelledd, or sub-labelled, by a specific string. (in this case Geeks).
function processLabel(label) {
var data = GmailApp.getUserLabelByName(label).getThreads();
for (var i=0; i < data.length; i++) {
if(!data[i].isUnread() && !data[i].hasStarredMessages()){
data[i].moveToTrash();
}
}
};
function deleteOldMessages(){
GmailApp.getTrashThreads()
var labels = GmailApp.getUserLabels();
for (var i = 0; i < labels.length; i++) {
if(labels[i].getName().indexOf("Geeks/")===0){
processLabel(labels[i].getName());
Logger.log("label: " + labels[i].getName());
Utilities.sleep(1000);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment