【发布时间】:2016-07-26 02:22:18
【问题描述】:
事实:
我有一个在收件箱中搜索未读电子邮件的脚本,所有未加星标的内容都会从收件箱中删除并应用标签。 有过滤器可以将某些电子邮件地址标记为已加星标。
目标:
将收件箱中的所有内容移动到不相关的文件夹中。 除了加星标的项目。 还有一种方法允许手动拖回收件箱并确保它们留在那里。
问题:
大多数电子邮件都会根据需要进行处理。 只有一些加星标的电子邮件仍在应用脚本,因此从收件箱中移出并标记为“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();
}
}
我使用此链接作为其中的一部分:Gmail Script: search then move to inbox, remove label
【问题讨论】: