google-apps-script - 一次在 Gmail 线程中搜索多个未读标签的脚本

标签 google-apps-script google-sheets gmail gmail-api

我有以下标签结构

+------------+------------+---------------+
|   label    | sub-label  | sub-sub-label |
+------------+------------+---------------+
| 01-fruit   |            |               |
|            | 01-apples  |               |
|            |            | green         |
|            |            | red           |
|            | 02-oranges |               |
|            |            | red           |
|            |            | orange        |
| 02-veggies |            |               |
|            | 01-peppers |               |
|            |            | green         |
|            |            | red           |
+------------+------------+---------------+

正在使用的脚本是:

function mail2Sheets() {
  var ss = SpreadsheetApp.getActive();
  var sheet = ss.getSheetByName('newRec'); //get the sheet
  var freshLabel = GmailApp.getUserLabelByName("00-fresh"); // in the end, add this label
  const query = "label:unread" + " label:01-fruit"; 
  var foundThreads = GmailApp.search(query);
  var newReceipts = [];
  for (var i = 0; i < foundThreads.length; i++) {

  +++++++ SOME CODE HERE +++++++

    }
  }
  if(!foundThreads.length) return; //  if there are no unread ones, do nothing.
  sheet.getRange(SpreadsheetApp.getActiveSheet().getLastRow()+1,2,newReceipts.length,newReceipts[0].length).setValues(newReceipts); //write to sheet
  GmailApp.markThreadsRead(foundThreads); // mark "foundThreads" as read
  freshLabel.addToThreads(foundThreads); // add label "00-fresh" to "foundThreads"
  GmailApp.refreshThreads(foundThreads); // refresh "foundThreads" for changes to show
}

我可以成功搜索单个标签,例如:const query = "label:unread"+ "label:01-fruit";

还有。
尽管我有 GmailApp.refreshThreads(foundThreads); Execution 从未完成。
相反,它显示 Status Running

enter image description here

回顾

如何让查询同时搜索多个标签,例如
"label:unread"+ "label:00-fruit/01-apples/red"

"label:unread"+ "label:02-veggies/01-peppers/red"

还有。如何解决 Status Running 问题?

最佳答案

  • "" 是一个空格,用作 AND 运算符。
  • OR{} 可以用作 OR 运算符。

使用上述运算符,您的目标可以实现。

  • 当您想搜索带有label:unreadlabel:00-fruit/01-apples/red 的邮件时,请使用搜索查询作为如下。

    标签:未读标签:00-水果/01-苹果/红色

  • 当您想搜索带有label:unreadlabel:00-fruit/01-apples/redlabel:02 的邮件时-veggies/01-peppers/red,请按如下方式使用搜索查询。

      label:unread (label:00-fruit/01-apples/red OR label:02-veggies/01-peppers/red)
    
  •   label:unread {label:00-fruit/01-apples/red label:02-veggies/01-peppers/red}
    

引用:

关于google-apps-script - 一次在 Gmail 线程中搜索多个未读标签的脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65036762/

相关文章:

java - 仅向拥有商业公司邮件地址的人员授予通过 Google oAuth 的访问权限

google-apps-script - Google脚本库: Project Key deprecated?

javascript - Google 脚本数字格式错误

google-apps-script - 应用程序制作工具 : Public facing IP for UrlFetch?

javascript - GAS Google Script - 如何复制值并粘贴到另一个单元格中

google-apps-script - 如何使用应用程序脚本在 Google 电子表格中移动工作表

gmail - 在没有 Google App 域的情况下开发 Gmail 上下文小工具?

javascript - 通过 Google Apps 脚本中的 API 组合 GET 和 POST 请求

google-apps-script - 从 Gmail 导入 XLS - 基于昨天日期的工作表

android - 如何创建选择器 Intent 以从 gmail 应用程序、yahoo 邮件应用程序或浏览器中进行选择?