5 var _ = require('lodash');
7 module.exports = function(sequelize, DataTypes) {
9 var MailMessage = sequelize.define('MailMessage', {
10 messageId: DataTypes.STRING,
11 inReplyTo: DataTypes.STRING,
12 subject: DataTypes.STRING,
14 type: DataTypes.STRING,
16 return this.getDataValue('from') ? this.getDataValue('from').split(';') : [];
19 this.setDataValue('from', val.join(';'));
25 return this.getDataValue('to') ? this.getDataValue('to').split(';') : [];
28 this.setDataValue('to', val.join(';'));
34 return this.getDataValue('cc') ? this.getDataValue('cc').split(';') : [];
37 this.setDataValue('cc', val.join(';'));
43 return this.getDataValue('bcc') ? this.getDataValue('bcc').split(';') : [];
46 this.setDataValue('bcc', val.join(';'));
50 type: DataTypes.INTEGER
52 attachment: DataTypes.TEXT,
56 if (this.getDataValue('text')) {
57 return _.toString(this.getDataValue('text'));
64 if (this.getDataValue('html')) {
65 if (this.getDataValue('html')) {
66 return _.toString(this.getDataValue('html'));
71 reason: DataTypes.TEXT,
73 type: DataTypes.ENUM('SENT', 'SENDING', 'RECEIVED', 'FAILED', 'NOTE'),
74 defaultValue: 'SENDING'
77 tableName: 'mail_messages',
79 associate: function(models) {
80 MailMessage.hasMany(models.MailAttachment);
81 MailMessage.belongsTo(models.User);
82 MailMessage.belongsTo(models.MailRoom, {