I have an array of strings where each value represents a Gmail Threadid. This looks something like this:
var threadArray = [threadId1, threadId2, threadId3, threadId4, threadId5];
I want to apply a Gmail Label to each of the elements in my array of threadids, but my current approach is not efficient and takes too long to execute. See below:
for (var i = 0; i < threadArray.length; i++)
{
thread = getThreadById(threadArray[i]) // this statement takes too long (several seconds) to execute!!
thread.addLabel(exampleLabel);
}
What's the best approach for applying a Gmail Label to each Gmail Thread in an array of Gmail ThreadIds?
Gmail provides functions like getInboxThreads()
which retrieve many threads at once to return GmailThread[] but its unclear to me how I can construct my own GmailThread[] purely based on the threadids, not my entire inbox.
Has anyone else experienced this issue or found a workaround? I found a similar open issue here: https://code.google.com/p/google-apps-script-issues/issues/detail?id=2598