问题
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