I'm attempting to get a count of ALL of the emails in a user's mailbox using the Gmail API. That means running something like
do{
page = request.execute();
if (page.getMessages() != null){
totalSize += page.getMessages().size();
}
request.setPageToken(page.getNextPageToken());
}while (request.getPageToken() != null && request.getPageToken().length() > 0);
The issue is that for large mailboxes, this can be a long process, taking many API calls. For instance, one mailbox with 31,000 emails takes well over a minute to run, and takes 300+ iterations to do so.
Is there a better way?
I've tried using the maxResults parameter, but it defaults to 100 and ignores any values >100. Batch processing wouldn't work, because there's no way to know how many requests you have to make until you've iterated through every page already. And the resultSizeEstimate
property in the List response is absurdly inaccurate.