<commit_before>'use strict';

module.exports = function (options) {
  if (!options.transform) {
    options.transform = function () {};
  }

  return {
    name: 'nodemailer',
    send: function (model, done) {
      var message = {
        from: model.from,
        to: model.to.join(', '),
        subject: model.subject,
        html: model.html,
        generateTextFromHTML: true
      };
      var transformed = options.transform(message);
      options.transport.sendMail(transformed || message, done);
    }
  };
};<commit_msg>Add the support of inline images for nodemailer<commit_after>'use strict';
var util = require('util');

module.exports = function (options) {
  if (!options.transform) {
    options.transform = function () {};
  }

  /**
   * Map the image from campaing to the node mailer attachment structure
   * @param campaignImages
   * @returns {Array}
   */
  function mapImageData(campaignImages) {

    var mappedImages = [];

    campaignImages.forEach(function (campaignImage) {

      mappedImages.push({
        filename: campaignImage.name,
        content: campaignImage.data,
        contentType: campaignImage.mime,
        encoding: 'base64',
        cid: campaignImage.name
      });
    });

    return mappedImages;
  }

  return {
    name: 'nodemailer',
    send: function (model, done) {
      var images = model.images ? model.images : [];
      
      //add header image if set 
      if (model._header) {
        images.unshift({
          name: '_header',
          data: model._header.data,
          mime: model._header.mime
        });
      }
      
      var message = {
        from: model.from,
        to: model.to.join(', '),
        subject: model.subject,
        html: model.html,
        generateTextFromHTML: true,
        attachments: mapImageData(images)
      };
      var transformed = options.transform(message);
      options.transport.sendMail(transformed || message, done);
    }
  };
};
{'fraction_non_alphanumeric': 0.12372188139059305, 'fraction_numerical': 0.0010224948875255625, 'mean_word_length': 2.311336717428088, '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': '7409641', 'n_tokens_mistral': 566, 'n_tokens_neox': 550, 'n_words': 132}