Last active
January 12, 2018 20:00
-
-
Save rbreaves/d185c1cd2892561199f5b90e1af5117b to your computer and use it in GitHub Desktop.
Gmail - Archive > 1 week && Mark As Read > 2 weeks
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 characters
function markArchivedAsRead() { | |
var delayDays = 7; // will only impact emails more than 7 days old | |
var maxDate = new Date(); | |
maxDate.setDate(maxDate.getDate()-delayDays); // what was the date at that time? | |
//Look for unread emails that are older than 14 days and exclude starred emails | |
var threads = GmailApp.search('label:unread older_than:14d -is:starred'); | |
GmailApp.markThreadsRead(threads); | |
// 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(); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In google script, https://script.google.com, you can set a trigger to run this daily.