Skip to content

Instantly share code, notes, and snippets.

@anroopak
Last active December 6, 2021 03:55
Show Gist options
  • Save anroopak/5376a29c31cce1ab5edac5f8e6c28d35 to your computer and use it in GitHub Desktop.
Save anroopak/5376a29c31cce1ab5edac5f8e6c28d35 to your computer and use it in GitHub Desktop.
Google App Script - Email cleanup
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