commit 5b93a0a4499cee949c22e22fd04d078d2847d4e2 Author: Knut Ahlers Date: Sat Oct 20 13:37:57 2018 +0200 Initial version diff --git a/.clasp.json b/.clasp.json new file mode 100644 index 0000000..35fc566 --- /dev/null +++ b/.clasp.json @@ -0,0 +1 @@ +{"scriptId":"1vTgZT2m51WMyO8e_3muHlzLhrrRoqiNdU9BcJn7-05aKhIpJgnKXt4VN"} diff --git a/Code.js b/Code.js new file mode 100644 index 0000000..4129f08 --- /dev/null +++ b/Code.js @@ -0,0 +1,22 @@ +// Apps Scripts may only run for ~5m so we limit the execution +const MAX_DELETE_PER_LOOP = 1000 + +function cleanup() { + trashByQuery("label:newsletter older_than:6m") +} + +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) +} diff --git a/appsscript.json b/appsscript.json new file mode 100644 index 0000000..e1fa4a4 --- /dev/null +++ b/appsscript.json @@ -0,0 +1,6 @@ +{ + "timeZone": "Europe/Paris", + "dependencies": { + }, + "exceptionLogging": "STACKDRIVER" +} \ No newline at end of file