Built motion from commit d3a776a.|0.0.126
[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                 auto: {
73                         type: DataTypes.BOOLEAN,
74                         defaultValue: false
75                 },
76                 status: {
77                         type: DataTypes.ENUM('SENDING', 'SENT', 'RECEIVED', 'FAILED', 'NOTE'),
78                         defaultValue: 'SENDING'
79                 },
80                 retry: {
81                         type: DataTypes.INTEGER,
82                         defaultValue: 0
83                 },
84                 voiceSource: DataTypes.STRING,
85                 userName: DataTypes.STRING,
86                 userFullname: DataTypes.STRING,
87                 accountId: DataTypes.INTEGER,
88                 accountName: DataTypes.STRING
89         }, {
90                 tableName: 'mail_messages',
91                 paranoid: true,
92                 associate: function(models) {
93                         MailMessage.hasMany(models.MailAttachment);
94                         MailMessage.belongsTo(models.User);
95                         MailMessage.belongsTo(models.MailRoom, {
96                                 onDelete: 'cascade'
97                         });
98                 }
99         });
100
101         return MailMessage;
102 };