Skip to content

Instantly share code, notes, and snippets.

@Daviey
Last active September 22, 2016 21:49
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 Daviey/eb61c284b6d3bf6562763db2cb8a7351 to your computer and use it in GitHub Desktop.
Save Daviey/eb61c284b6d3bf6562763db2cb8a7351 to your computer and use it in GitHub Desktop.
function main() {
// Get or create label
var label = GmailApp.getUserLabelByName("OSSP");
if (label == null) {
var label = GmailApp.createLabel("OSSP");
}
// lets go!
processInbox(label)
}
function processInbox(label) {
var threads = GmailApp.search("to:openstack-dev@lists.openstack.org newer_than:4h");
for (var i = 0; i < threads.length; i++) {
var messages = threads[i].getMessages();
for (var j = 0; j < messages.length; j++) {
var message = messages[j];
processMessage(message, label);
}
}
}
function processMessage(message, label) {
var body = message.getRawContent();
var searchtopic = "X-Topics.*(Security).*"
if (body.search(searchtopic) != -1) {
message.getThread().addLabel(label)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment