Google Apps脚本GmailApp-标签线程包括标签外的邮件 [英] Google Apps Script GmailApp - Label threads include off-label messages

查看:153
本文介绍了Google Apps脚本GmailApp-标签线程包括标签外的邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下方法检索标签的主题和消息:

I am using the following to retrieve the threads and messages for my label:

var threads = GmailApp.search("label:labelName to:forwarded@email.addr");    
//Same result returned from using
//var threads = GmailApp.getUserLabelByName(labelName).getThreads();

for (var i=0; i<threads.length; i++){    
  var messages = GmailApp.getMessagesForThread(threads[i]);
  for (var j=0; j<messages.length;j++){
    var msg=messages[j].getPlainBody();
    ...
  }
}

我正在成功检索数据.但是,存在一些孤立的事件,其中,发送到与搜索中指定的地址不同且与标签不相关的地址的消息被聚集到线程中.我可以通过电子邮件帐户本身中的对话视图"确认这一点.

I am successfully retrieving data. However, there are isolated incidents where messages sent to an address that is not the one specified in the search and are not associated with the label are clumped into the thread. I can confirm this with "conversation view" in the email account itself.

我正在尝试仅检索符合我的搜索条件的消息,而不是属于线程成员但不属于标签成员的消息.我该如何可靠地做到这一点?

I am attempting to retrieve JUST the messages that match my search criteria, not the ones that are a member of the thread but not a member of the label. How can I do this reliably?

因此,在进行了广泛研究之后,我得出结论,目前无法通过脚本API做到这一点.但是,脚本现在可以通过将完整的GMail API用作资源,然后在您的Google Developer Center中启用GMail api来包含完整的GMail API.使用完整的GMail API,以下代码可用于比较消息标签,但是使用Scripts API则无法实现.我已经提交了功能请求

So after extensive research, I've concluded this currently isn't possible with the scripts API. However, scripts can now include the full GMail API by enabling it as a resource and then enabling GMail api in your Google Developer center. With the full GMail API the below code can be used to compare message labels, but this is not otherwise possible with the Scripts API. I have filed a feature request here.

与上面的代码一起使用,以下内容将用于验证消息标签:

Inline with the above code, the below will serve to verify message labels:

var abort=true;
var labelID="permenant_label_id"; //NOT label name.
//Compare message label
var compare=Gmail.Users.Messages.get('me', messages[j].getID());
for (var l=0; l<compare.labelIds.length;l++) {
  //if abort==false then message verified against label.
  abort = (compare.labelIds[l]!=labelID)?true:false;
  if (!abort) break; //stop sorting labels
}   

推荐答案

因此,经过大量研究,我得出结论,脚本API目前无法实现.但是,脚本现在可以通过将完整的GMail API用作资源,然后在您的Google Developer Center中启用GMail api来包含完整的GMail API.使用完整的GMail API,以下代码可用于比较消息标签,但是使用Scripts API则无法实现.

So after extensive research, I've concluded this currently isn't possible with the scripts API. However, scripts can now include the full GMail API by enabling it as a resource and then enabling GMail api in your Google Developer center. With the full GMail API the below code can be used to compare message labels, but this is not otherwise possible with the Scripts API.

与上面的代码一起使用,以下内容将用于验证消息标签:

Inline with the above code, the below will serve to verify message labels:

var abort=true;
var labelID="permenant_label_id"; //NOT label name.
//Compare message label
var compare=Gmail.Users.Messages.get('me', messages[j].getID());
for (var l=0; l<compare.labelIds.length;l++) {
  //if abort==false then message verified against label.
  abort = (compare.labelIds[l]!=labelID)?true:false;
  if (!abort) break; //stop sorting labels
}   

这篇关于Google Apps脚本GmailApp-标签线程包括标签外的邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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