Skip to content

Instantly share code, notes, and snippets.

@Damovisa
Last active February 16, 2023 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Damovisa/dc064d6ee6e3cc9af5e6b4113a02780c to your computer and use it in GitHub Desktop.
Save Damovisa/dc064d6ee6e3cc9af5e6b4113a02780c to your computer and use it in GitHub Desktop.
Google Apps Script to mark all non-starred unread emails as read
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