mirror of
https://github.com/Luzifer/gmail-manage.git
synced 2024-12-23 04:21:21 +00:00
Add more logging, remove logging from lib
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
d3480f5c34
commit
a5bcc4d2fd
2 changed files with 14 additions and 2 deletions
14
src/index.js
14
src/index.js
|
@ -1,9 +1,12 @@
|
||||||
// executeMailCleanup takes the queries defined in config and deletes
|
// executeMailCleanup takes the queries defined in config and deletes
|
||||||
// mails matched by those filters
|
// mails matched by those filters
|
||||||
function executeMailCleanup() {
|
function executeMailCleanup() {
|
||||||
|
console.log("Starting mail cleanup...")
|
||||||
|
|
||||||
for (let i = 0; i < config.cleanup_queries.length; i++) {
|
for (let i = 0; i < config.cleanup_queries.length; i++) {
|
||||||
let query = config.cleanup_queries[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
|
// matches them to the filters already defined in the Gmail account
|
||||||
// and afterwards applies reqired changes
|
// and afterwards applies reqired changes
|
||||||
function applyFilterDefinition() {
|
function applyFilterDefinition() {
|
||||||
|
console.log("Starting to apply filters...")
|
||||||
|
|
||||||
let presentFilters = getHashedFilters()
|
let presentFilters = getHashedFilters()
|
||||||
let definedFilters = {}
|
let definedFilters = {}
|
||||||
|
|
||||||
|
@ -34,15 +39,22 @@ function applyFilterDefinition() {
|
||||||
definedFilters[hashFilter(filter)] = filter
|
definedFilters[hashFilter(filter)] = filter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let removedFilters = 0
|
||||||
|
let createdFilters = 0
|
||||||
|
|
||||||
for (let hash in presentFilters) {
|
for (let hash in presentFilters) {
|
||||||
if (hash in definedFilters) continue
|
if (hash in definedFilters) continue
|
||||||
Gmail.Users.Settings.Filters.remove("me", presentFilters[hash].id)
|
Gmail.Users.Settings.Filters.remove("me", presentFilters[hash].id)
|
||||||
console.log(["Removed filter", presentFilters[hash]])
|
console.log(["Removed filter", presentFilters[hash]])
|
||||||
|
removedFilters++
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let hash in definedFilters) {
|
for (let hash in definedFilters) {
|
||||||
if (hash in presentFilters) continue
|
if (hash in presentFilters) continue
|
||||||
Gmail.Users.Settings.Filters.create(definedFilters[hash], "me")
|
Gmail.Users.Settings.Filters.create(definedFilters[hash], "me")
|
||||||
console.log(["Created filter", definedFilters[hash]])
|
console.log(["Created filter", definedFilters[hash]])
|
||||||
|
createdFilters++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("%d filters removed, %d filters created, %d filters untouched", removedFilters, createdFilters, presentFilters.length - removedFilters)
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,5 +94,5 @@ function trashByQuery(query) {
|
||||||
}
|
}
|
||||||
} while (threads.length > 0 && removedThreads < MAX_DELETE_PER_LOOP)
|
} while (threads.length > 0 && removedThreads < MAX_DELETE_PER_LOOP)
|
||||||
|
|
||||||
console.log('Removed %d threads for query "%s"', removedThreads, query)
|
return removedThreads
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue