Skip to content

Instantly share code, notes, and snippets.

@mde
Created December 15, 2015 07:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mde/35cf484c78245a39cab5 to your computer and use it in GitHub Desktop.
Save mde/35cf484c78245a39cab5 to your computer and use it in GitHub Desktop.
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