Book Image

Google Apps Script for Beginners

By : Serge Gabet
Book Image

Google Apps Script for Beginners

By: Serge Gabet

Overview of this book

Table of Contents (16 chapters)
Google Apps Script for Beginners
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
7
Using User Interfaces in Spreadsheets and Documents
Index

Counting, sorting, archiving, and deleting e-mails and threads


We have seen in the earlier examples that it is quite easy to manipulate threads and messages with regard to labels.

Once we get a thread object, we can do what we want with it. A quick look at the documentation shows the many methods available but as I have already mentioned, these operations might take some time and we may easily face issues with the maximum execution time limit of five minutes.

Execution time versus time limit

The solution to this is to proceed with relatively small bunches of threads. A careful approach is to treat 100 threads at a time and continue as long as we need or until it is finished.

Google Apps Script has all the tools we need:

  • A programmable time trigger to automate the process

  • A convenient place to store the number of processed items

  • A way to delete the trigger when it is finished

The following code is an example that will examine all your e-mails and add labels inside every thread according to the thread...