我有以下标签结构
+------------+------------+---------------+
| 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
回顾
如何让查询同时搜索多个标签,例如
"label:unread"+ "label:00-fruit/01-apples/red"
和
"label:unread"+ "label:02-veggies/01-peppers/red"
还有。如何解决 Status Running
问题?
最佳答案
""
是一个空格,用作AND
运算符。OR
和{}
可以用作OR
运算符。
使用上述运算符,您的目标可以实现。
当您想搜索带有
label:unread
和label:00-fruit/01-apples/red
的邮件时,请使用搜索查询作为如下。标签:未读标签:00-水果/01-苹果/红色
当您想搜索带有
label:unread
和label:00-fruit/01-apples/red
或label: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/