主题相同的gmail邮件-删除所有(最新消息除外) [英] gmail messages with same subject - delete all but most recent

查看:71
本文介绍了主题相同的gmail邮件-删除所有(最新消息除外)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个脚本来处理具有相同主题的Gmail邮件,例如删除来自XYZ的警报",方法是删除除最新消息以外的所有消息.通常,Gmail将对主题和发件人相同的电子邮件进行处理,但是我收到的这些警报电子邮件无法正常工作.只要警报条件成立,我每天都会收到一封单独的电子邮件.因此,基本上,脚本需要查找具有特定主题和发件人的所有邮件,并删除除最新邮件以外的所有邮件.我敢肯定,这很容易做到,但是我对JavaScript还是一个新手. 我将不胜感激.

I am looking for a script that will process Gmail messages with the same subject, e.g. "Alert from XYZ", by deleting all but the most recent. Normally, Gmail will thread emails of the same subject and sender, but these alert emails I get do not work that way. For as long as the alert condition holds true, I will get a separate email every day. So, basically, the script needs to look for all messages with the specific subject and sender and delete all but the most recent. I'm sure this can be easily done, but I'm still a bit of a novice with JavaScript. I'd appreciate any guidance.

推荐答案

显然,使用时间触发的Google Apps脚本可以相对轻松地完成此操作.我在寻找相同类型的插件或功能,并为自己写了一个解决方案:

This can apparently be done relatively trivially with a time-triggered google apps script. I was looking for the same sort of plugin or feature, and wrote a solution for myself:

function removeAllButMostRecent() {

  var tagList = ["Kickstarter-Happening"];

  for ( var j = 0; j < tagList.length; j++ ) {

    var label = GmailApp.getUserLabelByName( tagList[j] );

    if ( label != null ) {
      var threads = label.getThreads();

      for ( var i = 1; i < threads.length; i++ ) { // skip most recent one
          threads[i].moveToTrash();
      } // for
    } // if
  } // for
} // function

这篇关于主题相同的gmail邮件-删除所有(最新消息除外)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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