Built motion from commit 95b01fa.|0.0.70
[motion.git] / server / models / mail_message.js
1 /**
2  * Chat Website Model
3  */
4
5 var crypto = require('crypto');
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.STRING,
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.STRING,
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.STRING,
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                 attachment: DataTypes.TEXT,
50                 text: {
51                         type: DataTypes.BLOB,
52                         get: function() {
53                                 if (this.getDataValue('text')) {
54                                         return this.getDataValue('text').toString();
55                                 }
56                         }
57                 },
58                 html: {
59                         type: DataTypes.BLOB,
60                         get: function() {
61                                 if (this.getDataValue('html')) {
62                                         return this.getDataValue('html').toString();
63                                 }
64                         }
65                 },
66                 reason: DataTypes.TEXT,
67                 status: {
68                         type: DataTypes.ENUM('SENT', 'SENDING', 'RECEIVED', 'FAILED', 'NOTE'),
69                         defaultValue: 'SENDING'
70                 }
71         }, {
72                 tableName: 'mail_messages',
73                 paranoid: true,
74                 associate: function(models) {
75                         MailMessage.hasMany(models.MailAttachment);
76                         MailMessage.belongsTo(models.User);
77                         MailMessage.belongsTo(models.MailRoom, {
78                                 onDelete: 'cascade'
79                         });
80                 }
81         });
82
83         return MailMessage;
84 };