Gmail脚本:过滤器,星星和gmailApp.search,但一些电子邮件通过裂缝 [英] Gmail script: Filters, stars and gmailApp.search, but some emails fall through the cracks

查看:182
本文介绍了Gmail脚本:过滤器,星星和gmailApp.search,但一些电子邮件通过裂缝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

事实:



我有一个脚本,用于搜索收件箱中的未读电子邮件,而任何未加星号的内容将从收件箱和应用的标签中删除。
有些过滤器将某些电子邮件地址标记为已加星标。



目标:



将所有内容从收件箱移至不相关的文件夹。
之外的已加星标的项目。
还有一种方法,可以手动拖回到收件箱,并确保它们停留在那里。



问题:



大多数电子邮件都会根据需要进行处理。
只有一些已加星标的电子邮件仍然可以使用该脚本,因此已从收件箱中移出并标记为newLabel。



感谢您的帮助。如果有更好的方法来完成同样的事情,我会将其切换。

  / ** 
*获取标签,或创建标签(如果不存在)
* /
function _getAssistLabel(){
/ **
*如果您想让标签说不同的东西,在这里修改
* /
var assist_label_text =newLabel;
/ **
*获取标签
* /
var label = GmailApp.getUserLabelByName(assist_label_text);
/ **
*如果Label找不到,创建它
* /
if(label == null){
var label = GmailApp.createLabel assist_label_text);
}

返回标签;
}


/ **
*在收件箱中搜索已加星标的未读消息
*应用一个标签
*然后归档消息(从收件箱中删除)
* /
function addAssistLabels(){
var label = _getAssistLabel();
$ b $ / **
*如果邮件未读,并且位于收件箱中,且未加星标...
* /
var threads = GmailApp.search ('是:未读:inbox -label:Starred -label:Sales');

/ ** ..然后标记邮件并将其从收件箱中删除。
*这将使消息显示在文件夹
* /
中(var i = 0; i< threads.length; i ++){
标签。 addToThread(线程[I]);
threads [i] .moveToArchive();
}
}






/ **
*强制加星标电子邮件和任何带有标签的forBoss返回收件箱
* /

功能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脚本:搜索然后移动到收件箱,删除标签

解决方案

您的第一个线程不会正确地收取邮件。 $ b

  var threads = GmailApp.search('is:unread in:inbox -label:Starred -label:Sales'); 

您表示


我有一个独立脚本,用于搜索收件箱中的未读电子邮件,而任何未加星标的文件都是从收件箱和应用标签中删除


GmailApp.search()应该只使用 is:unread 在:收件箱为你想要的。
此外,使用搜索查询参数 label:不应该有破折号。



查看已接受的搜索查询参数列表的文档此处 p>

FACTS:

I have a script that searches inbox for unread email, and anything that isn't starred are removed from inbox and applied label. There are filters in place to label certain email addys as starred.

GOAL:

To move everything from inbox to a folder that is not relevant. Except the items that are starred. Also have a method that allows for manually dragging back to inbox and make sure they stay there.

PROBLEM:

Most all emails are processed as needed. Only some of the starred emails are still getting the script applied to, and are thus moved from inbox and labeled "newLabel"

Thanks for your help. If there is a better way to accomplish the same thing, I'll switch it up.

/**
* 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();
  }
}

I used this link for part of this: Gmail Script: search then move to inbox, remove label

解决方案

Your first thread is not picking up mails correctly.

var threads = GmailApp.search('is:unread in:inbox -label:Starred -label:Sales');

You indicated that

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() should only use is:unread in:inbox for what you want. Also, using the search query parameter label: shouldn't have a dash before it.

Check out the documentation for the list of accepted search query parameters here

这篇关于Gmail脚本:过滤器,星星和gmailApp.search,但一些电子邮件通过裂缝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆