Created
January 17, 2021 13:48
-
-
Save davenicoll/5166192c4216a2dc165c9776f7ff9b42 to your computer and use it in GitHub Desktop.
Autoarchive for GMail
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 gmailAutoarchive() { | |
var holdDays = 8; | |
var maxDate = new Date(); | |
maxDate.setDate(maxDate.getDate()-holdDays); | |
var threads = GmailApp.getInboxThreads(0,500).filter(function(thread) { | |
// Return only old threads and without stars | |
return (thread.getLastMessageDate() < maxDate && thread.hasStarredMessages() == false); | |
}); | |
var batch_size = 100; | |
while (threads.length) { | |
var this_batch_size = Math.min(threads.length, batch_size); | |
var this_batch = threads.splice(0, this_batch_size); | |
GmailApp.moveThreadsToArchive(this_batch); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment