1

我们公司最近从 Exchange 2007 迁移到 Google Apps for Business。我们有几个共享邮箱具有相当复杂和广泛的文件夹结构,并被要求在这些邮箱中完全实施标签技术(以优化搜索)。

例如说,迁移后,曾经在 MyCompany/Projects/2012/Q3/Approved Projects/StackOverflow(文件夹结构)中的对话现在具有标签 MyCompany/Projects/2012/Q3/Approved Projects/StackOverflow。这里的意图是该对话必须使用标签 MyCompany、Projects、2012、Q3、Approved Projects、StackOverflow 进行标记。

我已经编写了一个完全执行此操作的脚本(至少在我的测试环境中)。问题是,根据我所阅读的内容,您可以对 Google API 执行的调用次数存在某些限制。此外,脚本执行时间非常非常差。

我想知道是否有办法以某种方式在客户端执行操作并将它们批量发送到谷歌 API。我已阅读有关缓存服务的信息,并且想知道我是否在寻找正确的方向。

这是我的脚本:

function addLabels() {
  //Get all labels
  var allLabels = GmailApp.getUserLabels();

  for (var i = 0; i < allLabels.length; i++) {
    var label = allLabels[i];//label to get the threads from
    var threads = label.getThreads();  //threads assigned with label
    var labels = label.getName().split("/");//array of new label names

    //add the new labels to the specified threads only if there's a "/" in the label's name
    if(label.getName().indexOf("/") != null){
      for (var a = 0; a < labels.length; a++){
        trace("Adding label '" + labels[a] + "' to "+ threads.length +" threads in '"+ label.getName() + "'.");

        //create a new label with the specified name and add it to the threads
        //var newLabel = GmailApp.createLabel(labels[a]);//comment this line for test purposes
        //newLabel.addToThreads(threads);//comment this line for test purposes
      }
    }
  }
}
function trace(message){
  Logger.log(message);
}

提前致谢!

4

1 回答 1

0

您可能希望分阶段运行此脚本。第一阶段是确定所有需要创建的新标签以及应该分配给它们的线程。第二阶段是创建这些标签。最后阶段是将这些标签分配给线程。如果您正在处理大量电子邮件,您可能需要对这项工作进行分片,保留待处理的工作队列,并使用触发器继续处理。

于 2012-07-19T19:00:53.803 回答