mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-01-01 12:32:40 +08:00
Code refactoring
This commit is contained in:
parent
f817a680a2
commit
d8c9f7ec14
15 changed files with 469 additions and 189 deletions
|
@ -90,6 +90,15 @@
|
|||
return Utils.isNormal(mValue) ? '' + mValue : '';
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {*} mValue
|
||||
* @return {boolean}
|
||||
*/
|
||||
Utils.pBool = function (mValue)
|
||||
{
|
||||
return !!mValue;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} sComponent
|
||||
* @return {string}
|
||||
|
|
123
dev/Helper/Message.js
Normal file
123
dev/Helper/Message.js
Normal file
|
@ -0,0 +1,123 @@
|
|||
|
||||
(function () {
|
||||
|
||||
'use strict';
|
||||
|
||||
var
|
||||
Utils = require('Common/Utils'),
|
||||
|
||||
EmailModel = require('Model/Email')
|
||||
;
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function MessageHelper() {}
|
||||
|
||||
/**
|
||||
* @param {Array.<EmailModel>} aEmail
|
||||
* @param {boolean=} bFriendlyView
|
||||
* @param {boolean=} bWrapWithLink = false
|
||||
* @return {string}
|
||||
*/
|
||||
MessageHelper.prototype.emailArrayToString = function (aEmail, bFriendlyView, bWrapWithLink)
|
||||
{
|
||||
var
|
||||
aResult = [],
|
||||
iIndex = 0,
|
||||
iLen = 0
|
||||
;
|
||||
|
||||
if (Utils.isNonEmptyArray(aEmail))
|
||||
{
|
||||
for (iIndex = 0, iLen = aEmail.length; iIndex < iLen; iIndex++)
|
||||
{
|
||||
aResult.push(aEmail[iIndex].toLine(bFriendlyView, bWrapWithLink));
|
||||
}
|
||||
}
|
||||
|
||||
return aResult.join(', ');
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Array.<EmailModel>} aEmails
|
||||
* @return {string}
|
||||
*/
|
||||
MessageHelper.prototype.emailArrayToStringClear = function (aEmails)
|
||||
{
|
||||
var
|
||||
aResult = [],
|
||||
iIndex = 0,
|
||||
iLen = 0
|
||||
;
|
||||
|
||||
if (Utils.isNonEmptyArray(aEmails))
|
||||
{
|
||||
for (iIndex = 0, iLen = aEmails.length; iIndex < iLen; iIndex++)
|
||||
{
|
||||
if (aEmails[iIndex] && aEmails[iIndex].email && '' !== aEmails[iIndex].name)
|
||||
{
|
||||
aResult.push(aEmails[iIndex].email);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return aResult.join(', ');
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {?Array} aJson
|
||||
* @return {Array.<EmailModel>}
|
||||
*/
|
||||
MessageHelper.prototype.emailArrayFromJson = function (aJson)
|
||||
{
|
||||
var
|
||||
iIndex = 0,
|
||||
iLen = 0,
|
||||
oEmailModel = null,
|
||||
aResult = []
|
||||
;
|
||||
|
||||
if (Utils.isNonEmptyArray(aJson))
|
||||
{
|
||||
for (iIndex = 0, iLen = aJson.length; iIndex < iLen; iIndex++)
|
||||
{
|
||||
oEmailModel = EmailModel.newInstanceFromJson(aJson[iIndex]);
|
||||
if (oEmailModel)
|
||||
{
|
||||
aResult.push(oEmailModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return aResult;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Array.<EmailModel>} aInputEmails
|
||||
* @param {Object} oUnic
|
||||
* @param {Array} aLocalEmails
|
||||
*/
|
||||
MessageHelper.prototype.replyHelper = function (aInputEmails, oUnic, aLocalEmails)
|
||||
{
|
||||
if (aInputEmails && 0 < aInputEmails.length)
|
||||
{
|
||||
var
|
||||
iIndex = 0,
|
||||
iLen = aInputEmails.length
|
||||
;
|
||||
|
||||
for (; iIndex < iLen; iIndex++)
|
||||
{
|
||||
if (Utils.isUnd(oUnic[aInputEmails[iIndex].email]))
|
||||
{
|
||||
oUnic[aInputEmails[iIndex].email] = true;
|
||||
aLocalEmails.push(aInputEmails[iIndex]);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = new MessageHelper();
|
||||
|
||||
}());
|
|
@ -16,9 +16,10 @@
|
|||
|
||||
PgpStore = require('Stores/User/Pgp'),
|
||||
|
||||
EmailModel = require('Model/Email'),
|
||||
AttachmentModel = require('Model/Attachment'),
|
||||
|
||||
MessageHelper = require('Helper/Message'),
|
||||
|
||||
AbstractModel = require('Knoin/AbstractModel')
|
||||
;
|
||||
|
||||
|
@ -148,114 +149,6 @@
|
|||
return oMessageModel.initByJson(oJsonMessage) ? oMessageModel : null;
|
||||
};
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @param {Array} aEmail
|
||||
* @param {boolean=} bFriendlyView
|
||||
* @param {boolean=} bWrapWithLink = false
|
||||
* @return {string}
|
||||
*/
|
||||
MessageModel.emailsToLine = function (aEmail, bFriendlyView, bWrapWithLink)
|
||||
{
|
||||
var
|
||||
aResult = [],
|
||||
iIndex = 0,
|
||||
iLen = 0
|
||||
;
|
||||
|
||||
if (Utils.isNonEmptyArray(aEmail))
|
||||
{
|
||||
for (iIndex = 0, iLen = aEmail.length; iIndex < iLen; iIndex++)
|
||||
{
|
||||
aResult.push(aEmail[iIndex].toLine(bFriendlyView, bWrapWithLink));
|
||||
}
|
||||
}
|
||||
|
||||
return aResult.join(', ');
|
||||
};
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @param {Array} aEmail
|
||||
* @return {string}
|
||||
*/
|
||||
MessageModel.emailsToLineClear = function (aEmail)
|
||||
{
|
||||
var
|
||||
aResult = [],
|
||||
iIndex = 0,
|
||||
iLen = 0
|
||||
;
|
||||
|
||||
if (Utils.isNonEmptyArray(aEmail))
|
||||
{
|
||||
for (iIndex = 0, iLen = aEmail.length; iIndex < iLen; iIndex++)
|
||||
{
|
||||
if (aEmail[iIndex] && aEmail[iIndex].email && '' !== aEmail[iIndex].name)
|
||||
{
|
||||
aResult.push(aEmail[iIndex].email);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return aResult.join(', ');
|
||||
};
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @param {?Array} aJsonEmails
|
||||
* @return {Array.<EmailModel>}
|
||||
*/
|
||||
MessageModel.initEmailsFromJson = function (aJsonEmails)
|
||||
{
|
||||
var
|
||||
iIndex = 0,
|
||||
iLen = 0,
|
||||
oEmailModel = null,
|
||||
aResult = []
|
||||
;
|
||||
|
||||
if (Utils.isNonEmptyArray(aJsonEmails))
|
||||
{
|
||||
for (iIndex = 0, iLen = aJsonEmails.length; iIndex < iLen; iIndex++)
|
||||
{
|
||||
oEmailModel = EmailModel.newInstanceFromJson(aJsonEmails[iIndex]);
|
||||
if (oEmailModel)
|
||||
{
|
||||
aResult.push(oEmailModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return aResult;
|
||||
};
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @param {Array.<EmailModel>} aMessageEmails
|
||||
* @param {Object} oLocalUnic
|
||||
* @param {Array} aLocalEmails
|
||||
*/
|
||||
MessageModel.replyHelper = function (aMessageEmails, oLocalUnic, aLocalEmails)
|
||||
{
|
||||
if (aMessageEmails && 0 < aMessageEmails.length)
|
||||
{
|
||||
var
|
||||
iIndex = 0,
|
||||
iLen = aMessageEmails.length
|
||||
;
|
||||
|
||||
for (; iIndex < iLen; iIndex++)
|
||||
{
|
||||
if (Utils.isUnd(oLocalUnic[aMessageEmails[iIndex].email]))
|
||||
{
|
||||
oLocalUnic[aMessageEmails[iIndex].email] = true;
|
||||
aLocalEmails.push(aMessageEmails[iIndex]);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
MessageModel.prototype.clear = function ()
|
||||
{
|
||||
this.folderFullNameRaw = '';
|
||||
|
@ -373,12 +266,12 @@
|
|||
|
||||
this.size(Utils.pInt(oJsonMessage.Size));
|
||||
|
||||
this.from = MessageModel.initEmailsFromJson(oJsonMessage.From);
|
||||
this.to = MessageModel.initEmailsFromJson(oJsonMessage.To);
|
||||
this.cc = MessageModel.initEmailsFromJson(oJsonMessage.Cc);
|
||||
this.bcc = MessageModel.initEmailsFromJson(oJsonMessage.Bcc);
|
||||
this.replyTo = MessageModel.initEmailsFromJson(oJsonMessage.ReplyTo);
|
||||
this.deliveredTo = MessageModel.initEmailsFromJson(oJsonMessage.DeliveredTo);
|
||||
this.from = MessageHelper.emailArrayFromJson(oJsonMessage.From);
|
||||
this.to = MessageHelper.emailArrayFromJson(oJsonMessage.To);
|
||||
this.cc = MessageHelper.emailArrayFromJson(oJsonMessage.Cc);
|
||||
this.bcc = MessageHelper.emailArrayFromJson(oJsonMessage.Bcc);
|
||||
this.replyTo = MessageHelper.emailArrayFromJson(oJsonMessage.ReplyTo);
|
||||
this.deliveredTo = MessageHelper.emailArrayFromJson(oJsonMessage.DeliveredTo);
|
||||
|
||||
this.subject(oJsonMessage.Subject);
|
||||
if (Utils.isArray(oJsonMessage.SubjectParts))
|
||||
|
@ -396,10 +289,10 @@
|
|||
this.hasAttachments(!!oJsonMessage.HasAttachments);
|
||||
this.attachmentsMainType(oJsonMessage.AttachmentsMainType);
|
||||
|
||||
this.fromEmailString(MessageModel.emailsToLine(this.from, true));
|
||||
this.fromClearEmailString(MessageModel.emailsToLineClear(this.from));
|
||||
this.toEmailsString(MessageModel.emailsToLine(this.to, true));
|
||||
this.toClearEmailsString(MessageModel.emailsToLineClear(this.to));
|
||||
this.fromEmailString(MessageHelper.emailArrayToString(this.from, true));
|
||||
this.fromClearEmailString(MessageHelper.emailArrayToStringClear(this.from));
|
||||
this.toEmailsString(MessageHelper.emailArrayToString(this.to, true));
|
||||
this.toClearEmailsString(MessageHelper.emailArrayToStringClear(this.to));
|
||||
|
||||
this.threads(Utils.isArray(oJsonMessage.Threads) ? oJsonMessage.Threads : []);
|
||||
|
||||
|
@ -524,7 +417,7 @@
|
|||
*/
|
||||
MessageModel.prototype.fromToLine = function (bFriendlyView, bWrapWithLink)
|
||||
{
|
||||
return MessageModel.emailsToLine(this.from, bFriendlyView, bWrapWithLink);
|
||||
return MessageHelper.emailArrayToString(this.from, bFriendlyView, bWrapWithLink);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -549,7 +442,7 @@
|
|||
*/
|
||||
MessageModel.prototype.toToLine = function (bFriendlyView, bWrapWithLink)
|
||||
{
|
||||
return MessageModel.emailsToLine(this.to, bFriendlyView, bWrapWithLink);
|
||||
return MessageHelper.emailArrayToString(this.to, bFriendlyView, bWrapWithLink);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -559,7 +452,7 @@
|
|||
*/
|
||||
MessageModel.prototype.ccToLine = function (bFriendlyView, bWrapWithLink)
|
||||
{
|
||||
return MessageModel.emailsToLine(this.cc, bFriendlyView, bWrapWithLink);
|
||||
return MessageHelper.emailArrayToString(this.cc, bFriendlyView, bWrapWithLink);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -569,7 +462,7 @@
|
|||
*/
|
||||
MessageModel.prototype.bccToLine = function (bFriendlyView, bWrapWithLink)
|
||||
{
|
||||
return MessageModel.emailsToLine(this.bcc, bFriendlyView, bWrapWithLink);
|
||||
return MessageHelper.emailArrayToString(this.bcc, bFriendlyView, bWrapWithLink);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -579,7 +472,7 @@
|
|||
*/
|
||||
MessageModel.prototype.replyToToLine = function (bFriendlyView, bWrapWithLink)
|
||||
{
|
||||
return MessageModel.emailsToLine(this.replyTo, bFriendlyView, bWrapWithLink);
|
||||
return MessageHelper.emailArrayToString(this.replyTo, bFriendlyView, bWrapWithLink);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -778,10 +671,10 @@
|
|||
oUnic = Utils.isUnd(oExcludeEmails) ? {} : oExcludeEmails
|
||||
;
|
||||
|
||||
MessageModel.replyHelper(this.replyTo, oUnic, aResult);
|
||||
MessageHelper.replyHelper(this.replyTo, oUnic, aResult);
|
||||
if (0 === aResult.length)
|
||||
{
|
||||
MessageModel.replyHelper(this.from, oUnic, aResult);
|
||||
MessageHelper.replyHelper(this.from, oUnic, aResult);
|
||||
}
|
||||
|
||||
return aResult;
|
||||
|
@ -799,14 +692,14 @@
|
|||
oUnic = Utils.isUnd(oExcludeEmails) ? {} : oExcludeEmails
|
||||
;
|
||||
|
||||
MessageModel.replyHelper(this.replyTo, oUnic, aToResult);
|
||||
MessageHelper.replyHelper(this.replyTo, oUnic, aToResult);
|
||||
if (0 === aToResult.length)
|
||||
{
|
||||
MessageModel.replyHelper(this.from, oUnic, aToResult);
|
||||
MessageHelper.replyHelper(this.from, oUnic, aToResult);
|
||||
}
|
||||
|
||||
MessageModel.replyHelper(this.to, oUnic, aToResult);
|
||||
MessageModel.replyHelper(this.cc, oUnic, aCcResult);
|
||||
MessageHelper.replyHelper(this.to, oUnic, aToResult);
|
||||
MessageHelper.replyHelper(this.cc, oUnic, aCcResult);
|
||||
|
||||
return [aToResult, aCcResult];
|
||||
};
|
||||
|
|
63
dev/Model/MessageDynamic.js
Normal file
63
dev/Model/MessageDynamic.js
Normal file
|
@ -0,0 +1,63 @@
|
|||
|
||||
(function () {
|
||||
|
||||
'use strict';
|
||||
|
||||
var
|
||||
_ = require('_'),
|
||||
ko = require('ko'),
|
||||
|
||||
Enums = require('Common/Enums'),
|
||||
Utils = require('Common/Utils'),
|
||||
|
||||
MessageHelper = require('Helper/Message'),
|
||||
|
||||
MessageSimpleModel = require('Model/MessageSimple')
|
||||
;
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function MessageDynamicModel()
|
||||
{
|
||||
MessageSimpleModel.call(this, 'MessageDynamicModel');
|
||||
|
||||
this.flags = {};
|
||||
this.states = {};
|
||||
|
||||
this.flags.unseen = ko.observable(false);
|
||||
this.flags.deleted = ko.observable(false);
|
||||
this.flags.flagged = ko.observable(false);
|
||||
this.flags.answered = ko.observable(false);
|
||||
this.flags.forwarded = ko.observable(false);
|
||||
|
||||
this.states.checked = ko.observable(false);
|
||||
this.states.deleted = ko.observable(false);
|
||||
this.states.selected = ko.observable(false);
|
||||
this.states.focused = ko.observable(false);
|
||||
|
||||
this.states.showReadReceipt = ko.observable(false);
|
||||
this.states.showExternalImages = ko.observable(false);
|
||||
|
||||
this.states.hasUnseenSubMessage = ko.observable(false);
|
||||
this.states.hasFlaggedSubMessage = ko.observable(false);
|
||||
|
||||
this.threads = ko.observableArray([]);
|
||||
}
|
||||
|
||||
_.extend(MessageDynamicModel.prototype, MessageSimpleModel.prototype);
|
||||
|
||||
MessageDynamicModel.prototype.clear = function ()
|
||||
{
|
||||
this.flags.unseen(false);
|
||||
this.flags.deleted(false);
|
||||
this.flags.flagged(false);
|
||||
this.flags.answered(false);
|
||||
this.flags.forwarded(false);
|
||||
|
||||
this.threads([]);
|
||||
};
|
||||
|
||||
module.exports = MessageDynamicModel;
|
||||
|
||||
}());
|
119
dev/Model/MessageFull.js
Normal file
119
dev/Model/MessageFull.js
Normal file
|
@ -0,0 +1,119 @@
|
|||
|
||||
(function () {
|
||||
|
||||
'use strict';
|
||||
|
||||
var
|
||||
_ = require('_'),
|
||||
|
||||
Enums = require('Common/Enums'),
|
||||
Utils = require('Common/Utils'),
|
||||
|
||||
// MessageHelper = require('Helper/Message'),
|
||||
|
||||
MessageSimpleModel = require('Model/MessageSimple')
|
||||
;
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function MessageFullModel()
|
||||
{
|
||||
MessageSimpleModel.call(this, 'MessageFullModel');
|
||||
}
|
||||
|
||||
_.extend(MessageFullModel.prototype, MessageSimpleModel.prototype);
|
||||
|
||||
MessageFullModel.prototype.priority = 0;
|
||||
MessageFullModel.prototype.hash = '';
|
||||
MessageFullModel.prototype.requestHash = '';
|
||||
MessageFullModel.prototype.proxy = false;
|
||||
MessageFullModel.prototype.hasAttachments = false;
|
||||
MessageFullModel.prototype.attachmentsMainType = '';
|
||||
MessageFullModel.prototype.attachmentsClass = '';
|
||||
|
||||
MessageFullModel.prototype.clear = function ()
|
||||
{
|
||||
MessageSimpleModel.prototype.clear.call(this);
|
||||
|
||||
this.priority = 0;
|
||||
this.hash = '';
|
||||
this.requestHash = '';
|
||||
|
||||
this.proxy = false;
|
||||
|
||||
this.hasAttachments = false;
|
||||
this.attachmentsMainType = '';
|
||||
this.attachmentsClass = '';
|
||||
};
|
||||
|
||||
MessageFullModel.prototype.getAttachmentsClass = function ()
|
||||
{
|
||||
var sClass = '';
|
||||
if (this.hasAttachments)
|
||||
{
|
||||
sClass = 'icon-attachment';
|
||||
switch (this.attachmentsMainType)
|
||||
{
|
||||
case 'image':
|
||||
sClass = 'icon-image';
|
||||
break;
|
||||
case 'archive':
|
||||
sClass = 'icon-file-zip';
|
||||
break;
|
||||
case 'doc':
|
||||
sClass = 'icon-file-text';
|
||||
break;
|
||||
case 'certificate':
|
||||
sClass = 'icon-file-certificate';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return sClass;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {AjaxJsonMessage} oJson
|
||||
* @return {boolean}
|
||||
*/
|
||||
MessageFullModel.prototype.initByJson = function (oJson)
|
||||
{
|
||||
var bResult = false;
|
||||
|
||||
if (oJson && 'Object/Message' === oJson['@Object'] &&
|
||||
MessageSimpleModel.prototype.initByJson.call(this, oJson))
|
||||
{
|
||||
this.priority = Utils.pInt(oJson.Priority);
|
||||
this.priority = Utils.inArray(this.priority, [Enums.MessagePriority.High, Enums.MessagePriority.Low]) ?
|
||||
this.priority : Enums.MessagePriority.Normal;
|
||||
|
||||
this.hash = Utils.pString(oJson.Hash);
|
||||
this.requestHash = Utils.pString(oJson.RequestHash);
|
||||
|
||||
this.proxy = !!oJson.ExternalProxy;
|
||||
|
||||
this.hasAttachments = !!oJson.HasAttachments;
|
||||
this.attachmentsMainType = Utils.pString(oJson.AttachmentsMainType);
|
||||
this.attachmentsClass = this.getAttachmentsClass();
|
||||
|
||||
bResult = true;
|
||||
}
|
||||
|
||||
return bResult;
|
||||
};
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @param {AjaxJsonMessage} oJson
|
||||
* @return {?MessageFullModel}
|
||||
*/
|
||||
MessageFullModel.newInstanceFromJson = function (oJson)
|
||||
{
|
||||
var oItem = oJson ? new MessageFullModel() : null;
|
||||
return oItem && oItem.initByJson(oJson) ? oItem : null;
|
||||
};
|
||||
|
||||
module.exports = MessageFullModel;
|
||||
|
||||
}());
|
|
@ -8,67 +8,109 @@
|
|||
|
||||
Utils = require('Common/Utils'),
|
||||
|
||||
MessageModel = require('Model/Message'),
|
||||
MessageHelper = require('Helper/Message'),
|
||||
|
||||
AbstractModel = require('Knoin/AbstractModel')
|
||||
;
|
||||
|
||||
/**
|
||||
* @param {string=} sSuperName
|
||||
* @constructor
|
||||
*/
|
||||
function MessageSimpleModel()
|
||||
function MessageSimpleModel(sSuperName)
|
||||
{
|
||||
AbstractModel.call(this, 'MessageSimpleModel');
|
||||
|
||||
this.clear();
|
||||
AbstractModel.call(this, sSuperName || 'MessageSimpleModel');
|
||||
}
|
||||
|
||||
_.extend(MessageSimpleModel.prototype, AbstractModel.prototype);
|
||||
|
||||
MessageSimpleModel.prototype.selected = false;
|
||||
MessageSimpleModel.prototype.folderFullNameRaw = '';
|
||||
MessageSimpleModel.prototype.folder = '';
|
||||
MessageSimpleModel.prototype.uid = '';
|
||||
MessageSimpleModel.prototype.size = 0;
|
||||
MessageSimpleModel.prototype.sender = '';
|
||||
MessageSimpleModel.prototype.subject = '';
|
||||
MessageSimpleModel.prototype.dateInUTC = 0;
|
||||
|
||||
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;
|
||||
|
||||
MessageSimpleModel.prototype.clear = function ()
|
||||
{
|
||||
this.selected = false;
|
||||
|
||||
this.folderFullNameRaw = '';
|
||||
this.folder = '';
|
||||
this.uid = '';
|
||||
this.size = 0;
|
||||
|
||||
this.sender = '';
|
||||
this.subject = '';
|
||||
|
||||
this.dateInUTC = 0;
|
||||
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;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {AjaxJsonMessage} oJsonMessage
|
||||
* @param {AjaxJsonMessage} oJson
|
||||
* @return {boolean}
|
||||
*/
|
||||
MessageSimpleModel.prototype.initByJson = function (oJsonMessage)
|
||||
MessageSimpleModel.prototype.initByJson = function (oJson)
|
||||
{
|
||||
var bResult = false;
|
||||
|
||||
if (oJsonMessage && 'Object/Message' === oJsonMessage['@Object'])
|
||||
if (oJson && 'Object/Message' === oJson['@Object'])
|
||||
{
|
||||
this.selected = false;
|
||||
this.folder = Utils.pString(oJson.Folder);
|
||||
this.uid = Utils.pString(oJson.Uid);
|
||||
|
||||
this.folderFullNameRaw = oJsonMessage.Folder;
|
||||
this.uid = oJsonMessage.Uid;
|
||||
this.size = Utils.pInt(oJsonMessage.Size);
|
||||
this.subject = Utils.pString(oJson.Subject);
|
||||
|
||||
this.sender = MessageModel.emailsToLine(
|
||||
MessageModel.initEmailsFromJson(oJsonMessage.From), true);
|
||||
this.subjectPrefix = '';
|
||||
this.subjectSuffix = this.subject;
|
||||
|
||||
this.subject = oJsonMessage.Subject;
|
||||
if (Utils.isArray(oJson.SubjectParts))
|
||||
{
|
||||
this.subjectPrefix = Utils.pString(oJson.SubjectParts[0]);
|
||||
this.subjectSuffix = Utils.pString(oJson.SubjectParts[1]);
|
||||
}
|
||||
|
||||
this.dateInUTC = Utils.pInt(oJsonMessage.DateTimeStampInUTC);
|
||||
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();
|
||||
|
||||
bResult = true;
|
||||
}
|
||||
|
@ -76,15 +118,27 @@
|
|||
return bResult;
|
||||
};
|
||||
|
||||
MessageSimpleModel.prototype.populateSenderEmail = function (bDraftOrSentFolder)
|
||||
{
|
||||
this.senderAsString = this.fromAsString;
|
||||
this.senderAsStringClear = this.fromAsStringClear;
|
||||
|
||||
if (bDraftOrSentFolder)
|
||||
{
|
||||
this.senderAsString = this.toAsString;
|
||||
this.senderAsStringClear = this.toAsStringClear;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @param {AjaxJsonMessage} oJsonMessage
|
||||
* @param {AjaxJsonMessage} oJson
|
||||
* @return {?MessageSimpleModel}
|
||||
*/
|
||||
MessageSimpleModel.newInstanceFromJson = function (oJsonMessage)
|
||||
MessageSimpleModel.newInstanceFromJson = function (oJson)
|
||||
{
|
||||
var oMessageModel = new MessageSimpleModel();
|
||||
return oMessageModel.initByJson(oJsonMessage) ? oMessageModel : null;
|
||||
var oItem = oJson ? new MessageSimpleModel() : null;
|
||||
return oItem && oItem.initByJson(oJson) ? oItem : null;
|
||||
};
|
||||
|
||||
module.exports = MessageSimpleModel;
|
||||
|
|
|
@ -26,7 +26,8 @@
|
|||
|
||||
Remote = require('Remote/User/Ajax'),
|
||||
|
||||
MessageModel = require('Model/Message')
|
||||
MessageModel = require('Model/Message'),
|
||||
MessageHelper = require('Helper/Message')
|
||||
;
|
||||
|
||||
/**
|
||||
|
@ -299,7 +300,8 @@
|
|||
{
|
||||
NotificationStore.displayDesktopNotification(
|
||||
Links.notificationMailIcon(),
|
||||
MessageModel.emailsToLine(MessageModel.initEmailsFromJson(aNewMessages[iIndex].From), false),
|
||||
MessageHelper.emailArrayToString(
|
||||
MessageHelper.emailArrayFromJson(aNewMessages[iIndex].From), false),
|
||||
aNewMessages[iIndex].Subject
|
||||
);
|
||||
}
|
||||
|
|
|
@ -716,7 +716,7 @@
|
|||
})
|
||||
.on('click', '.thread-list .thread-list-message', function () {
|
||||
var oMessage = ko.dataFor(this);
|
||||
if (oMessage && oMessage.folderFullNameRaw && oMessage.uid)
|
||||
if (oMessage && oMessage.folder && oMessage.uid)
|
||||
{
|
||||
self.openThreadMessage(oMessage.uid);
|
||||
}
|
||||
|
|
|
@ -1245,6 +1245,17 @@ END;
|
|||
\str_replace(array('"', '/', '\\', '*', '?', '<', '>', '|', ':'), ' ', $sValue));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sValue
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function Trim($sValue)
|
||||
{
|
||||
return \trim(\preg_replace('/^[\x00-\x1F]+/u', '',
|
||||
\preg_replace('/[\x00-\x1F]+$/u', '', \trim($sValue))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sDir
|
||||
*
|
||||
|
|
|
@ -194,8 +194,8 @@ class ImapClient extends \MailSo\Net\NetClient
|
|||
\MailSo\Log\Enumerations\Type::ERROR, true);
|
||||
}
|
||||
|
||||
$sLogin = \trim($sLogin);
|
||||
$sLogin = \MailSo\Base\Utils::IdnToAscii($sLogin);
|
||||
$sLogin = \MailSo\Base\Utils::IdnToAscii(\MailSo\Base\Utils::Trim($sLogin));
|
||||
|
||||
$sPassword = $sPassword;
|
||||
|
||||
$this->sLogginedUser = $sLogin;
|
||||
|
@ -326,7 +326,7 @@ class ImapClient extends \MailSo\Net\NetClient
|
|||
|
||||
try
|
||||
{
|
||||
$this->SendRequestWithCheck('AUTHENTICATE', array('XOAUTH2', trim($sXOAuth2Token)));
|
||||
$this->SendRequestWithCheck('AUTHENTICATE', array('XOAUTH2', \trim($sXOAuth2Token)));
|
||||
}
|
||||
catch (\MailSo\Imap\Exceptions\NegativeResponseException $oException)
|
||||
{
|
||||
|
|
|
@ -58,9 +58,11 @@ class Email
|
|||
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
|
||||
}
|
||||
|
||||
$this->sEmail = \MailSo\Base\Utils::IdnToAscii(\trim($sEmail), true);
|
||||
$this->sDisplayName = \trim($sDisplayName);
|
||||
$this->sRemark = \trim($sRemark);
|
||||
$this->sEmail = \MailSo\Base\Utils::IdnToAscii(
|
||||
\MailSo\Base\Utils::Trim($sEmail), true);
|
||||
|
||||
$this->sDisplayName = \MailSo\Base\Utils::Trim($sDisplayName);
|
||||
$this->sRemark = \MailSo\Base\Utils::Trim($sRemark);
|
||||
|
||||
$this->sDkimStatus = \MailSo\Mime\Enumerations\DkimStatus::NONE;
|
||||
$this->sDkimValue = '';
|
||||
|
@ -88,6 +90,7 @@ class Email
|
|||
*/
|
||||
public static function Parse($sEmailAddress)
|
||||
{
|
||||
$sEmailAddress = \MailSo\Base\Utils::Trim($sEmailAddress);
|
||||
if (!\MailSo\Base\Validator::NotEmptyString($sEmailAddress, true))
|
||||
{
|
||||
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
|
||||
|
|
|
@ -26,6 +26,7 @@ class EmailCollection extends \MailSo\Base\Collection
|
|||
{
|
||||
parent::__construct();
|
||||
|
||||
$sEmailAddresses = \MailSo\Base\Utils::Trim($sEmailAddresses);
|
||||
if (0 < \strlen($sEmailAddresses))
|
||||
{
|
||||
$this->parseEmailAddresses($sEmailAddresses);
|
||||
|
@ -213,7 +214,7 @@ class EmailCollection extends \MailSo\Base\Collection
|
|||
$this->Add(
|
||||
\MailSo\Mime\Email::Parse(\substr($sWorkingRecipients, $iEmailStartPos, $iEmailEndPos - $iEmailStartPos))
|
||||
);
|
||||
|
||||
|
||||
$iEmailStartPos = $iCurrentPos + 1;
|
||||
}
|
||||
catch (\MailSo\Base\Exceptions\InvalidArgumentException $oException)
|
||||
|
|
|
@ -186,7 +186,7 @@ class SmtpClient extends \MailSo\Net\NetClient
|
|||
*/
|
||||
public function Login($sLogin, $sPassword)
|
||||
{
|
||||
$sLogin = \MailSo\Base\Utils::IdnToAscii($sLogin);
|
||||
$sLogin = \MailSo\Base\Utils::IdnToAscii(\MailSo\Base\Utils::Trim($sLogin));
|
||||
|
||||
if ($this->IsAuthSupported('LOGIN'))
|
||||
{
|
||||
|
@ -283,7 +283,7 @@ class SmtpClient extends \MailSo\Net\NetClient
|
|||
{
|
||||
try
|
||||
{
|
||||
$this->sendRequestWithCheck('AUTH', 235, 'XOAUTH2 '.trim($sXOAuth2Token));
|
||||
$this->sendRequestWithCheck('AUTH', 235, 'XOAUTH2 '.\trim($sXOAuth2Token));
|
||||
}
|
||||
catch (\MailSo\Smtp\Exceptions\NegativeResponseException $oException)
|
||||
{
|
||||
|
@ -315,7 +315,9 @@ class SmtpClient extends \MailSo\Net\NetClient
|
|||
*/
|
||||
public function MailFrom($sFrom, $sSizeIfSupported = '', $bDsn = false)
|
||||
{
|
||||
$sFrom = \MailSo\Base\Utils::IdnToAscii($sFrom, true);
|
||||
$sFrom = \MailSo\Base\Utils::IdnToAscii(
|
||||
\MailSo\Base\Utils::Trim($sFrom), true);
|
||||
|
||||
$sCmd = 'FROM:<'.$sFrom.'>';
|
||||
|
||||
$sSizeIfSupported = (string) $sSizeIfSupported;
|
||||
|
@ -356,7 +358,9 @@ class SmtpClient extends \MailSo\Net\NetClient
|
|||
\MailSo\Log\Enumerations\Type::ERROR, true);
|
||||
}
|
||||
|
||||
$sTo = \MailSo\Base\Utils::IdnToAscii($sTo, true);
|
||||
$sTo = \MailSo\Base\Utils::IdnToAscii(
|
||||
\MailSo\Base\Utils::Trim($sTo), true);
|
||||
|
||||
$sCmd = 'TO:<'.$sTo.'>';
|
||||
|
||||
if ($bDsn && $this->IsSupported('DSN'))
|
||||
|
@ -495,6 +499,9 @@ class SmtpClient extends \MailSo\Net\NetClient
|
|||
*/
|
||||
public function Vrfy($sUser)
|
||||
{
|
||||
$sUser = \MailSo\Base\Utils::IdnToAscii(
|
||||
\MailSo\Base\Utils::Trim($sUser));
|
||||
|
||||
$this->sendRequestWithCheck('VRFY', array(250, 251, 252), $sUser);
|
||||
|
||||
return $this;
|
||||
|
|
|
@ -385,12 +385,6 @@ class Actions
|
|||
}
|
||||
}
|
||||
|
||||
// $sSubQuerty = \trim(\trim($this->Http()->GetQuery('s', '')), ' /');
|
||||
// $sSubSubQuerty = \trim(\trim($this->Http()->GetQuery('ss', '')), ' /');
|
||||
//
|
||||
// $sQuery .= 0 < \strlen($sSubQuerty) ? '/'.$sSubQuerty : '';
|
||||
// $sQuery .= 0 < \strlen($sSubSubQuerty) ? '/'.$sSubSubQuerty : '';
|
||||
|
||||
if ('' === $this->GetSpecAuthToken())
|
||||
{
|
||||
$aPaths = \explode('/', $sQuery);
|
||||
|
@ -1632,7 +1626,7 @@ class Actions
|
|||
$aResult['UserBackgroundHash'] = (string) $oSettings->GetConf('UserBackgroundHash', $aResult['UserBackgroundHash']);
|
||||
// if (!empty($aResult['UserBackgroundName']) && !empty($aResult['UserBackgroundHash']))
|
||||
// {
|
||||
// $aResult['IncludeBackground'] = './?/Raw/&s=/{{USER}}/UserBackground/&ss=/'.
|
||||
// $aResult['IncludeBackground'] = './?/Raw/&q[]=/{{USER}}/UserBackground/&q[]=/'.
|
||||
// $aResult['UserBackgroundHash'].'/';
|
||||
// }
|
||||
}
|
||||
|
@ -1834,7 +1828,8 @@ class Actions
|
|||
{
|
||||
$this->Plugins()->RunHook('filter.login-credentials.step-1', array(&$sEmail, &$sPassword));
|
||||
|
||||
$sEmail = \MailSo\Base\Utils::StrToLowerIfAscii($sEmail);
|
||||
$sEmail = \MailSo\Base\Utils::StrToLowerIfAscii(
|
||||
\MailSo\Base\Utils::Trim($sEmail));
|
||||
|
||||
if (false === \strpos($sEmail, '@'))
|
||||
{
|
||||
|
@ -2069,7 +2064,7 @@ class Actions
|
|||
*/
|
||||
public function DoLogin()
|
||||
{
|
||||
$sEmail = \trim($this->GetActionParam('Email', ''));
|
||||
$sEmail = \MailSo\Base\Utils::Trim($this->GetActionParam('Email', ''));
|
||||
$sPassword = $this->GetActionParam('Password', '');
|
||||
$sLanguage = $this->GetActionParam('Language', '');
|
||||
$bSignMe = '1' === (string) $this->GetActionParam('SignMe', '0');
|
||||
|
@ -7707,8 +7702,8 @@ class Actions
|
|||
\array_shift($aParams);
|
||||
$sLast = \array_pop($aParams);
|
||||
|
||||
$sUrl = $this->Http()->GetFullUrl().'?/Raw/&s=/'.implode('/', $aParams).'/&ss=/'.$sLast;
|
||||
$sFullUrl = 'https://docs.google.com/viewer?embedded=true&url='.urlencode($sUrl);
|
||||
$sUrl = $this->Http()->GetFullUrl().'?/Raw/&q[]=/'.\implode('/', $aParams).'/&q[]=/'.$sLast;
|
||||
$sFullUrl = 'https://docs.google.com/viewer?embedded=true&url='.\urlencode($sUrl);
|
||||
|
||||
@\header('Content-Type: text/html; charset=utf-8');
|
||||
echo '<html style="height: 100%; width: 100%; margin: 0; padding: 0"><head></head>'.
|
||||
|
@ -8725,7 +8720,7 @@ class Actions
|
|||
*/
|
||||
public function GetActionParam($sKey, $mDefault = null)
|
||||
{
|
||||
return is_array($this->aCurrentActionParams) && isset($this->aCurrentActionParams[$sKey]) ?
|
||||
return \is_array($this->aCurrentActionParams) && isset($this->aCurrentActionParams[$sKey]) ?
|
||||
$this->aCurrentActionParams[$sKey] : $mDefault;
|
||||
}
|
||||
|
||||
|
|
|
@ -215,9 +215,9 @@
|
|||
<div data-bind="foreach: viewThreadMessages, visible: !messageListOfThreadsLoading()">
|
||||
<li class="e-item thread-list-message" role="presentation" data-bind="css: {'selected': selected}">
|
||||
<a class="e-link menuitem" href="#" tabindex="-1" onclick="return false;">
|
||||
<span class="thread-date pull-right" data-moment-format="SHORT" data-bind="moment: dateInUTC"></span>
|
||||
<span class="thread-date pull-right" data-moment-format="SHORT" data-bind="moment: timestamp"></span>
|
||||
<div style="text-overflow: ellipsis; overflow: hidden;">
|
||||
<span class="thread-from" data-bind="text: sender"></span>
|
||||
<span class="thread-from" data-bind="text: fromAsString"></span>
|
||||
|
||||
</div>
|
||||
<div style="text-overflow: ellipsis; overflow: hidden;">
|
||||
|
|
Loading…
Reference in a new issue