How to Retrieve Replied Emails for Gmail

Gists

Description :

This sample script is for retrieving emails which replied for received mails. Because there are no samples which confirm whether the owner (me) replied to the received mails, I created this. The point is as follows.

This sample script is made of Google Apps Script (GAS). But also this can be applied to other languages.

Note :

Sample 1

function main() {
  var threadId = "";
  var thread = GmailApp.getInboxThreads();
  thread.forEach(function(th) {
    th.getMessages().forEach(function(msg) {
      var mm = msg.getThread().getMessages();
      if (mm.length > 0) {
        var temp = [];
        mm.forEach(function(m) {
          var re = /<(\w.+)>/g;
          var from  = m.getFrom();
          var to = m.getTo();
          temp.push({
            from: from.match(re) ? re.exec(from)[1] : from,
            to: to.match(re) ? re.exec(to)[1] : to
          });
        });
        if (temp.length > 1 && threadId != th.getId()) {
          if (temp.filter(function(e){return temp[0].from == e.to}).length > 0) {
            Logger.log("threadId: %s", th.getId())

            // do something

          }
         threadId = th.getId();
        }
      }
    });
  });
}

 Share!