Gmail 脚本:过滤器、星标和 gmailApp.search,但有些电子邮件会漏掉
Gmail script: Filters, stars and gmailApp.search, but some emails fall through the cracks
事实:
我有一个脚本可以在收件箱中搜索未读电子邮件,任何未加星标的内容都会从收件箱中删除并应用标签。
有适当的过滤器可以将某些电子邮件地址标记为已加星标。
目标:
将收件箱中的所有内容移至不相关的文件夹。
除了 已加星标的项目。
还有一种方法允许手动拖回收件箱并确保它们留在那里。
问题:
大多数电子邮件都会根据需要进行处理。
只有一些加星标的电子邮件仍在应用脚本,因此从收件箱中移出并标记为 "newLabel"
感谢您的帮助。如果有更好的方法来完成同样的事情,我会改用它。
/**
* Get the label, or create it if it doesn't exist
*/
function _getAssistLabel() {
/**
* If you'd like your label to say something different, modify it here
*/
var assist_label_text = "newLabel";
/**
*Get the label
*/
var label = GmailApp.getUserLabelByName(assist_label_text);
/**
*if Label isn't found, create it
*/
if (label == null) {
var label = GmailApp.createLabel(assist_label_text);
}
return label;
}
/**
* Search for starred, unread messages in the inbox
* apply a label
* then archive message (remove from inbox)
*/
function addAssistLabels() {
var label = _getAssistLabel();
/**
* If a message is unread, and is in the inbox and is NOT starred...
*/
var threads = GmailApp.search('is:unread in:inbox -label:Starred -label:Sales');
/** ..then label the message and remove it from the inbox.
* This will make the message show up in the "folder"
*/
for (var i = 0; i < threads.length; i++) {
label.addToThread(threads[i]);
threads[i].moveToArchive();
}
}
/**
* Force threads with starred emails and any with label "forBoss" to return to inbox
*/
function forceInbox() {
var label = GmailApp.getUserLabelByName("newLabel");
var threads = GmailApp.search('label: newLabel label:forBoss');
for (var i = 0; i < threads.length; i++) {
label.removeFromThread(threads[i]);
threads[i].moveToInbox();
}
}
我使用了这个 link 部分内容:
您的第一个线程没有正确接收邮件。
var threads = GmailApp.search('is:unread in:inbox -label:Starred -label:Sales');
您表示
I have a standalone script that searches inbox for unread email, and anything that isn't starred are
removed from inbox and applied label.
GmailApp.search()
应该只使用 is:unread
in:inbox
作为你想要的。
此外,使用搜索查询参数 label:
之前不应有破折号。
查看接受的搜索查询参数列表的文档here
事实:
我有一个脚本可以在收件箱中搜索未读电子邮件,任何未加星标的内容都会从收件箱中删除并应用标签。 有适当的过滤器可以将某些电子邮件地址标记为已加星标。
目标:
将收件箱中的所有内容移至不相关的文件夹。 除了 已加星标的项目。 还有一种方法允许手动拖回收件箱并确保它们留在那里。
问题:
大多数电子邮件都会根据需要进行处理。 只有一些加星标的电子邮件仍在应用脚本,因此从收件箱中移出并标记为 "newLabel"
感谢您的帮助。如果有更好的方法来完成同样的事情,我会改用它。
/**
* Get the label, or create it if it doesn't exist
*/
function _getAssistLabel() {
/**
* If you'd like your label to say something different, modify it here
*/
var assist_label_text = "newLabel";
/**
*Get the label
*/
var label = GmailApp.getUserLabelByName(assist_label_text);
/**
*if Label isn't found, create it
*/
if (label == null) {
var label = GmailApp.createLabel(assist_label_text);
}
return label;
}
/**
* Search for starred, unread messages in the inbox
* apply a label
* then archive message (remove from inbox)
*/
function addAssistLabels() {
var label = _getAssistLabel();
/**
* If a message is unread, and is in the inbox and is NOT starred...
*/
var threads = GmailApp.search('is:unread in:inbox -label:Starred -label:Sales');
/** ..then label the message and remove it from the inbox.
* This will make the message show up in the "folder"
*/
for (var i = 0; i < threads.length; i++) {
label.addToThread(threads[i]);
threads[i].moveToArchive();
}
}
/**
* Force threads with starred emails and any with label "forBoss" to return to inbox
*/
function forceInbox() {
var label = GmailApp.getUserLabelByName("newLabel");
var threads = GmailApp.search('label: newLabel label:forBoss');
for (var i = 0; i < threads.length; i++) {
label.removeFromThread(threads[i]);
threads[i].moveToInbox();
}
}
我使用了这个 link 部分内容:
您的第一个线程没有正确接收邮件。
var threads = GmailApp.search('is:unread in:inbox -label:Starred -label:Sales');
您表示
I have a standalone script that searches inbox for unread email, and anything that isn't starred are removed from inbox and applied label.
GmailApp.search()
应该只使用 is:unread
in:inbox
作为你想要的。
此外,使用搜索查询参数 label:
之前不应有破折号。
查看接受的搜索查询参数列表的文档here