<commit_before>'use strict'

const Hp = require('hemera-plugin')
const Nodemailer = require('nodemailer')

exports.plugin = Hp(function hemeraMsgpack (options) {
  const hemera = this
  const topic = 'mail'
  const Joi = hemera.exposition['hemera-joi'].joi
  const transporter = Nodemailer.createTransport(options.transport)

  hemera.add({
    topic,
    cmd: 'send',
    message: Joi.object().keys({
      from: Joi.string().required(),
      to: Joi.string().required(),
      subject: Joi.string().required(),
      text: Joi.string().optional(),
      html: Joi.string().optional(),
      bcc: Joi.string().optional(),
      cc: Joi.string().optional()
    }).required()
  }, function (req, reply) {
    transporter.sendMail(req.message, (err, info) => {
      if (err) {
        this.log.eror(err, 'Could not send email!')
        return reply()
      }

      this.log.debug('Message %s sent %s', info.messageId, info.response)

      reply(null, {
        envelope: info.envelope,
        messageId: info.messageId
      })
    })
  })
})

exports.options = {
  payloadValidator: 'hemera-joi',
  transport: {
    jsonTransport: true // for debugging
  }<commit_msg>fix(typo): change eror tot error<commit_after>'use strict'

const Hp = require('hemera-plugin')
const Nodemailer = require('nodemailer')

exports.plugin = Hp(function hemeraMsgpack (options) {
  const hemera = this
  const topic = 'mail'
  const Joi = hemera.exposition['hemera-joi'].joi
  const transporter = Nodemailer.createTransport(options.transport)

  hemera.add({
    topic,
    cmd: 'send',
    message: Joi.object().keys({
      from: Joi.string().required(),
      to: Joi.string().required(),
      subject: Joi.string().required(),
      text: Joi.string().optional(),
      html: Joi.string().optional(),
      bcc: Joi.string().optional(),
      cc: Joi.string().optional()
    }).required()
  }, function (req, reply) {
    transporter.sendMail(req.message, (err, info) => {
      if (err) {
        this.log.error(err, 'Could not send email!')
        return reply()
      }

      this.log.debug('Message %s sent %s', info.messageId, info.response)

      reply(null, {
        envelope: info.envelope,
        messageId: info.messageId
      })
    })
  })
})

exports.options = {
  payloadValidator: 'hemera-joi',
  transport: {
    jsonTransport: true // for debugging
  }
{'fraction_non_alphanumeric': 0.1584953508030431, 'fraction_numerical': 0.0, 'mean_word_length': 2.925373134328358, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4912670', 'n_tokens_mistral': 787, 'n_tokens_neox': 769, 'n_words': 162}