Built motion from commit c56b56e.|0.0.125
[motion.git] / server / models / mail_message.js
1 /**
2  * Chat Website Model
3  */
4
5 var _ = require('lodash');
6
7 module.exports = function(sequelize, DataTypes) {
8
9         var MailMessage = sequelize.define('MailMessage', {
10                 messageId: DataTypes.STRING,
11                 inReplyTo: DataTypes.STRING,
12                 subject: DataTypes.STRING,
13                 from: {
14                         type: DataTypes.STRING,
15                         get: function() {
16                                 return this.getDataValue('from') ? this.getDataValue('from').split(';') : [];
17                         },
18                         set: function(val) {
19                                 this.setDataValue('from', val.join(';'));
20                         }
21                 },
22                 to: {
23                         type: DataTypes.TEXT,
24                         get: function() {
25                                 return this.getDataValue('to') ? this.getDataValue('to').split(';') : [];
26                         },
27                         set: function(val) {
28                                 this.setDataValue('to', val.join(';'));
29                         }
30                 },
31                 cc: {
32                         type: DataTypes.TEXT,
33                         get: function() {
34                                 return this.getDataValue('cc') ? this.getDataValue('cc').split(';') : [];
35                         },
36                         set: function(val) {
37                                 this.setDataValue('cc', val.join(';'));
38                         }
39                 },
40                 bcc: {
41                         type: DataTypes.TEXT,
42                         get: function() {
43                                 return this.getDataValue('bcc') ? this.getDataValue('bcc').split(';') : [];
44                         },
45                         set: function(val) {
46                                 this.setDataValue('bcc', val.join(';'));
47                         }
48                 },
49                 fromId: {
50                         type: DataTypes.INTEGER
51                 },
52                 attachment: DataTypes.TEXT,
53                 text: {
54                         type: DataTypes.BLOB,
55                         get: function() {
56                                 if (this.getDataValue('text')) {
57                                         return _.toString(this.getDataValue('text'));
58                                 }
59                         }
60                 },
61                 html: {
62                         type: DataTypes.BLOB,
63                         get: function() {
64                                 if (this.getDataValue('html')) {
65                                         if (this.getDataValue('html')) {
66                                                 return _.toString(this.getDataValue('html'));
67                                         }
68                                 }
69                         },
70                 },
71                 reason: DataTypes.TEXT,
72                 status: {
73                         type: DataTypes.ENUM('SENDING', 'SENT', 'RECEIVED', 'FAILED', 'NOTE'),
74                         defaultValue: 'SENDING'
75                 },
76                 retry: {
77                         type: DataTypes.INTEGER,
78                         defaultValue: 0
79                 },
80                 voiceSource: DataTypes.STRING,
81                 userName: DataTypes.STRING,
82                 userFullname: DataTypes.STRING,
83                 accountId: DataTypes.INTEGER,
84                 accountName: DataTypes.STRING
85         }, {
86                 tableName: 'mail_messages',
87                 paranoid: true,
88                 associate: function(models) {
89                         MailMessage.hasMany(models.MailAttachment);
90                         MailMessage.belongsTo(models.User);
91                         MailMessage.belongsTo(models.MailRoom, {
92                                 onDelete: 'cascade'
93                         });
94                 }
95         });
96
97         return MailMessage;
98 };