Skip to content

Instantly share code, notes, and snippets.

@berkedel
Forked from balupton/README.md
Created March 12, 2019 06:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save berkedel/6c28542e852a15e8ea5c0c2ad34ffa04 to your computer and use it in GitHub Desktop.
Save berkedel/6c28542e852a15e8ea5c0c2ad34ffa04 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:log@docpad.org";
  
  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