Skip to content

Instantly share code, notes, and snippets.

@pan-long
Last active April 15, 2019 14:55
Show Gist options
  • Save pan-long/74fd18d57b5509d3b2424630551d59d2 to your computer and use it in GitHub Desktop.
Save pan-long/74fd18d57b5509d3b2424630551d59d2 to your computer and use it in GitHub Desktop.
App Script to move old Gmail threads to Trash
function GmailIndef() {
var INDEF_LABEL = 'Indef';
var RETENTION_DAYS = 356;
var RETENTION_DATE = new Date();
RETENTION_DATE.setDate(RETENTION_DATE.getDate() - RETENTION_DAYS);
var threads = GmailApp.search('in:anywhere'
+ ' -(label:' + INDEF_LABEL + ')'
+ ' before:' + RETENTION_DATE.getFullYear()
+ '-' + (RETENTION_DATE.getMonth() + 1)
+ '-' + RETENTION_DATE.getDate());
threads.forEach(function(thread) {
GmailApp.moveThreadToTrash(thread);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment