1
0
Fork 0
mirror of https://github.com/Luzifer/gmail-manage.git synced 2024-11-08 15:30:10 +00:00
gmail-manage/Code.js

25 lines
652 B
JavaScript
Raw Normal View History

2018-10-20 11:37:57 +00:00
// Apps Scripts may only run for ~5m so we limit the execution
2018-10-20 12:48:42 +00:00
var MAX_DELETE_PER_LOOP = 1000
2018-10-20 11:37:57 +00:00
function cleanup() {
2018-10-20 12:48:42 +00:00
trashByQuery("older_than:10y")
2018-10-20 11:37:57 +00:00
trashByQuery("label:newsletter older_than:6m")
2018-10-20 16:05:26 +00:00
trashByQuery("label:social-media older_than:2y")
2018-10-20 11:37:57 +00:00
}
function trashByQuery(query) {
var threads = []
var removedThreads = 0
2018-10-20 11:38:10 +00:00
2018-10-20 11:37:57 +00:00
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)
2018-10-20 11:38:10 +00:00
2018-10-20 11:37:57 +00:00
Logger.log('Removed %s threads for query "%s"', removedThreads, query)
}