如何从 Gmail API 获取没有原始消息的回复消息 [英] How to get the reply message without the original message from the Gmail API

查看:20
本文介绍了如何从 Gmail API 获取没有原始消息的回复消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在没有原始消息的线程中获得回复消息.但是,当我使用 Users.messages: GET 或 Users.threads: GET 时,我也会收到带有原始消息(不需要)的回复(根据需要).请参阅下面的代码截图.

I would like to get the reply message in a thread without the original message. However, when I use either Users.messages: GET or Users.threads: GET, I receive the reply (as desired) with the original message (undesired) as well. See screenshot below code.

(据我所知,这个问题也被提出 这里,但是我没有发现提议的解决方案回答了这个问题,提议的解决方案的发布者建议我开始一个新问题.我试过了但是,Tholle 建议的 Users.threads 收到了相同的结果.)

(This question, as far as I can tell, was also posed here, however I did not find that the proposed solution answers the question and the poster of the proposed solution suggested I start a new question. I tried with Users.threads as Tholle suggests however received the same result.)

我是菜鸟,非常感谢任何和所有帮助,如果我遗漏了一些明显的东西,我深表歉意.

I'm a noob, so any and all help is greatly appreciated and I apologize if I'm missing something obvious.

var gapiGETRequest = function (gapiRequestURL)
  {
      var xmlHttp = new XMLHttpRequest();
      xmlHttp.open( "GET", gapiRequestURL, false );
      xmlHttp.send( null );
      return xmlHttp.responseText;
  }

var gapiRequestInboxMessagesAndToken = "https://www.googleapis.com/gmail/v1/users/me/messages?q=-label%3ASENT+in%3AINBOX&access_token=" + thisToken
var allMessagesReceived = gapiGETRequest(gapiRequestInboxMessagesAndToken)
var allMessagesObject = JSON.parse(allMessagesReceived)
var messageIdsOfReceivedMessages = [];
var getIdsOfReceivedMessages = function(responseObject){
  for(var i=0; i < responseObject.messages.length; i ++) {
    messageIdsOfReceivedMessages.push(responseObject.messages[i].id);
  }
}

var messageContentsArr = [];
var getMessageContents = function(messageIdList)
{
  for(var i=0; i < messageIdList.length; i++)
  {
    var gapiRequestMessageWithId = "https://www.googleapis.com/gmail/v1/users/me/messages/" + messageIdList[i] + "?access_token=" + thisToken
    var currentMessage = JSON.parse(gapiGETRequest(gapiRequestMessageWithId))
    var encodedMessageContents = currentMessage.payload.parts[0].body.data
    var decodedMessageContents = atob(encodedMessageContents.replace(/-/g, '+').replace(/_/g, '/'));
    messageContentsArr.push(decodedMessageContents)
  }
}

getIdsOfReceivedMessages(allMessagesObject);
getMessageContents(messageIdsOfReceivedMessages);

回应

推荐答案

您将收到完整的回复消息.当报告回复时,他们引用了原始消息,并且原始文本在回复消息中.您可能只想做 Gmail 和许多其他现代电子邮件应用程序所做的事情,并折叠/隐藏任何以 > 开头的回复文本.

You are getting the full reply message. When the report replied, they quoted the original message and this the text of the original is in the reply message. You may just want to do what Gmail and many other modern emails apps do and collapse/hide any reply text which begins with >.

这篇关于如何从 Gmail API 获取没有原始消息的回复消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆