5 var crypto = require('crypto');
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(';'));
23 type: DataTypes.STRING,
25 return this.getDataValue('to') ? this.getDataValue('to').split(';') : [];
28 this.setDataValue('to', val.join(';'));
32 type: DataTypes.STRING,
34 return this.getDataValue('cc') ? this.getDataValue('cc').split(';') : [];
37 this.setDataValue('cc', val.join(';'));
41 type: DataTypes.STRING,
43 return this.getDataValue('bcc') ? this.getDataValue('bcc').split(';') : [];
46 this.setDataValue('bcc', val.join(';'));
49 attachment: DataTypes.TEXT,
53 if (this.getDataValue('text')) {
54 return this.getDataValue('text').toString();
61 if (this.getDataValue('html')) {
62 return this.getDataValue('html').toString();
66 reason: DataTypes.TEXT,
68 type: DataTypes.ENUM('SENT', 'SENDING', 'RECEIVED', 'FAILED', 'NOTE'),
69 defaultValue: 'SENDING'
72 tableName: 'mail_messages',
74 associate: function(models) {
75 MailMessage.hasMany(models.MailAttachment);
76 MailMessage.belongsTo(models.User);
77 MailMessage.belongsTo(models.MailRoom, {