Created
December 2, 2012 22:20
-
-
Save smfreegard/4191321 to your computer and use it in GitHub Desktop.
mongo.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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