Skip to content

Instantly share code, notes, and snippets.

@nickpreston24
Created November 18, 2023 03:44
Show Gist options
  • Select an option

  • Save nickpreston24/c0602ea53375d6c5ef40dbb297203957 to your computer and use it in GitHub Desktop.

Select an option

Save nickpreston24/c0602ea53375d6c5ef40dbb297203957 to your computer and use it in GitHub Desktop.
Filters out 'via' spammers in Gmail
let debug_mode = true;
// Filters out emails sent on behalf of some other server they might be impersonating
// E.g. mg3.ceipalmm.com
// TODO: put your own mail domains in this array. Mine are samples.
var my_blacklisted_domains = [
"X-Feedback-Id: [email protected]"
,"X-Feedback-Id: [email protected]"];
function filterViaSpam() {
var threads = GmailApp.getInboxThreads(0, 50);
for (var i = 0; i < threads.length; i++) {
var messages=threads[i].getMessages();
debug_mode && console.log('message count: ', messages.length)
for (var j = 0; j < messages.length; j++) {
var message=messages[j];
var body=message.getRawContent();
var subject = message.getSubject();
debug_mode && console.log('subject:', subject)
for(var k = 0; k < my_blacklisted_domains.length; k++){
var domain = my_blacklisted_domains[k];
debug_mode && console.log('checking for domain with name: ', domain)
if(body.indexOf(domain)>-1){
console.log('message:', message)
debug_mode && console.log('body:', body)
GmailApp.moveThreadToSpam(threads[i]);
}
}
Utilities.sleep(1000);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment