function noMitnick() { try { // Get the most recent 50 threads in your inbox var threads = GmailApp.search("in:inbox", 0, 50); // If there are threads if (threads.length > 0) { // For each thread for (var t=threads.length-1; t>=0; t--) { // Get the current thread we are iterating over var thread = threads[t]; // Get the first message in the thread var message = thread.getMessages()[0]; // Get the from address var from = message.getFrom(); // See if the raw content has the header `X-PHISHTEST` if ((message.getHeader("X-PHISHTEST") != '') || (message.getHeader("X-MarketoID") != '') || (message.getHeader("X-Mailgun-Dkim") != '')) { // Log that the filter was created Logger.log("Filter phishing " + message.getDate() + "::" + message.getSubject() + " :: " + from); // Mark the thread as trash it thread.moveToTrash(); } } } } catch (e) { Logger.log(e.toString()); } }