Created
January 8, 2017 16:39
-
-
Save anonymous/2cca33d376f7f924fdaa67891ad098cc to your computer and use it in GitHub Desktop.
Revisions
-
There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ function gmailAutoarchive() { var delayDays = 2; // will only impact emails more than 48h old var maxDate = new Date(); maxDate.setDate(maxDate.getDate()-delayDays); // what was the date at that time? // 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()<maxDate) { threads[i].moveToArchive(); } } }