在对象 Gmail 线程中找不到函数 removeLabel
Cannot find function removeLabel in object Gmail Thread
我收到医生预约等的电子邮件通知,但只需要保持最新。我正在尝试创建一个 google 脚本来在我从同一提供商收到新提醒时存档旧提醒。
该脚本的基本工作方式是 gmail 过滤器为收到的任何新提醒添加一个标签,然后脚本使用该标签查看是否存在来自该提供商的现有提醒(通过检查另一个标签),然后相应地采取行动(通过更改标签和归档消息)
然而,我一直在第 34 行收到错误 "Cannot find function removeLabel in object Gmail Thread",尽管我认为一切正常
//get the threads with the new message label (new threads that need to be checked by the function)
var newThreadsLabel = GmailApp.getUserLabelByName("@Automate/Keep Only One/New Message")
var newThreads = newThreadsLabel.getThreads(0, 400);
//get the current threads (messages that were previously defined as the "current reminder")
var currentThreadsLabel = GmailApp.getUserLabelByName("@Automate/Keep Only One/Current Reminder")
var currentThreads = currentThreadsLabel.getThreads(0, 400);
//loop through the new threads
for (var i = 0; i < newThreads.length; i++){
var newThread = newThreads[i];
//get the subject for the newThread
var subject = newThread.getFirstMessageSubject();
//loop through the "current reminder" threads to see if they are now old (they have the same subject as the "new message"), archive them if they are, then label the "new thread" as the "current thread"
for (var i = 0; i < currentThreads.length; i++){
var currentThread = currentThreads[i];
//check if any of the "current threads" have the same subject as the "new thread", and is not the "new thread" itself
if(currentThread.getFirstMessageSubject() == subject){
//Now, we need to make sure that we don't archive the current thead itself (in some cases gmail may have bundled them into the same thread)
//Get the labels on the "current thread"
var labels = currentThreads[i].getLabels();
//check to see if the labels on the "current thread" include the newThreadsLabel
if(labels.indexOf(newThreadsLabel) !== -1){
//if the "new thread" and "current thread" are the same dont do anything because we don't need to archive it
}else{
//if they are not the same, archive the currentThread and remove the currentThreadsLabel
currentThread.removelabel(currentThreadsLabel);
currentThread.moveToArchive();
}
}
}
//remove the new thread label, then add the current thread label (new thread becomes the "current reminder" thread)
newThread.removeLabel(newThreadsLabel);
newThread.addLabel(currentThreadsLabel);
}
}
我仔细检查了文档,这似乎是使用 removeLabel 的正确方法。为什么我会收到此错误?
您是否缺少大写字母 "L"?
我认为:else{
//if they are not the same, archive the currentThread and remove the currentThreadsLabel
currentThread.removelabel(currentThreadsLabel);
currentThread.moveToArchive();
应该是这样的:else{
//if they are not the same, archive the currentThread and remove the currentThreadsLabel
currentThread.removeLabel(currentThreadsLabel);
currentThread.moveToArchive();
我收到医生预约等的电子邮件通知,但只需要保持最新。我正在尝试创建一个 google 脚本来在我从同一提供商收到新提醒时存档旧提醒。
该脚本的基本工作方式是 gmail 过滤器为收到的任何新提醒添加一个标签,然后脚本使用该标签查看是否存在来自该提供商的现有提醒(通过检查另一个标签),然后相应地采取行动(通过更改标签和归档消息)
然而,我一直在第 34 行收到错误 "Cannot find function removeLabel in object Gmail Thread",尽管我认为一切正常
//get the threads with the new message label (new threads that need to be checked by the function)
var newThreadsLabel = GmailApp.getUserLabelByName("@Automate/Keep Only One/New Message")
var newThreads = newThreadsLabel.getThreads(0, 400);
//get the current threads (messages that were previously defined as the "current reminder")
var currentThreadsLabel = GmailApp.getUserLabelByName("@Automate/Keep Only One/Current Reminder")
var currentThreads = currentThreadsLabel.getThreads(0, 400);
//loop through the new threads
for (var i = 0; i < newThreads.length; i++){
var newThread = newThreads[i];
//get the subject for the newThread
var subject = newThread.getFirstMessageSubject();
//loop through the "current reminder" threads to see if they are now old (they have the same subject as the "new message"), archive them if they are, then label the "new thread" as the "current thread"
for (var i = 0; i < currentThreads.length; i++){
var currentThread = currentThreads[i];
//check if any of the "current threads" have the same subject as the "new thread", and is not the "new thread" itself
if(currentThread.getFirstMessageSubject() == subject){
//Now, we need to make sure that we don't archive the current thead itself (in some cases gmail may have bundled them into the same thread)
//Get the labels on the "current thread"
var labels = currentThreads[i].getLabels();
//check to see if the labels on the "current thread" include the newThreadsLabel
if(labels.indexOf(newThreadsLabel) !== -1){
//if the "new thread" and "current thread" are the same dont do anything because we don't need to archive it
}else{
//if they are not the same, archive the currentThread and remove the currentThreadsLabel
currentThread.removelabel(currentThreadsLabel);
currentThread.moveToArchive();
}
}
}
//remove the new thread label, then add the current thread label (new thread becomes the "current reminder" thread)
newThread.removeLabel(newThreadsLabel);
newThread.addLabel(currentThreadsLabel);
}
}
我仔细检查了文档,这似乎是使用 removeLabel 的正确方法。为什么我会收到此错误?
您是否缺少大写字母 "L"?
我认为:else{
//if they are not the same, archive the currentThread and remove the currentThreadsLabel
currentThread.removelabel(currentThreadsLabel);
currentThread.moveToArchive();
应该是这样的:else{
//if they are not the same, archive the currentThread and remove the currentThreadsLabel
currentThread.removeLabel(currentThreadsLabel);
currentThread.moveToArchive();