Last active
April 15, 2019 14:55
-
-
Save pan-long/74fd18d57b5509d3b2424630551d59d2 to your computer and use it in GitHub Desktop.
App Script to move old Gmail threads to Trash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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