<commit_before>'use strict';

const Mailgun = require('mailgun-js');
const checkWhitelist = require('../check-whitelist');
const logger = require('../../../lib/logger');

module.exports = function () {

  const mailgunClient = Mailgun({
    apiKey: process.env.MAILGUN_API_KEY,
    domain: process.env.OIDC_EMAIL_DOMAIN,
  });

  return {
    send : (emailObject) => {

      return new Promise((resolve, reject) => {

        if (!emailObject.to) {
          return reject('no to address provided');
        }

        if (!emailObject.subject) {
          return reject('no subject provided');
        }

        if (!emailObject.text && !emailObject.html) {
          return reject('no text or html body provided');
        }

        const mail = {
          from: emailObject.from || 'no-reply@' + process.env.OIDC_EMAIL_DOMAIN,
          to: checkWhitelist(emailObject.to, reject),
          subject: emailObject.subject,
          text: emailObject.text || '',
          html: emailObject.html || ''
        };

        if (emailObject.attachments) {
          if (!Array.isArray(emailObject.attachments)) {
            return reject('attachments must be an array');
          }

          const attachments = [];
          emailObject.attachments.forEach((attachment) => {

            if (typeof attachment.data === 'string') {
              attachment.data = new Buffer(attachment.data);
            }

            attachments.push(new mailgunClient.Attachment({
              contentType: attachment.contentType,
              filename: attachment.filename,
              data: attachment.data
            }));
            mail.attachment = attachments[0];
          });
        }

        mailgunClient.messages().send(mail, (error, body) => {
          if (error) {
            logger.info(error, mail);
            reject(error);
          }
          else {
            resolve(body);
          }
        });
      });
    }
  };
};<commit_msg>Change mailgun to use logger.error instead of info<commit_after>'use strict';

const Mailgun = require('mailgun-js');
const checkWhitelist = require('../check-whitelist');
const logger = require('../../../lib/logger');

module.exports = function () {

  const mailgunClient = Mailgun({
    apiKey: process.env.MAILGUN_API_KEY,
    domain: process.env.OIDC_EMAIL_DOMAIN,
  });

  return {
    send : (emailObject) => {

      return new Promise((resolve, reject) => {

        if (!emailObject.to) {
          return reject('no to address provided');
        }

        if (!emailObject.subject) {
          return reject('no subject provided');
        }

        if (!emailObject.text && !emailObject.html) {
          return reject('no text or html body provided');
        }

        const mail = {
          from: emailObject.from || 'no-reply@' + process.env.OIDC_EMAIL_DOMAIN,
          to: checkWhitelist(emailObject.to, reject),
          subject: emailObject.subject,
          text: emailObject.text || '',
          html: emailObject.html || ''
        };

        if (emailObject.attachments) {
          if (!Array.isArray(emailObject.attachments)) {
            return reject('attachments must be an array');
          }

          const attachments = [];
          emailObject.attachments.forEach((attachment) => {

            if (typeof attachment.data === 'string') {
              attachment.data = new Buffer(attachment.data);
            }

            attachments.push(new mailgunClient.Attachment({
              contentType: attachment.contentType,
              filename: attachment.filename,
              data: attachment.data
            }));
            mail.attachment = attachments[0];
          });
        }

        mailgunClient.messages().send(mail, (error, body) => {
          if (error) {
            logger.error(error, mail);
            reject(error);
          }
          else {
            resolve(body);
          }
        });
      });
    }
  };
};
{'fraction_non_alphanumeric': 0.13119312436804853, 'fraction_numerical': 0.0005055611729019212, 'mean_word_length': 1.8529199711607787, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '4032339', 'n_tokens_mistral': 1069, 'n_tokens_neox': 1040, 'n_words': 217}