Skip to content

Instantly share code, notes, and snippets.

@lewayotte
Last active November 9, 2023 19:04
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 lewayotte/a33304f5f55a6dca2ce40b85aa1a6dae to your computer and use it in GitHub Desktop.
Save lewayotte/a33304f5f55a6dca2ce40b85aa1a6dae to your computer and use it in GitHub Desktop.
Automatically delete fake phishing emails from IT
function filter_emails() {
/// 1day is the smallest increment
var threads = GmailApp.search("newer_than:1d in:inbox");
for (var i = 0; i < threads.length; i++) {
// get all messages in a given thread
var messages = threads[i].getMessages();
for (var j = 0; j < messages.length; j++) {
var body = messages[j].getRawContent();
// Possible headers to filter
// X-PHISH: This is a security awareness phishing simulation test from InfoSec Institute that has been authorized by the recipient organization
// X-Report-Abuse-To: abuse-siq@infosecinstitute.com
if (body.indexOf("X-PHISH-CRID") > -1) {
message[j].markRead();
message[j].moveToTrash();
}
}
}
}
/*
* Go to script.google.com
* Add new project
* Add the above code
* Click save icon
* Go to Triggers
* Add new trigger
* Everything is gravy
* /
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment