<commit_before>

var RuleTypes = {
  INSTANT: 'INSTANT',
  TRIGGER: 'TRIGGER'
};


/**
 * Sends an email based upon an EmailRule. Tags are swapped out.
 * Handles to, subject and body fields.
 *
 * @param {String[]} headerRow An array of header values.
 * @param {String[]} row An array of row values.
 * @param {Object} rule The rule used to send the email. See the client-side object EmailRule for info.
 * @return {Boolean} true if the email was sent, false otherwise.
 */
function sendBasicEmail(headerRow, row, rule) {
  var combinedObj = {};
  for (var j = 0; j < headerRow.length; j++) {
    combinedObj[headerRow[j]] = row[j];
  }

  // Convert <<>> tags to actual text.
  var to = replaceTags(rule.to, combinedObj);
  var subject = replaceTags(rule.subject, combinedObj);
  var body = replaceTags(rule.body, combinedObj);

  var template = HtmlService.createTemplateFromFile('email-template');
  template.id = getSpreadsheet().getId();
  template.bodyArray = body.split('\n');

  log('Sending email to ' + to);

  MailApp.sendEmail({
    to: to,
    subject: subject,
    htmlBody: template.evaluate().getContent()
  });

  return true;
}


/**
 * Sends an email based upon an EmailRule. Tags are swapped out.
 * Handles to, subject, body, sendColumn and timestampColumn fields.
 * This is used for TRIGGER type rules.
 *
 * @param {String[]} headerRow An array of header values.
 * @param {String[]} row An array of row values.
 * @param {Object} rule The rule used to send the email. See the client-side object EmailRule for info.
 * @return {Boolean} true if the email was sent, false otherwise.
 */
function sendConditionalEmail(headerRow, row, rule) {
  var combinedObj = {};
  for (var j = 0; j < headerRow.length; j++) {
    combinedObj[headerRow[j]] = row[j];
  }

  // Convert <<>> tags to actual text.
  var to = replaceTags(rule.to, combinedObj);
  var subject = replaceTags(rule.subject, combinedObj);
  var body = replaceTags(rule.body, combinedObj);
  var sendColumn = replaceTags(rule.sendColumn, combinedObj);

  if (sendColumn.toLowerCase() === 'true') {
    var template = HtmlService.createTemplateFromFile('email-template');
    template.id = getSpreadsheet().getId();
    template.bodyArray = body.split('\n');

    log('Sending email to ' + to);
    MailApp.sendEmail({
      to: to,
      subject: subject,
      htmlBody: template.evaluate().getContent()
    });

    return true;
  }

  return false;
}


/**
 * Handles all trigger rules. For each rule, all rows will be iterated through.
 *
 */
function sendManyEmails() {
  try {
    log('Starting rules...');
    var rules = getAllRules();

    // Validate each rule for each row
    var ss = getSpreadsheet();
<commit_msg>Resolved the issue with sent emails showing up in the inbox. Closes #97.<commit_after>

var RuleTypes = {
  INSTANT: 'INSTANT',
  TRIGGER: 'TRIGGER'
};


/**
 * Sends an email based upon an EmailRule. Tags are swapped out.
 * Handles to, subject and body fields.
 *
 * @param {String[]} headerRow An array of header values.
 * @param {String[]} row An array of row values.
 * @param {Object} rule The rule used to send the email. See the client-side object EmailRule for info.
 * @return {Boolean} true if the email was sent, false otherwise.
 */
function sendBasicEmail(headerRow, row, rule) {
  var combinedObj = {};
  for (var j = 0; j < headerRow.length; j++) {
    combinedObj[headerRow[j]] = row[j];
  }

  // Convert <<>> tags to actual text.
  var to = replaceTags(rule.to, combinedObj);
  var subject = replaceTags(rule.subject, combinedObj);
  var body = replaceTags(rule.body, combinedObj);

  var template = HtmlService.createTemplateFromFile('email-template');
  template.id = getSpreadsheet().getId();
  template.bodyArray = body.split('\n');

  log('Sending email to ' + to);
  GmailApp.sendEmail(to, subject, body, {
    htmlBody: template.evaluate().getContent()
  });

  return true;
}


/**
 * Sends an email based upon an EmailRule. Tags are swapped out.
 * Handles to, subject, body, sendColumn and timestampColumn fields.
 * This is used for TRIGGER type rules.
 *
 * @param {String[]} headerRow An array of header values.
 * @param {String[]} row An array of row values.
 * @param {Object} rule The rule used to send the email. See the client-side object EmailRule for info.
 * @return {Boolean} true if the email was sent, false otherwise.
 */
function sendConditionalEmail(headerRow, row, rule) {
  var combinedObj = {};
  for (var j = 0; j < headerRow.length; j++) {
    combinedObj[headerRow[j]] = row[j];
  }

  // Convert <<>> tags to actual text.
  var to = replaceTags(rule.to, combinedObj);
  var subject = replaceTags(rule.subject, combinedObj);
  var body = replaceTags(rule.body, combinedObj);
  var sendColumn = replaceTags(rule.sendColumn, combinedObj);

  if (sendColumn.toLowerCase() === 'true') {
    var template = HtmlService.createTemplateFromFile('email-template');
    template.id = getSpreadsheet().getId();
    template.bodyArray = body.split('\n');

    log('Sending email to ' + to);
    GmailApp.sendEmail(to, subject, body, {
      htmlBody: template.evaluate().getContent()
    });

    return true;
  }

  return false;
}


/**
 * Handles all trigger rules. For each rule, all rows will be iterated through.
 *
 */
function sendManyEmails() {
  try {
    log('Starting rules...');
    var rules = getAllRules();

    // Validate each rule for each row
    var ss = getSpreadsheet();

{'fraction_non_alphanumeric': 0.12982005141388175, 'fraction_numerical': 0.0011017260374586854, 'mean_word_length': 3.585016835016835, 'pattern_counts': {'":': 0, '<': 15, '<?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': '6296400', 'n_tokens_mistral': 1688, 'n_tokens_neox': 1664, 'n_words': 566}