Posts

Showing posts from June, 2014

GmailThread ID is evil

Seems like GmailThread.getId() isn't always persistent. What good is a primary key which can occasionally change its value? I've now verified that this behavior is so unexpected that it is documented as well.

The recommended workaround is to not use the Thread ID, but use the ID of each message instead. However, this gets messy as if you want a persistent reference to a thread, you need to do the following dance:

var id = thread.getMessages()[0].getId(); // serialize id, and read it back later var thread2 = GmailApp.getMessageById(id).getThread();
Which kind of defeats the purpose of not needing to do slow fetching of all messages of each thread to draw conclusions about the thread itself when processing a search result. Yes, I'm trying to simulate Gmail filters by hand and need to watch out for quotas. I think I'm going for a hack based on getFirstMessageSubject() and/or getPermaLink(). And before you ask: no, there is no such thing as getThreadByPermaLink().

After see…