Difference between revisions of "Google"

From Wiki2
(Created page with "https://code.google.com/apis/ajax/playground/#localsearch")
 
Line 1: Line 1:
===cleanUp old emails===
# select emails of the type you want to get rid of after a bit of time and filter them to 'temp' folder
# cleanUp script will run every hour and get rid of them
    function cleanUp() {
      var delayDays = 9 // Enter # of days before messages are moved to trash
      var maxDate = new Date();
      maxDate.setDate(maxDate.getDate()-delayDays);
      var label = GmailApp.getUserLabelByName("temp");
      var inc = 100;
      var start = 0;
      do  {
        var threads = label.getThreads(start,inc);
        Logger.log(threads.length)
        for (var i = 0; i < threads.length; i++) {
          Logger.log(threads[i].getLastMessageDate())
          if (threads[i].getLastMessageDate()<maxDate)
          {
            threads[i].moveToTrash();
          }
        } 
        start += inc;
      } while(threads.length===inc);
    }
getThreads has a max of 500 so you have to do them in chunks
https://code.google.com/apis/ajax/playground/#localsearch
https://code.google.com/apis/ajax/playground/#localsearch

Revision as of 10:34, 24 May 2016

cleanUp old emails

  1. select emails of the type you want to get rid of after a bit of time and filter them to 'temp' folder
  2. cleanUp script will run every hour and get rid of them
   function cleanUp() {
     var delayDays = 9 // Enter # of days before messages are moved to trash
     var maxDate = new Date();
     maxDate.setDate(maxDate.getDate()-delayDays);
     var label = GmailApp.getUserLabelByName("temp");
     var inc = 100;
     var start = 0;
     do  { 
       var threads = label.getThreads(start,inc);
       Logger.log(threads.length) 
       for (var i = 0; i < threads.length; i++) {
         Logger.log(threads[i].getLastMessageDate())
         if (threads[i].getLastMessageDate()<maxDate)
         {
           threads[i].moveToTrash();
         }
       }   
       start += inc;
     } while(threads.length===inc);
   }

getThreads has a max of 500 so you have to do them in chunks

https://code.google.com/apis/ajax/playground/#localsearch