diff --git a/src/index.js b/src/index.js index af8edf9..c2f7135 100644 --- a/src/index.js +++ b/src/index.js @@ -1,9 +1,12 @@ // executeMailCleanup takes the queries defined in config and deletes // mails matched by those filters function executeMailCleanup() { + console.log("Starting mail cleanup...") + for (let i = 0; i < config.cleanup_queries.length; i++) { let query = config.cleanup_queries[i] - trashByQuery(query) + let removedThreads = trashByQuery(query) + console.log('Removed %d threads for query "%s"', removedThreads, query) } } @@ -11,6 +14,8 @@ function executeMailCleanup() { // matches them to the filters already defined in the Gmail account // and afterwards applies reqired changes function applyFilterDefinition() { + console.log("Starting to apply filters...") + let presentFilters = getHashedFilters() let definedFilters = {} @@ -34,15 +39,22 @@ function applyFilterDefinition() { definedFilters[hashFilter(filter)] = filter } + let removedFilters = 0 + let createdFilters = 0 + for (let hash in presentFilters) { if (hash in definedFilters) continue Gmail.Users.Settings.Filters.remove("me", presentFilters[hash].id) console.log(["Removed filter", presentFilters[hash]]) + removedFilters++ } for (let hash in definedFilters) { if (hash in presentFilters) continue Gmail.Users.Settings.Filters.create(definedFilters[hash], "me") console.log(["Created filter", definedFilters[hash]]) + createdFilters++ } + + console.log("%d filters removed, %d filters created, %d filters untouched", removedFilters, createdFilters, presentFilters.length - removedFilters) } diff --git a/src/lib.js b/src/lib.js index 0feda5e..f902cd1 100644 --- a/src/lib.js +++ b/src/lib.js @@ -94,5 +94,5 @@ function trashByQuery(query) { } } while (threads.length > 0 && removedThreads < MAX_DELETE_PER_LOOP) - console.log('Removed %d threads for query "%s"', removedThreads, query) + return removedThreads }