I made the following algorithm in Google Script which deletes all mails from a specific adress from all folders:
function deleteForever() {
var labelName
labelName="some_mail_address"
var threads = GmailApp.search("in: all from:" labelName);
for (var i = 0; i < threads.length; i ) {
Gmail.Users.Messages.remove("me", threads[i].getId());
}
}
Is this safe to use for my gmail account? (With a trigger such that it runs every minute)
In particular, I am wondering whether a thread can contain multiple mails, and whether this can result in deleting mails which are not from the unwanted sender.
Also, I have seen "in: anywhere" on some webpages. Is this different from "in: all"?
CodePudding user response:
Short answer: No.
It's not "safe" because:
the thread id is the same id for the first thread message but the first message might be from other sender.
the message will be deleted permanently
running a script every minute might consume the daily quota so you might first getting error messages and lately the trigger might be disabled due to having so many errors.
in:anywhere
is not the same as in:all
. The first will return threads labeled as spam and trash but the later doesn't.
- Instead using the thread id, iterate over the thread messages to check the sender, if it matches then "delete" the message
- Instead of using "remove" use "trash"
- If you use "trash" instead of "remove" don't use "in:anywhere" otherwise the same message will be processed over an over until it's deleted permanently.
- Instead of using a trigger scheduled to run every minute, run it every ten minutes or use a lower frequency if you plan to use other time driven triggers.
Related