Initial commit

This commit is contained in:
Andrew Davidson 2016-05-30 12:44:38 -04:00
commit 2b85f56c00
2 changed files with 56 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
Spam-Archive

55
spam-summary.js Executable file
View file

@ -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});