commit 2b85f56c009326a5e4c43ff0dda309ea8baaf9b0 Author: Andrew Davidson Date: Mon May 30 12:44:38 2016 -0400 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f044ecb --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +Spam-Archive diff --git a/spam-summary.js b/spam-summary.js new file mode 100755 index 0000000..7a3d188 --- /dev/null +++ b/spam-summary.js @@ -0,0 +1,55 @@ +#!/usr/bin/env node + +// Script to present a summary of the $number of least likely spam messages +// from the recent spam folder. A good check on the more aggressive +// spamassassin configurations + +// Notes: +// Totally blocks the event loop for simplicity, would need to be refactored +// if it were to be used on massive spam receivers or servers with many users. +// Currently designed for periodic use on small personal mail servers. + +// Dependencies +var fs = require('fs'); +var execSync = require('child_process').execSync; + +// Constant definition +var spamFolder = "./Spam-Archive/cur/"; +var sendTo = "amdavidson"; + +// Variable definition +var emails = new Array(); +var summary = ""; + + +// Read all emails in specified directory, parse for +// date, from, return-path, subject, and spam score. +filenames = fs.readdirSync(spamFolder) +filenames.forEach(function(filename) { + data = fs.readFileSync(spamFolder + filename); + email = {}; + email.fileName = filename; + email.from = /From: (.+)/.exec(data)[1]; + email.returnPath = /Return-Path: (.+)/.exec(data)[1]; + email.subject = /Subject: (.+)/.exec(data)[1]; + email.date = /Date: (.*)/.exec(data)[1]; + email.score = /score=([\-\+]?[0-9]*(\.[0-9]+)?)/.exec( + /X-Spam-Status: (.+)/.exec(data)[1])[1]; + emails.push(email); +}); + +// Sort by spam socre +emails.sort(function (a, b) { + return parseFloat(a.score) - parseFloat(b.score) +}); + +// Construct a summary +for (var i=0; i < 25; i++) { + summary += i + ": " + emails[i].date + "\n\t" + emails[i].from + "\n\t" + + emails[i].subject + "\n\tScore: " + emails[i].score + "\n\n"; +} +summary += "\n\n"; + +// Send summary via email +var child = execSync("mail -s \"Spam Summary " + new Date().toISOString() + + "\" " + sendTo, {input: summary});