Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.