title: GmailApp.getMessagesForThreads() returns too many messages
body: <p>I want to return a list of all email subjects received at a specified day, at my Gmail account. If there is more than one message with the same subject, I want to have a number of how many there are. This is what I did:</p>
  <pre><code>var emailThreads = GmailApp.search(&quot;subject:&lt;partial_subject&gt; after:2020/8/30 before:2020/8/31&quot;);
  var messages = GmailApp.getMessagesForThreads(emailThreads);
  </code></pre>
  <p>This returns &quot;an array of arrays of messages, where each item in the outer array corresponds to a thread and the inner array contains the messages in that thread&quot;.</p>
  <p>I try to access data I need like this:</p>
  <pre><code>for (i = 0; i &lt; messages.length; i++) {
    messages[i][0].getSubject() // a subject
    messages[i].length          // number of messages with the same subject
  }
  </code></pre>
  <p>However, this returns more messages than is displayed in Gmail UI.</p>
  <p>Here's what I've noticed:</p>
  <ul>
  <li>it only happens to threads with more than one message</li>
  <li>it doesn't happen to all threads with more than one message</li>
  <li>every time a run my script for the same day, the result is the same</li>
  <li>when I run my script for different days, the result is different even though the same emails were received</li>
  </ul>
  <p>Considering that this code is very simple and I'm only using methods delivered by google, I assume I must have misunderstood something or Gmail is doing something weird with messages in threads.</p>
  <p>Any ideas what could this be and how to work around it?</p>
  <hr />
  <p>Edit:
  I've noticed that there is a &quot;Don't include chats&quot; checkbox in gmail filter, which adds &quot;-in:chats&quot; into search query, but it didn't help either.
  I also tried adding &quot;in:inbox&quot; to the query, but with no change in the result.</p>