Skip to content

Instantly share code, notes, and snippets.

@rbreaves
Last active January 12, 2018 20:00
Show Gist options
  • Save rbreaves/d185c1cd2892561199f5b90e1af5117b to your computer and use it in GitHub Desktop.
Save rbreaves/d185c1cd2892561199f5b90e1af5117b to your computer and use it in GitHub Desktop.
Gmail - Archive > 1 week && Mark As Read > 2 weeks
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();
}
}
};
@rbreaves
Copy link
Author

rbreaves commented Jan 9, 2018

In google script, https://script.google.com, you can set a trigger to run this daily.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment