2

I'm learning Google-App-Script. An I have written a very simply script to manage my emails:

var threads = GmailApp.search('label:Project1 is:unread');
GmailApp.markThreadsRead(threads);

This script works nearly perfect. But when I have more then 100 unread emails in the Label "Porject1" I get the Error-Message that max. 100 Threads are allowed to change.

How can i limit my search command to 99 hits? Or is there another way to manage all hits in one step?

4

2 回答 2

2

You can use the splice method:

function mailReader(){
  var bigThreads = GmailApp.search('label:Project1 is:unread');

  // While bigthreads bigger than 100 threads
  while(bigThreads.length>99) {

    // Split the bigThreads array in two
    var littlethreads = bigThreads.splice(0,99); 
    // Mark those threads as unread
    GmailApp.markThreadsRead(littlethreads);
  }

  // Mark the rest of the threads on bigThreads
  GmailApp.markThreadsRead(bigThreads);
}
于 2017-08-11T10:31:00.077 回答
0

To answer this part of your question:

How can i limit my searchcommand to 99 hit´s?

you can use:

var threads = GmailApp.search('label:Project1 is:unread',0,100);

Also note the max thread results I believe is 500.

于 2017-08-12T05:08:21.433 回答