在 30 天后永久删除之前,如何从垃圾箱中排除线程消息?

how can I exclude in a thread messages from the trash before they are permanently deleted in 30 days?

过滤器将某些电子邮件放在标签中 然后我用

阅读它们
var folder = "[Gmail]/MAJTableauLR";
  var threads = GmailApp.getUserLabelByName(folder).getThreads();

并提取数据 然后线程被丢弃。

for (n in threads) {
        var message = threads[n].getMessages();
        message[0].moveToTrash();
    }

在同一脚本的后续执行过程中,它包括放入垃圾箱的邮件,而如果我将它们放入垃圾箱,最好将它们从该文件夹中排除。那么如何在 30 天后将这些邮件永久删除之前将它们从垃圾箱中排除?

你有两个选择:

永久删除

与其移至回收站,不如永久删除它们。您需要启用 Gmail API V1:

function main(){
  const threads = GmailApp.getUserLabelByName('Custom').getThreads()
  for(const th of threads){
    th.getMessages().forEach(msg=>deletePermanently(msg.getId()))
  }
}

function deletePermanently(msgId){
  Gmail.Users.Messages.remove('me', msgId)
}

检查 message/thread 是否已在回收站中

你有两种方法 GmailMessage and GmailThread for check if it is already trashed: isInTrash()

function main() {
  const threads = GmailApp.getUserLabelByName('Custom').getThreads()
  for (const th of threads) {
    //Will jump to the next no in trash
    if (th.isInTrash()) continue
    for (const msg of th.getMessages()) {
      // Same for msgs
      if (msg.isInTrash()) continue
    }
  }
}