2012-07-16 65 views
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); 
} 

提前感谢!

回答

0

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