<commit_before>var https = require("https");

var MandrillGateway = function (mandrillKey, defaultFromEmail, defaultFromName) {
    var self = this;
    
    self.handleInboundEmail = function (req, res, messageStore) {
        var events = req.body.mandrill_events || [];
        if (typeof events === "string") {
            events = JSON.parse(events);
        }
        events.forEach(function (event) {
            var newMessage = {
                received: new Date(),
                account: event.msg.email,
                fromEmail: event.msg.from_email,
                fromName: event.msg.from_name,
                toEmail: event.msg.to,
                subject: event.msg.subject,
                text: event.msg.text,
                status: 'Pending',
                // so we can reply in context later
                _contextMessageId: event.msg.headers['Message-Id']
            };
            messageStore.saveMessage(newMessage);
        });
        return res.send(204);
    };
    
    self.replyToSender = function(message, body, senderEmail) {
        var payload = {
            key : mandrillKey,
            message: {
                text: "This is an automated response to your message to "+ message.account + "\n\n" + body,
                from_email: senderEmail || defaultFromEmail,
                from_name: defaultFromName,
                subject: (message.subject && message.subject.indexOf("Re:") === -1) ? ("Re: "+ message.subject) : message.subject,
                to: [{
                    email: message.fromEmail,     
                    name: message.fromName,
                    type: "to"
                }],
                headers: { 
                    'In-Reply-To': message._contextMessageId
                }
            }
        };
	    var options = {
	      hostname: 'mandrillapp.com',
	      path: '/api/1.0/messages/send.json',
	      method: 'POST',
              headers: { 'content-type': 'application/json' }
	    };
        console.log(options);
        console.log(payload);
        var req = https.request(options, function(res) {<commit_msg>errors are not being reported consistently to user #2 - gonna need more messages<commit_after>var https = require("https");

var MandrillGateway = function (mandrillKey, defaultFromEmail, defaultFromName) {
    var self = this;
    
    self.handleInboundEmail = function (req, res, messageStore) {
        var events = req.body.mandrill_events || [];
        if (typeof events === "string") {
            events = JSON.parse(events);
        }
        events.forEach(function (event) {
            var newMessage = {
                received: new Date(),
                account: event.msg.email,
                fromEmail: event.msg.from_email,
                fromName: event.msg.from_name,
                toEmail: event.msg.to,
                subject: event.msg.subject,
                text: event.msg.text,
                status: 'Pending',
                // so we can reply in context later
                _contextMessageId: event.msg.headers['Message-Id']
            };
            messageStore.saveMessage(newMessage);
        });
        return res.send(204);
    };
    
    self.replyToSender = function(message, body, senderEmail) {
        var payload = {
            key : mandrillKey,
            message: {
                text: "This is an automated response to your message to "+ message.account + "\n\n" + body,
                from_email: senderEmail || defaultFromEmail,
                from_name: defaultFromName,
                subject: (message.subject && message.subject.indexOf("Re:") === -1) ? ("Re: "+ message.subject) : message.subject,
                to: [{
                    email: message.fromEmail,     
                    name: message.fromName,
                    type: "to"
                }],
                headers: { 
                    'In-Reply-To': message._contextMessageId
                }
            }
        };
	    var options = {
	      hostname: 'mandrillapp.com',
	      path: '/api/1.0/messages/send.json',
	      method: 'POST',
              headers: { 'content-type': 'application/json' }
	    };
	    console.log("message: \n"+ JSON.stringify(message));
        console.log("options: \n"+ JSON.stringify(options));
        console.log("payload: \n"+ JSON.stringify(payload));
        var req = https.request(options, function(res) {
{'fraction_non_alphanumeric': 0.11711508026226543, 'fraction_numerical': 0.0029391815509834953, 'mean_word_length': 1.5932004689331771, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4696784', 'n_tokens_mistral': 1201, 'n_tokens_neox': 1131, 'n_words': 260}