如何检查Gmail标签是否有嵌套的子标签? [英] How to check if a Gmail label has a nested sub-label?

查看:194
本文介绍了如何检查Gmail标签是否有嵌套的子标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Google Apps Script,是否有一项功能可以检查Gmail标签是否嵌套子标签?如果标签有一个或多个子标签,我想从代码序列中排除它们。

解决方案

没有直接的方法可以从父标签获取标签,但使用简单的 getUserLabels() method 记录在这里,并由以下小代码说明:

 函数getAllLabels(){
var results = [];
var labels = GmailApp.getUserLabels();
for(var i = 0; i< labels.length; i ++){
Logger.log(label:+ labels [i] .getName());
results.push(labels [i] .getName()); (结果[i] .indexOf('/')> 0){记录器。
}
for(var i = 0; i< results.length; i ++) log(results [i] +'有一个subLabel')};






$ b这将显示所有标签的列表,在第二个循环中,您将获得至少包含一个子标签的所有标签的列表。

注意,此脚本必须改进,因为它会考虑 > INBOX (例如但不仅仅是)作为一个标签,它不是你想要的,但是这个部分在一些条件下很容易管理。


Using Google Apps Script, is there a function to check if a Gmail label has nested sub-labels? If a label has one or more sub-labels I want to exclude them from a code sequence.

解决方案

There is no direct method to get labels from a "parent" label but this is quite simple to get using the simple getUserLabels() method documented here and illustrated by the following small code :

function getAllLabels(){
  var results = [];
  var labels = GmailApp.getUserLabels();
  for (var i = 0; i < labels.length; i++) {
    Logger.log("label: " + labels[i].getName());
    results.push(labels[i].getName());
  }
  for (var i = 0; i < results.length; i++) {
    if(results[i].indexOf('/')>0){Logger.log(results[i]+' has a subLabel')};
  }
}

This will show a list of all your labels and from the second loop you'll get a list of all Labels that have at least one sub-Label.

Note that this script has to be improved because it will consider INBOX (for example but not only) as a label which is not really what you want but that part will be easy to manage with a few conditions.

这篇关于如何检查Gmail标签是否有嵌套的子标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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