Last active
December 6, 2021 03:55
-
-
Save anroopak/5376a29c31cce1ab5edac5f8e6c28d35 to your computer and use it in GitHub Desktop.
Google App Script - Email cleanup
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
CUTOFF_IN_DAYS = 7 | |
function cleanEmail() { | |
const searchQueries = [ | |
"bigrock.com", | |
"instahyre.com", | |
"accounts.google.com", | |
] | |
searchQueries.forEach(searchText => { | |
const search = "from:"+searchText + " older_than:"+CUTOFF_IN_DAYS+"d" | |
const response = Gmail.Users.Threads.list("me", {q: search}) | |
Logger.log("search: " + search) | |
Logger.log("searchText: "+searchText+". Approx Count: " +response.resultSizeEstimate); | |
(response.threads || []).forEach(t => { | |
const thread = GmailApp.getThreadById(t.id) | |
if (!thread.hasStarredMessages()){ | |
thread.moveToTrash() | |
} | |
}) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment