<commit_before>/**
 * Dependencies
 */

var config = require('./config');
var hogan = require('hogan.js');
var juice = require('juice');
var Mandrill = require('mandrill-api/mandrill').Mandrill;

/**
 * Templates
 */

var templates = {};

/**
 * Create `client`
 */

var client = module.exports.client = new Mandrill(process.env.MANDRILL_API_KEY);

/**
 * Expose `send`
 */

module.exports.send = send;

/**
 * Send
 */

function send(options, callback, template) {
  if (process.env.NODE_ENV === 'test') {
    return callback(null, {
      _id: '123',
      status: 'sent'
    });
  }

  if (!template) {
    if (templates[options.template]) {
      return send(options, callback, templates[options.template]);
    } else {
      return juice(__dirname + '/../email-templates/' + options.template +
        '.html', function(err, data) {
          if (err) {
            return callback(err);
          } else {
            templates[options.template] = hogan.compile(data);
            return send(options, callback, templates[options.template]);
          }
        });
    }
  }

  client.messages.send({
    message: {
      html: template.render(options),
      subject: options.subject,
      to: [options.to],
      from_email: config.email.address,
      from_name: config.email.name,
      track_opens: true,
      track_clicks: true,
      auto_text: true,
      tags: options.tags || []
    }
  }, function(result) {
    if (result[0].status === 'rejected' || result[0].status === 'invalid') {
      callback(new Error(result[0].reject_reason), result[0]);
    } else {
      callback(null, result[0]);
    }
  }, function(err) {
    callback(err);
  });
}<commit_msg>Added helper function for retrieving email info<commit_after>/**
 * Dependencies
 */

var config = require('./config');
var hogan = require('hogan.js');
var juice = require('juice');
var Mandrill = require('mandrill-api/mandrill').Mandrill;

/**
 * Templates
 */

var templates = {};

/**
 * Create `client`
 */

var client = module.exports.client = new Mandrill(process.env.MANDRILL_API_KEY);

/**
 * Expose `send` & `info`
 */

module.exports.send = send;
module.exports.info = info;

/**
 * Send
 */

function send(options, callback, template) {
  if (process.env.NODE_ENV === 'test') {
    return callback(null, {
      _id: '123',
      status: 'sent'
    });
  }

  if (!template) {
    if (templates[options.template]) {
      return send(options, callback, templates[options.template]);
    } else {
      return juice(__dirname + '/../email-templates/' + options.template +
        '.html', function(err, data) {
          if (err) {
            return callback(err);
          } else {
            templates[options.template] = hogan.compile(data);
            return send(options, callback, templates[options.template]);
          }
        });
    }
  }

  client.messages.send({
    message: {
      html: template.render(options),
      subject: options.subject,
      to: [options.to],
      from_email: config.email.address,
      from_name: config.email.name,
      track_opens: true,
      track_clicks: true,
      auto_text: true,
      tags: options.tags || []
    }
  }, function(result) {
    if (result[0].status === 'rejected' || result[0].status === 'invalid') {
      callback(new Error(result[0].reject_reason), result[0]);
    } else {
      callback(null, result[0]);
    }
  }, function(err) {
    callback(err);
  });
}

/**
 * Info
 */

function info(id, callback) {
  client.messages.info({
    id: id
  }, function(results) {
    callback(null, results);
  }, function(err) {
    callback(err);
  });
}
{'fraction_non_alphanumeric': 0.16781863422726015, 'fraction_numerical': 0.004423555432679016, 'mean_word_length': 2.625250501002004, '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': '2312767', 'n_tokens_mistral': 1155, 'n_tokens_neox': 1134, 'n_words': 227}