mirror of
https://github.com/Luzifer/gmail-manage.git
synced 2024-11-08 15:30:10 +00:00
24 lines
652 B
JavaScript
24 lines
652 B
JavaScript
// Apps Scripts may only run for ~5m so we limit the execution
|
|
var MAX_DELETE_PER_LOOP = 1000
|
|
|
|
function cleanup() {
|
|
trashByQuery("older_than:10y")
|
|
trashByQuery("label:newsletter older_than:6m")
|
|
trashByQuery("label:social-media older_than:2y")
|
|
}
|
|
|
|
function trashByQuery(query) {
|
|
var threads = []
|
|
var removedThreads = 0
|
|
|
|
do {
|
|
threads = GmailApp.search(query)
|
|
for (var i = 0; i < threads.length; i++) {
|
|
var thread = threads[i]
|
|
thread.moveToTrash()
|
|
removedThreads++
|
|
}
|
|
} while (threads.length > 0 && removedThreads < MAX_DELETE_PER_LOOP)
|
|
|
|
Logger.log('Removed %s threads for query "%s"', removedThreads, query)
|
|
}
|