Need help optimizing a google apps script that labels emails

前端 未结 3 1596
自闭症患者
自闭症患者 2020-12-23 23:45

Gmail has a issue where conversation labels are not applied to new messages that arrive in the conversation thread. issue details here

We found a Google Apps Script

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-24 00:12

    This will find individual messages that do not have a label and apply the label of the associated thread. It takes much less time because it's not relabeling every single message.

    function label_unlabeled_messages() {
      var unlabeled = GmailApp.search("has:nouserlabels -label:inbox -label:sent -label:chats -label:draft -label:spam -label:trash");
    
      for (var i = 0; i < unlabeled.length; i++) {
        Logger.log("thread: " + i + " " + unlabeled[i].getFirstMessageSubject());
        labels = unlabeled[i].getLabels();
        for (var j = 0; j < labels.length; j++) {
          Logger.log("labels: " + i + " " + labels[j].getName());
          labels[j].addToThread(unlabeled[i]);
        }
      }
    }
    

提交回复
热议问题