Skip to content

Instantly share code, notes, and snippets.

@fuglu
Last active November 12, 2019 10:56
Show Gist options
  • Save fuglu/c1d88719621da926a20681543cdf679b to your computer and use it in GitHub Desktop.
Save fuglu/c1d88719621da926a20681543cdf679b to your computer and use it in GitHub Desktop.
Google Spam Filter
function spamFilter() {
var threads = GmailApp.search('is:unread in:inbox');
for (var i = 0; i < threads.length; i++) {
var thread = threads[i];
if (!thread.isUnread()) {
continue;
}
var messages = thread.getMessages();
var isSpam = false;
for (var b = 0; b < messages.length; b++) {
var message = messages[b];
if (message.getBody().match(/ub.php/)) {
Logger.log("[SPAM]" + message.getSubject());
isSpam = true;
break;
}
}
if (isSpam) {
thread.moveToSpam();
continue;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment