Last active
February 16, 2023 13:22
-
-
Save Damovisa/dc064d6ee6e3cc9af5e6b4113a02780c to your computer and use it in GitHub Desktop.
Google Apps Script to mark all non-starred unread emails as read
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 getInboxUnreadCount() { | |
Logger.log(GmailApp.getInboxUnreadCount() + " unread emails"); | |
} | |
function setAllUnreadNonStarredAsRead() { | |
// Define the search string to identify emails | |
var searchString = "is:unread -is:starred in:inbox"; | |
// Get all threads matching search string | |
var threads = GmailApp.search(searchString,0,500); | |
for (var i=0; i<threads.length; i++) { | |
var thread = threads[i]; | |
Logger.log(Utilities.formatDate(thread.getLastMessageDate(),"GMT","yyyy-MM-dd") + " : " + thread.getFirstMessageSubject()); | |
if (threads[i].hasStarredMessages()) { | |
Logger.log(" ➰ Starred so skipped") | |
} else { | |
threads[i].markRead() | |
Logger.log(" ✅ Marked as read") | |
} | |
} | |
} | |
getInboxUnreadCount() | |
// this will only do 500 at a time, but I'll just keep running it | |
setAllUnreadNonStarredAsRead() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment