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,
54 type: DataTypes.BLOB('long'),
56 if (this.getDataValue('text')) {
57 return _.toString(this.getDataValue('text'));
62 type: DataTypes.BLOB('long'),
64 if (this.getDataValue('html')) {
65 if (this.getDataValue('html')) {
66 return _.toString(this.getDataValue('html'));
71 reason: DataTypes.TEXT,
73 type: DataTypes.BOOLEAN,
77 type: DataTypes.ENUM('SENDING', 'SENT', 'RECEIVED', 'FAILED', 'NOTE'),
78 defaultValue: 'SENDING'
81 type: DataTypes.INTEGER,
84 voiceSource: DataTypes.STRING,
85 userName: DataTypes.STRING,
86 userFullname: DataTypes.STRING,
87 accountId: DataTypes.INTEGER,
88 accountName: DataTypes.STRING
90 tableName: 'mail_messages',
92 associate: function(models) {
93 MailMessage.hasMany(models.MailAttachment);
94 MailMessage.belongsTo(models.User);
95 MailMessage.belongsTo(models.MailRoom, {