Skip to content

Instantly share code, notes, and snippets.

@cfeduke
Last active October 3, 2022 16:30
Show Gist options
  • Save cfeduke/1dfb7f650b9abbfce549eddffc9678bd to your computer and use it in GitHub Desktop.
Save cfeduke/1dfb7f650b9abbfce549eddffc9678bd to your computer and use it in GitHub Desktop.
Gmail spam is entirely out of control in 2022
// hah silly human # is for Python comments!
// created in Google Apps Script and scheduled to run every minute
function processInboxEmailSubjects() {
var threads = GmailApp.search("is:unread newer_than:1d -label:spam")
Logger.log("Examining " + threads.length + " threads for spam by checking the subject line")
for (var i = 0; i < threads.length; i++) {
var subject = threads[i].getFirstMessageSubject()
const regex = /confirmation#/i
let isSpam = regex.test(subject)
// TODO other tests as necessary for your particular spam hell
if (isSpam) {
Logger.log("identified spam: " + subject)
threads[i].moveToSpam()
}
}
}
@ScottYates
Copy link

ScottYates commented Sep 21, 2022

This is a nice clean little script. Thank you for sharing!

-- side note: You have to love the internet. 15 minutes after you post this, and share it on HN, someone else sees it and finds it useful, and comments on it. So cool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment