Home > Net >  Is deleting Gmail thread specific enough to delete only messages from a specific email?
Is deleting Gmail thread specific enough to delete only messages from a specific email?

Time:02-23

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:

  1. the thread id is the same id for the first thread message but the first message might be from other sender.

  2. the message will be deleted permanently

  3. 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.


  1. Instead using the thread id, iterate over the thread messages to check the sender, if it matches then "delete" the message
  2. Instead of using "remove" use "trash"
  3. 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.
  4. 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

  • Related