Created
October 18, 2018 21:29
-
-
Save imightbeamy/6d63f0b81bfe84f48c11204a841d68cd 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
var DAYS = 24; | |
function gmailAutoarchive() { | |
processesLabel(12, "merged", archive); | |
processesLabel(7*DAYS, "OOO", archive); | |
processesLabel(20, "daily", archive); | |
processesLabel(7*DAYS, "Etc.", markRead); | |
} | |
var MILLIS_PER_HOUR = 1000 * 60 * 60; | |
function processesLabel(delayHours, labelName, action) { | |
var maxDate = new Date((new Date()).getTime() - (delayHours*MILLIS_PER_HOUR)); | |
// Get all the labelled threads | |
var label = GmailApp.getUserLabelByName(labelName); | |
var threads = label.getThreads(0, 400); | |
// Take action on threads if they're older than the limit set in delayHours | |
for (var i = 0; i < threads.length; i++) { | |
if (threads[i].getLastMessageDate()<maxDate) { | |
action(threads[i]); | |
} | |
} | |
} | |
function archive(thread) { | |
thread.moveToArchive(); | |
} | |
function markRead(thread) { | |
thread.markRead(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment