-
-
Save Sporky023/61e50ca90899b39361af69550bb03010 to your computer and use it in GitHub Desktop.
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 delayDays = 2; // will only impact emails more than 48h old | |
var maxDate = new Date((new Date).getTime() - delayDays * 24 * 3600 * 1000); | |
// Get all the threads labelled 'autoarchive' | |
var label = GmailApp.getUserLabelByName("autoarchive"); | |
var threads = label.getThreads(0, 400); | |
// we archive all the threads if they're unread AND older than the limit we set in delayDays | |
for (var i = 0; i < threads.length; i++) { | |
if (threads[i].getLastMessageDate().getTime() < maxDate.getTime()) | |
{ | |
threads[i].moveToArchive(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment