title: Google Apps Script - GMail to Google Sheets - Get Oldest Unread Email in Thread's .csv Attachment
body: <p>First off: JavaScript novice. Any help/direction you could provide would be greatly appreciated.</p>
  
  <p>I have a new business case in which a GMail box is going to receive an e-mail 4 times a day with the same subject line, but with a new .csv attachment each time. I've created the label within GMail, and it is attaching successfully to each email. I need to be able to use Apps Script to only process the oldest unread e-mail. The part to parse the .csv is already tested/successful/completed. However, each time I run it, it's looping through all the files, and processing them again.</p>
  
  <p>Here is the current code for getting information from the GMail Box</p>
  
  <pre><code>// GMail Details
  var gmailLabel = ('_Projects/ProjectLabel');
  var label = GmailApp.getUserLabelByName(gmailLabel);
  var unreadCount = label.getUnreadCount();
  var gmailThreads = GmailApp.getUserLabelByName(gmailLabel).getThreads();
  Logger.log(label.getUnreadCount());
    for (var i = 0; i &lt; gmailThreads.length; i++) {
     Logger.log(gmailThreads[i].getFirstMessageSubject());
    }
  }
  </code></pre>
  
  <p>The log does show that there are 2 unread threads correctly, and does display the subject line in the logger. However, within the gmailThreads array, I can only see the object numbers for the threads. How could I get object numbers for each of the e-mails belonging to those threads? This would be the e-mail that I would need to parse the .csv attachment first, then mark as read (or change the label of) within the loop.</p>
  
  <p>Thanks again for looking!</p>