From 5b93a0a4499cee949c22e22fd04d078d2847d4e2 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Sat, 20 Oct 2018 13:37:57 +0200 Subject: [PATCH] Initial version --- .clasp.json | 1 + Code.js | 22 ++++++++++++++++++++++ appsscript.json | 6 ++++++ 3 files changed, 29 insertions(+) create mode 100644 .clasp.json create mode 100644 Code.js create mode 100644 appsscript.json 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