Skip to content

Instantly share code, notes, and snippets.

@abcarroll
Forked from balupton/README.md
Created January 18, 2019 02:41
Show Gist options
  • Save abcarroll/47f3580657e74efdfec35c0fd8cb9091 to your computer and use it in GitHub Desktop.
Save abcarroll/47f3580657e74efdfec35c0fd8cb9091 to your computer and use it in GitHub Desktop.
Remove script for Gmail that delets all email threads/messages that match search for when Gmail can't do it itself

Remove script for Gmail

function Intialize() {
  return;
}

function Install() {
  ScriptApp.newTrigger("purgeGmail")
           .timeBased().everyMinutes(10).create();

}

function Uninstall() {
  
  var triggers = ScriptApp.getScriptTriggers();
  for (var i=0; i<triggers.length; i++) {
    ScriptApp.deleteTrigger(triggers[i]);
  }
  
}

function purgeGmail() {
  var search = "to:[email protected]";
  
  var threads = GmailApp.search(search, 0, 100);
  
  for (var i=0; i<threads.length; i++) {
    var thread = threads[i];
    thread.moveToTrash();
  }
}
  1. Go to https://script.google.com and create a new script
  2. Copy the above to the script input
  3. Click the save icon
  4. Click the "Run" menu
  5. Click the "Install" submenu entry
  6. Wait a few days, it will delete 100 messages each 10 minutes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment