<commit_before>var nodemailer = require('nodemailer'),
    dataurl = require('dataurl');


exports.start = function (config_manager) {
    var transport;

    function updateConfig(appcfg) {
        var cfg = {
            host: appcfg.email_host,
            port: appcfg.email_port,
            auth: {
                user: appcfg.email_user,
                pass: appcfg.email_pass
            },
            secureConnection: appcfg.email_secure,
            service: appcfg.email_service
        };
        if (transport) {
            // retire old connection pool
            var _transport = transport;
            _transport.close();
        }
        // create new connection pool with updated config
        transport = nodemailer.createTransport("SMTP", cfg);
    }

    // set up initial config
    updateConfig(config_manager.getAppConfig());

    return {
        updateConfig: updateConfig,
        sendEmail: function (opt, callback) {
            try {
                // clone opt object as sendMail will extend it with
                // non JSON-serializable 'transport' property
                var email = JSON.parse(JSON.stringify(opt));
            }
            catch (e) {
                return callback(e);
            }
            if (email.attachments) {
                email.attachments = email.attachments.map(function (att) {
                    // strip filePath properties from attachments
                    delete att.filePath;
                    // parse dataURI properties
                    if (att.dataURI) {
                        var parsed = dataurl.parse(att.dataURI);
                        att.contents = parsed.data;
                        att.contentType = parsed.mimetype;
                        delete att.dataURI;
                    }
                    return att;
                });
            }
            return transport.sendMail(email, callback);
        },
        stop: function (callback) {
            return transport.close(callback);
        }
    };
};<commit_msg>add .message property to nodemailer errors<commit_after>var nodemailer = require('nodemailer'),
    dataurl = require('dataurl');


exports.start = function (config_manager) {
    var transport;

    function updateConfig(appcfg) {
        var cfg = {
            host: appcfg.email_host,
            port: appcfg.email_port,
            auth: {
                user: appcfg.email_user,
                pass: appcfg.email_pass
            },
            secureConnection: appcfg.email_secure,
            service: appcfg.email_service
        };
        if (transport) {
            // retire old connection pool
            var _transport = transport;
            _transport.close();
        }
        // create new connection pool with updated config
        transport = nodemailer.createTransport("SMTP", cfg);
    }

    // set up initial config
    updateConfig(config_manager.getAppConfig());

    return {
        updateConfig: updateConfig,
        sendEmail: function (opt, callback) {
            try {
                // clone opt object as sendMail will extend it with
                // non JSON-serializable 'transport' property
                var email = JSON.parse(JSON.stringify(opt));
            }
            catch (e) {
                return callback(e);
            }
            if (email.attachments) {
                email.attachments = email.attachments.map(function (att) {
                    // strip filePath properties from attachments
                    delete att.filePath;
                    // parse dataURI properties
                    if (att.dataURI) {
                        var parsed = dataurl.parse(att.dataURI);
                        att.contents = parsed.data;
                        att.contentType = parsed.mimetype;
                        delete att.dataURI;
                    }
                    return att;
                });
            }
            return transport.sendMail(email, function (err) {
                if (err) {
                    // nodemailer errors are missing .message property
                    err.message = 'Could not deliver email: ' + err.data;
                }
                callback(err);
            });
        },
        stop: function (callback) {
            return transport.close(callback);
        }
    };
};
{'fraction_non_alphanumeric': 0.08551123337918386, 'fraction_numerical': 0.0, 'mean_word_length': 1.3158174097664543, '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': '617627', 'n_tokens_mistral': 1056, 'n_tokens_neox': 1004, 'n_words': 253}