<commit_before>'use strict';
// =========================================================================
//
// part of the set of controllers for the messaging system
//
// these ones deal with the messages tables and their interactions
//
// =========================================================================
var mongoose        = require ('mongoose');
var User            = mongoose.model ('User');
var Message         = mongoose.model ('Message');
var MessageTemplate = mongoose.model ('MessageTemplate');
var MessageArchive  = mongoose.model ('MessageArchive');
var path            = require ('path');
var errorHandler    = require (path.resolve ('./modules/core/server/controllers/errors.server.controller'));
var handlebars      = require ('handlebars');
var htmlToText      = require ('html-to-text');
var config          = require (path.resolve ('./config/config'));
var nodemailer      = require('nodemailer');
var smtpTransport   = nodemailer.createTransport (config.mailer.options);
var chalk           = require('chalk');
var helpers         = require(path.resolve('./modules/core/server/controllers/core.server.helpers'));
var _               = require ('lodash');

// =========================================================================
//
// Common Functions
//
// =========================================================================
// -------------------------------------------------------------------------
//
// perform a query on the messages table
// HIDE THE LINKS - they hsould never get to the front end as they pose a
// security risk
//
// -------------------------------------------------------------------------
var query = function (table, q) {
	return new Promise (function (resolve, reject) {
		table.find (q)
		.select ('-link')
		.sort ({dateSent:-1, dateExpired: 1})
		.populate ('user', 'displayName email')
		.exec (function (err, messages) {
			if (err) reject (errorHandler.getErrorMessage(err));
			else resolve (messages);
		});
	});
};
var count = function (table, q) {
	return new Promise (function (resolve, reject) {
		table.count (q, function (err, c) {
			if (err) reject (errorHandler.getErrorMessage(err));
			else resolve (c);
		});
	});
};
var appendNotificationLink = function (messagebody) {
	var link = '<a href="{{domain}}/messages">Sign in to the BCDevExchange</a>';
	var m = 'To respond to this message, '+link+' and navigate to your messages.';
	return messagebody+'<p><br/>'+m+'<br/></p>';
}
// -------------------------------------------------------------------------
//
// archive a message
//
// -------------------------------------------------------------------------<commit_msg>BA-923 - Fix link in Company Invitation email template<commit_after>'use strict';
// =========================================================================
//
// part of the set of controllers for the messaging system
//
// these ones deal with the messages tables and their interactions
//
// =========================================================================
var mongoose        = require ('mongoose');
var User            = mongoose.model ('User');
var Message         = mongoose.model ('Message');
var MessageTemplate = mongoose.model ('MessageTemplate');
var MessageArchive  = mongoose.model ('MessageArchive');
var path            = require ('path');
var errorHandler    = require (path.resolve ('./modules/core/server/controllers/errors.server.controller'));
var handlebars      = require ('handlebars');
var htmlToText      = require ('html-to-text');
var config          = require (path.resolve ('./config/config'));
var nodemailer      = require('nodemailer');
var smtpTransport   = nodemailer.createTransport (config.mailer.options);
var chalk           = require('chalk');
var helpers         = require(path.resolve('./modules/core/server/controllers/core.server.helpers'));
var _               = require ('lodash');

// =========================================================================
//
// Common Functions
//
// =========================================================================
// -------------------------------------------------------------------------
//
// perform a query on the messages table
// HIDE THE LINKS - they hsould never get to the front end as they pose a
// security risk
//
// -------------------------------------------------------------------------
var query = function (table, q) {
	return new Promise (function (resolve, reject) {
		table.find (q)
		.select ('-link')
		.sort ({dateSent:-1, dateExpired: 1})
		.populate ('user', 'displayName email')
		.exec (function (err, messages) {
			if (err) reject (errorHandler.getErrorMessage(err));
			else resolve (messages);
		});
	});
};
var count = function (table, q) {
	return new Promise (function (resolve, reject) {
		table.count (q, function (err, c) {
			if (err) reject (errorHandler.getErrorMessage(err));
			else resolve (c);
		});
	});
};
var appendNotificationLink = function (messagebody) {
	var link = '<a href="{{domain}}/settings/messages">Sign in to the BCDevExchange</a>';
	var m = 'To respond to this message, '+link+' and navigate to your messages.';
	return messagebody+'<p><br/>'+m+'<br/></p>';
}
// -------------------------------------------------------------------------
//
// archive a message
//
// -------------------------------------------------------------------------
{'fraction_non_alphanumeric': 0.3400967982129561, 'fraction_numerical': 0.0013030528667163069, 'mean_word_length': 2.4049429657794676, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '6741118', 'n_tokens_mistral': 1326, 'n_tokens_neox': 1260, 'n_words': 393}