function gmailAutoarchive() { var archived_threads = 0; var delayDays = 2; var maxDate = new Date(); maxDate.setDate(maxDate.getDate()-delayDays); // what was the date at that time? // getUserLabels returns an array of gmail labels. // This way we don't have to convert the array elements and will archive all user labeled threads. var labels = GmailApp.getUserLabels() var threads = GmailApp.getInboxThreads(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++) { var thread = threads[i]; if (thread.getLastMessageDate()