Advertisement
dachte

NoMitnick

Feb 17th, 2023 (edited)
1,073
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function noMitnick() {
  2.     try {
  3.  
  4.     // Get the most recent 50 threads in your inbox
  5.     var threads = GmailApp.search("in:inbox", 0, 50);
  6.  
  7.     // If there are threads
  8.     if (threads.length > 0) {
  9.  
  10.       // For each thread
  11.       for (var t=threads.length-1; t>=0; t--) {
  12.  
  13.         // Get the current thread we are iterating over
  14.         var thread = threads[t];
  15.        
  16.         // Get the first message in the thread
  17.         var message = thread.getMessages()[0];
  18.        
  19.         // Get the from address
  20.         var from = message.getFrom();
  21.            
  22.         // See if the raw content has the header `X-PHISHTEST`
  23.         if ((message.getHeader("X-PHISHTEST") != '') || (message.getHeader("X-MarketoID") != '') || (message.getHeader("X-Mailgun-Dkim") != '')) {
  24.  
  25.           // Log that the filter was created
  26.           Logger.log("Filter phishing " + message.getDate() + "::" + message.getSubject() + " :: " + from);
  27.          
  28.           // Mark the thread as trash it
  29.           thread.moveToTrash();
  30.         }
  31.       }
  32.     }
  33.   } catch (e) {
  34.     Logger.log(e.toString());
  35.   }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement