gmail messages with same subject - delete all but most recent

淺唱寂寞╮ 提交于 2019-12-12 01:49:35

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/28635974/gmail-messages-with-same-subject-delete-all-but-most-recent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!