Skip to content

Instantly share code, notes, and snippets.

@smfreegard
Created December 2, 2012 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save smfreegard/4191321 to your computer and use it in GitHub Desktop.
Save smfreegard/4191321 to your computer and use it in GitHub Desktop.
mongo.js
var Stream = require('stream').Stream;
exports.hook_queue = function (next, connection) {
// MongoDB configuration settings.
var databaseUrl = "localhost";
var collections = ["email"];
var db = require("mongojs").connect(databaseUrl, collections);
// basic logging so we can see if we have an email hitting the stack
this.loginfo("New inbound email detected, inserting into mongodb");
// setup of variable to save us typing the same string over and over.
var transaction = connection.transaction;
var receivedDate = transaction.header.headers.date;
var subjectLine = transaction.header.headers.subject;
var data_lines = "";
var s = new Stream;
s.writable = true;
s.write = functiom (chunk) {
data_lines += chunk;
}
s.end = function () {
// persist the data within mongo. TODO still needs to add in user ID from MySQL so its stored in there mailbox.
db.email.save({
email: transaction.mail_from,
message: data_lines,
received: receivedDate,
subjectLine: subjectLine
});
// passes control over to the next plugin within Haraka.
return next(OK);
}
transaction.message_stream.pipe(s);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment