Created
December 15, 2015 07:58
-
-
Save mde/35cf484c78245a39cab5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function filterGhNotifications() { | |
var sourceLabel = GmailApp.getUserLabelByName('GH'); | |
var addedLabel = GmailApp.getUserLabelByName('GH -- mde'); | |
var pat = /@mde/; | |
var threads; | |
var foundThreads = []; | |
threads = sourceLabel.getThreads(0, 20); | |
threads.forEach(function (thread) { | |
var messages = thread.getMessages(); | |
var subject; | |
var found = messages.some(function (message) { | |
subject = message.getSubject(); | |
return pat.test(message.getBody()); | |
}); | |
if (found) { | |
foundThreads.push({ | |
obj: thread, | |
subj: subject | |
}); | |
} | |
}); | |
Logger.log('Found ' + foundThreads.length + ' matching threads'); | |
Logger.log('Adding to ' + addedLabel.getName()); | |
foundThreads.forEach(function (thread) { | |
addedLabel.addToThread(thread.obj); | |
Logger.log('Added ' + thread.subj); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment