Last active
January 27, 2023 16:53
-
-
Save leezer3/61581d226362d7194eb249b527e4376f to your computer and use it in GitHub Desktop.
SpamFilter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function spamFilter() { | |
var threads = GmailApp.search("newer_than:1h in:inbox"); | |
for (var i = 0; i < threads.length; i++) { | |
var newsRegex = ('[!-~]{5,20}\@news\.[A-Za-z0-9]{5,20}\.edu'); | |
var confirmationRegex = ('c[0,o,O]{0,4}nf[i,I]{0,2}rmat[i,I]{0,2}[0,o,O]{0,4}n'); | |
var securityRegex = ('[S,s]ecur[i,I]{0,2}ty'); | |
const newsFound = threads[i].getMessages()[0].getFrom().match(newsRegex); | |
const confirmationFound = threads[i].getFirstMessageSubject().match(confirmationRegex); | |
const securityFound = threads[i].getFirstMessageSubject().match(securityRegex); | |
if(newsFound) | |
{ | |
Logger.log("Found news in sender from edu domain- SPAM!"); | |
} | |
if(confirmationFound) | |
{ | |
Logger.log("Confirmation regex match- SPAM!") | |
} | |
if(securityFound) | |
{ | |
Logger.log("Security regex match- SPAM!") | |
} | |
if ((threads[i].getMessages()[0].getCc() == "<[leezer3@gmail.com](mailto:leezer3@gmail.com)>" || threads[i].getFirstMessageSubject().search("W0N-") != -1 || threads[i].getFirstMessageSubject().search("Y0U") != -1 || threads[i].getFirstMessageSubject().search("notification#") != -1 || threads[i].getFirstMessageSubject().search("HomeWarranty#") != -1 || securityFound || newsFound || confirmationFound) | |
&& threads[i].getMessageCount() == 1){ | |
var content = threads[i].getMessages()[0].getRawContent().split("\r\n"); | |
const regex = /d=[Nn][Ee][Tt][Oo][Rr][Gg][A-Za-z0-9]{3,15}\.onmicrosoft\.com/; | |
var foundSigned = false | |
for (var k=0;k<content.length && !foundSigned;k++) | |
{ | |
const found = content[k].match(regex); | |
if (found){ | |
Logger.log(threads[i].getFirstMessageSubject()) | |
var message = Utilities.newBlob(threads[i].getMessages()[0].getRawContent(), "message/rfc822", "Subject"); | |
//GmailApp.sendEmail("[stop-spoofing@amazon.com](mailto:stop-spoofing@amazon.com)", "Spoofing email", "See link to AWS URL in the attachment", { | |
//attachments: [message] | |
//}); | |
GmailApp.sendEmail("abuse@hotmail.com", "Spoofing email", "See phishing spam originated from onmicrosoft.com in the attachment", { | |
attachments: [message] | |
}); | |
threads[i].moveToSpam() | |
foundSigned = true | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment