2015-03-16 05:58:50 +08:00
|
|
|
|
|
|
|
(function () {
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var
|
|
|
|
_ = require('_'),
|
|
|
|
|
|
|
|
Utils = require('Common/Utils'),
|
|
|
|
|
2015-03-18 20:33:48 +08:00
|
|
|
MessageHelper = require('Helper/Message'),
|
2015-03-16 05:58:50 +08:00
|
|
|
|
|
|
|
AbstractModel = require('Knoin/AbstractModel')
|
|
|
|
;
|
|
|
|
|
|
|
|
/**
|
2015-03-18 20:33:48 +08:00
|
|
|
* @param {string=} sSuperName
|
2015-03-16 05:58:50 +08:00
|
|
|
* @constructor
|
|
|
|
*/
|
2015-03-18 20:33:48 +08:00
|
|
|
function MessageSimpleModel(sSuperName)
|
2015-03-16 05:58:50 +08:00
|
|
|
{
|
2015-03-18 20:33:48 +08:00
|
|
|
AbstractModel.call(this, sSuperName || 'MessageSimpleModel');
|
2015-03-16 05:58:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
_.extend(MessageSimpleModel.prototype, AbstractModel.prototype);
|
|
|
|
|
2015-03-18 20:33:48 +08:00
|
|
|
MessageSimpleModel.prototype.folder = '';
|
2015-03-17 22:12:19 +08:00
|
|
|
MessageSimpleModel.prototype.uid = '';
|
|
|
|
MessageSimpleModel.prototype.subject = '';
|
2015-03-18 20:33:48 +08:00
|
|
|
|
|
|
|
MessageSimpleModel.prototype.to = [];
|
|
|
|
MessageSimpleModel.prototype.from = [];
|
|
|
|
MessageSimpleModel.prototype.cc = [];
|
|
|
|
MessageSimpleModel.prototype.bcc = [];
|
|
|
|
MessageSimpleModel.prototype.replyTo = [];
|
|
|
|
MessageSimpleModel.prototype.deliveredTo = [];
|
|
|
|
|
|
|
|
MessageSimpleModel.prototype.fromAsString = '';
|
|
|
|
MessageSimpleModel.prototype.fromAsStringClear = '';
|
|
|
|
MessageSimpleModel.prototype.toAsString = '';
|
|
|
|
MessageSimpleModel.prototype.toAsStringClear = '';
|
|
|
|
MessageSimpleModel.prototype.senderAsString = '';
|
|
|
|
MessageSimpleModel.prototype.senderAsStringClear = '';
|
|
|
|
|
|
|
|
MessageSimpleModel.prototype.size = 0;
|
|
|
|
MessageSimpleModel.prototype.timestamp = 0;
|
2015-03-16 05:58:50 +08:00
|
|
|
|
|
|
|
MessageSimpleModel.prototype.clear = function ()
|
|
|
|
{
|
2015-03-18 20:33:48 +08:00
|
|
|
this.folder = '';
|
2015-03-16 05:58:50 +08:00
|
|
|
this.uid = '';
|
|
|
|
|
|
|
|
this.subject = '';
|
|
|
|
|
2015-03-18 20:33:48 +08:00
|
|
|
this.to = [];
|
|
|
|
this.from = [];
|
|
|
|
this.cc = [];
|
|
|
|
this.bcc = [];
|
|
|
|
this.replyTo = [];
|
|
|
|
this.deliveredTo = [];
|
|
|
|
|
|
|
|
this.fromAsString = '';
|
|
|
|
this.fromAsStringClear = '';
|
|
|
|
this.toAsString = '';
|
|
|
|
this.toAsStringClear = '';
|
|
|
|
this.senderAsString = '';
|
|
|
|
this.senderAsStringClear = '';
|
|
|
|
|
|
|
|
this.size = 0;
|
|
|
|
this.timestamp = 0;
|
2015-03-16 05:58:50 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2015-03-18 20:33:48 +08:00
|
|
|
* @param {AjaxJsonMessage} oJson
|
2015-03-16 05:58:50 +08:00
|
|
|
* @return {boolean}
|
|
|
|
*/
|
2015-03-18 20:33:48 +08:00
|
|
|
MessageSimpleModel.prototype.initByJson = function (oJson)
|
2015-03-16 05:58:50 +08:00
|
|
|
{
|
|
|
|
var bResult = false;
|
|
|
|
|
2015-03-18 20:33:48 +08:00
|
|
|
if (oJson && 'Object/Message' === oJson['@Object'])
|
2015-03-16 05:58:50 +08:00
|
|
|
{
|
2015-03-18 20:33:48 +08:00
|
|
|
this.folder = Utils.pString(oJson.Folder);
|
|
|
|
this.uid = Utils.pString(oJson.Uid);
|
2015-03-16 05:58:50 +08:00
|
|
|
|
2015-03-18 20:33:48 +08:00
|
|
|
this.subject = Utils.pString(oJson.Subject);
|
2015-03-16 05:58:50 +08:00
|
|
|
|
2015-03-18 20:33:48 +08:00
|
|
|
this.subjectPrefix = '';
|
|
|
|
this.subjectSuffix = this.subject;
|
2015-03-17 22:12:19 +08:00
|
|
|
|
2015-03-18 20:33:48 +08:00
|
|
|
if (Utils.isArray(oJson.SubjectParts))
|
|
|
|
{
|
|
|
|
this.subjectPrefix = Utils.pString(oJson.SubjectParts[0]);
|
|
|
|
this.subjectSuffix = Utils.pString(oJson.SubjectParts[1]);
|
|
|
|
}
|
2015-03-16 05:58:50 +08:00
|
|
|
|
2015-03-18 20:33:48 +08:00
|
|
|
this.from = MessageHelper.emailArrayFromJson(oJson.From);
|
|
|
|
this.to = MessageHelper.emailArrayFromJson(oJson.To);
|
|
|
|
this.cc = MessageHelper.emailArrayFromJson(oJson.Cc);
|
|
|
|
this.bcc = MessageHelper.emailArrayFromJson(oJson.Bcc);
|
|
|
|
this.replyTo = MessageHelper.emailArrayFromJson(oJson.ReplyTo);
|
|
|
|
this.deliveredTo = MessageHelper.emailArrayFromJson(oJson.DeliveredTo);
|
|
|
|
|
|
|
|
this.size = Utils.pInt(oJson.Size);
|
|
|
|
this.timestamp = Utils.pInt(oJson.DateTimeStampInUTC);
|
|
|
|
|
|
|
|
this.fromAsString = MessageHelper.emailArrayToString(this.from, true);
|
|
|
|
this.fromAsStringClear = MessageHelper.emailArrayToStringClear(this.from);
|
|
|
|
|
|
|
|
this.toAsString = MessageHelper.emailArrayToString(this.to, true);
|
|
|
|
this.toAsStringClear = MessageHelper.emailArrayToStringClear(this.to);
|
|
|
|
|
|
|
|
this.populateSenderEmail();
|
2015-03-16 05:58:50 +08:00
|
|
|
|
|
|
|
bResult = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bResult;
|
|
|
|
};
|
|
|
|
|
2015-03-18 20:33:48 +08:00
|
|
|
MessageSimpleModel.prototype.populateSenderEmail = function (bDraftOrSentFolder)
|
|
|
|
{
|
|
|
|
this.senderAsString = this.fromAsString;
|
|
|
|
this.senderAsStringClear = this.fromAsStringClear;
|
|
|
|
|
|
|
|
if (bDraftOrSentFolder)
|
|
|
|
{
|
|
|
|
this.senderAsString = this.toAsString;
|
|
|
|
this.senderAsStringClear = this.toAsStringClear;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-03-17 22:12:19 +08:00
|
|
|
/**
|
|
|
|
* @static
|
2015-03-18 20:33:48 +08:00
|
|
|
* @param {AjaxJsonMessage} oJson
|
2015-03-17 22:12:19 +08:00
|
|
|
* @return {?MessageSimpleModel}
|
|
|
|
*/
|
2015-03-18 20:33:48 +08:00
|
|
|
MessageSimpleModel.newInstanceFromJson = function (oJson)
|
2015-03-17 22:12:19 +08:00
|
|
|
{
|
2015-03-18 20:33:48 +08:00
|
|
|
var oItem = oJson ? new MessageSimpleModel() : null;
|
|
|
|
return oItem && oItem.initByJson(oJson) ? oItem : null;
|
2015-03-17 22:12:19 +08:00
|
|
|
};
|
|
|
|
|
2015-03-16 05:58:50 +08:00
|
|
|
module.exports = MessageSimpleModel;
|
|
|
|
|
|
|
|
}());
|