this.newMessageCommand = Utils.createCommand(this, function () { var aC = this.contactsCheckedOrSelected(), aE = []; if (Utils.isNonEmptyArray(aC)) { aE = _.map(aC, function (oItem) { if (oItem) { var aData = oItem.getNameAndEmailHelper(), oEmail = aData ? new EmailModel(aData[0], aData[1]) : null ; if (oEmail && oEmail.validate()) { return oEmail; } } return null; }); aE = _.compact(aE); } if (Utils.isNonEmptyArray(aE)) { kn.hideScreenPopup(require('View/Popup/Contacts')); kn.showScreenPopup(require('View/Popup/Compose'), [Enums.ComposeType.Empty, null, aE]); } }, function () {
MessageModel.prototype.initAttachmentsFromJson = function (oJsonAttachments) { var iIndex = 0, iLen = 0, oAttachmentModel = null, aResult = [] ; if (oJsonAttachments && 'Collection/AttachmentCollection' === oJsonAttachments['@Object'] && Utils.isNonEmptyArray(oJsonAttachments['@Collection'])) { for (iIndex = 0, iLen = oJsonAttachments['@Collection'].length; iIndex < iLen; iIndex++) { oAttachmentModel = AttachmentModel.newInstanceFromJson(oJsonAttachments['@Collection'][iIndex]); if (oAttachmentModel) { if ('' !== oAttachmentModel.cidWithOutTags && 0 < this.foundedCIDs.length && 0 <= Utils.inArray(oAttachmentModel.cidWithOutTags, this.foundedCIDs)) { oAttachmentModel.isLinked = true; } aResult.push(oAttachmentModel); } } } return aResult; };
/** * @param {(AjaxJsonAttachment|null)} oJsonAttachments * @returns {Array} */ initAttachmentsFromJson(json) { let index = 0, len = 0, attachment = null; const result = []; if (json && 'Collection/AttachmentCollection' === json['@Object'] && isNonEmptyArray(json['@Collection'])) { for (index = 0, len = json['@Collection'].length; index < len; index++) { attachment = AttachmentModel.newInstanceFromJson(json['@Collection'][index]); if (attachment) { if ('' !== attachment.cidWithOutTags && 0 < this.foundedCIDs.length && 0 <= inArray(attachment.cidWithOutTags, this.foundedCIDs)) { attachment.isLinked = true; } result.push(attachment); } } } return result; }
ContactsPopupView.prototype.populateViewContact = function (oContact) { var sId = '', sLastName = '', sFirstName = '', aList = [] ; this.watchHash(false); this.emptySelection(false); this.viewReadOnly(false); this.viewTags(''); if (oContact) { sId = oContact.idContact; if (Utils.isNonEmptyArray(oContact.properties)) { _.each(oContact.properties, function (aProperty) { if (aProperty && aProperty[0]) { if (Enums.ContactPropertyType.LastName === aProperty[0]) { sLastName = aProperty[1]; } else if (Enums.ContactPropertyType.FirstName === aProperty[0]) { sFirstName = aProperty[1]; } else { aList.push(new ContactPropertyModel(aProperty[0], aProperty[2] || '', aProperty[1])); } } }); } this.viewTags(oContact.tags); this.viewReadOnly(!!oContact.readOnly); } this.viewTags.focusTrigger.valueHasMutated(); this.viewTags.visibility('' !== this.viewTags()); aList.unshift(new ContactPropertyModel(Enums.ContactPropertyType.LastName, '', sLastName, false, this.getPropertyPlceholder(Enums.ContactPropertyType.LastName))); aList.unshift(new ContactPropertyModel(Enums.ContactPropertyType.FirstName, '', sFirstName, !oContact, this.getPropertyPlceholder(Enums.ContactPropertyType.FirstName))); this.viewID(sId); this.viewProperties([]); this.viewProperties(aList); this.watchDirty(false); this.watchHash(true); };
PluginPopupView.prototype.onShow = function (oPlugin) { this.name(); this.readme(); this.configures([]); if (oPlugin) { this.name(oPlugin['Name']); this.readme(oPlugin['Readme']); var aConfig = oPlugin['Config']; if (Utils.isNonEmptyArray(aConfig)) { this.configures(_.map(aConfig, function (aItem) { return { 'value': ko.observable(aItem[0]), 'Name': aItem[1], 'Type': aItem[2], 'Label': aItem[3], 'Default': aItem[4], 'Desc': aItem[5] }; })); } } };
Remote.contacts(function(sResult, oData) { var iCount = 0, aList = []; if (Enums.StorageResultType.Success === sResult && oData && oData.Result && oData.Result.List) { if (Utils.isNonEmptyArray(oData.Result.List)) { aList = _.map(oData.Result.List, function(oItem) { var oContact = new ContactModel(); return oContact.parse(oItem) ? oContact : null; }); aList = _.compact(aList); iCount = Utils.pInt(oData.Result.Count); iCount = 0 < iCount ? iCount : 0; } } self.contactsCount(iCount); Utils.delegateRunOnDestroy(self.contacts()); self.contacts(aList); self.contacts.loading(false); self.viewClearSearch('' !== self.search()); }, iOffset, Consts.CONTACTS_PER_PAGE, this.search());
'write': function (sNewValue) { var sCurrentValue = ko.unwrap(oTarget), aList = ko.unwrap(mList) ; if (Utils.isNonEmptyArray(aList)) { if (-1 < Utils.inArray(sNewValue, aList)) { oTarget(sNewValue); } else if (-1 < Utils.inArray(sCurrentValue, aList)) { oTarget(sCurrentValue + ' '); oTarget(sCurrentValue); } else { oTarget(aList[0] + ' '); oTarget(aList[0]); } } else { oTarget(''); } }
/** * @param {AjaxJsonMessage} json * @returns {boolean} */ initByJson(json) { let result = false, priority = MessagePriority.Normal; if (json && 'Object/Message' === json['@Object']) { priority = pInt(json.Priority); this.priority(-1 < inArray(priority, [MessagePriority.High, MessagePriority.Low]) ? priority : MessagePriority.Normal); this.folderFullNameRaw = json.Folder; this.uid = json.Uid; this.hash = json.Hash; this.requestHash = json.RequestHash; this.proxy = !!json.ExternalProxy; this.size(pInt(json.Size)); this.from = emailArrayFromJson(json.From); this.to = emailArrayFromJson(json.To); this.cc = emailArrayFromJson(json.Cc); this.bcc = emailArrayFromJson(json.Bcc); this.replyTo = emailArrayFromJson(json.ReplyTo); this.deliveredTo = emailArrayFromJson(json.DeliveredTo); this.unsubsribeLinks = isNonEmptyArray(json.UnsubsribeLinks) ? json.UnsubsribeLinks : []; this.subject(json.Subject); if (isArray(json.SubjectParts)) { this.subjectPrefix(json.SubjectParts[0]); this.subjectSuffix(json.SubjectParts[1]); } else { this.subjectPrefix(''); this.subjectSuffix(this.subject()); } this.dateTimeStampInUTC(pInt(json.DateTimeStampInUTC)); this.hasAttachments(!!json.HasAttachments); this.attachmentsSpecData(isArray(json.AttachmentsSpecData) ? json.AttachmentsSpecData : []); this.fromEmailString(emailArrayToString(this.from, true)); this.fromClearEmailString(emailArrayToStringClear(this.from)); this.toEmailsString(emailArrayToString(this.to, true)); this.toClearEmailsString(emailArrayToStringClear(this.to)); this.threads(isArray(json.Threads) ? json.Threads : []); this.initFlagsByJson(json); this.computeSenderEmail(); result = true; } return result; }
_.each(oData.Result.List, function (oItem) { var aList = [], sHash = Cache.getFolderHash(oItem.Folder), oFolder = Cache.getFolderFromCacheList(oItem.Folder), bUnreadCountChange = false ; if (oFolder) { oFolder.interval = iUtc; if (oItem.Hash) { Cache.setFolderHash(oItem.Folder, oItem.Hash); } if (Utils.isNormal(oItem.MessageCount)) { oFolder.messageCountAll(oItem.MessageCount); } if (Utils.isNormal(oItem.MessageUnseenCount)) { if (Utils.pInt(oFolder.messageCountUnread()) !== Utils.pInt(oItem.MessageUnseenCount)) { bUnreadCountChange = true; } oFolder.messageCountUnread(oItem.MessageUnseenCount); } if (bUnreadCountChange) { Cache.clearMessageFlagsFromCacheByFolder(oFolder.fullNameRaw); } if (oItem.Hash !== sHash || '' === sHash) { if (oFolder.fullNameRaw === FolderStore.currentFolderFullNameRaw()) { self.reloadMessageList(); } } else if (bUnreadCountChange) { if (oFolder.fullNameRaw === FolderStore.currentFolderFullNameRaw()) { aList = MessageStore.messageList(); if (Utils.isNonEmptyArray(aList)) { self.folderInformation(oFolder.fullNameRaw, aList); } } } } });
/** * @returns {string} */ fromDkimData() { let result = ['none', '']; if (isNonEmptyArray(this.from) && 1 === this.from.length && this.from[0] && this.from[0].dkimStatus) { result = [this.from[0].dkimStatus, this.from[0].dkimValue || '']; } return result; }
AttachmentModel.staticCombinedIconClass = function (aData) { var sClass = '', aTypes = [] ; if (Utils.isNonEmptyArray(aData)) { sClass = 'icon-attachment'; aTypes = _.uniq(_.compact(_.map(aData, function (aItem) { return aItem ? AttachmentModel.staticFileType( Utils.getFileExtension(aItem[0]), aItem[1]) : ''; }))); if (aTypes && 1 === aTypes.length && aTypes[0]) { switch (aTypes[0]) { case Enums.FileType.Text: case Enums.FileType.WordText: sClass = 'icon-file-text'; break; case Enums.FileType.Html: case Enums.FileType.Code: sClass = 'icon-file-code'; break; case Enums.FileType.Image: sClass = 'icon-file-image'; break; case Enums.FileType.Audio: sClass = 'icon-file-music'; break; case Enums.FileType.Video: sClass = 'icon-file-movie'; break; case Enums.FileType.Archive: sClass = 'icon-file-zip'; break; case Enums.FileType.Certificate: case Enums.FileType.CertificateBin: sClass = 'icon-file-certificate'; break; case Enums.FileType.Sheet: sClass = 'icon-file-excel'; break; case Enums.FileType.Presentation: sClass = 'icon-file-chart-graph'; break; } } } return sClass; };
Remote.contacts(function (sResult, oData) { var iCount = 0, aList = [], aTagsList = [] ; if (Enums.StorageResultType.Success === sResult && oData && oData.Result && oData.Result.List) { if (Utils.isNonEmptyArray(oData.Result.List)) { aList = _.map(oData.Result.List, function (oItem) { var oContact = new ContactModel(); return oContact.parse(oItem) ? oContact : null; }); aList = _.compact(aList); iCount = Utils.pInt(oData.Result.Count); iCount = 0 < iCount ? iCount : 0; } if (Utils.isNonEmptyArray(oData.Result.Tags)) { aTagsList = _.map(oData.Result.Tags, function (oItem) { var oContactTag = new ContactTagModel(); return oContactTag.parse(oItem) ? oContactTag : null; }); aTagsList = _.compact(aTagsList); } } self.contactsCount(iCount); self.contacts(aList); self.contacts.loading(false); self.contactTags(aTagsList); self.viewClearSearch('' !== self.search()); }, iOffset, Consts.Defaults.ContactsPerPage, this.search());
MessageModel.prototype.fromDkimData = function () { var aResult = ['none', '']; if (Utils.isNonEmptyArray(this.from) && 1 === this.from.length && this.from[0] && this.from[0].dkimStatus) { aResult = [this.from[0].dkimStatus, this.from[0].dkimValue || '']; } return aResult; };
ComposePopupView.prototype.prepearMessageAttachments = function (oMessage, sType) { if (oMessage) { var aAttachments = Utils.isNonEmptyArray(oMessage.attachments()) ? oMessage.attachments() : [], iIndex = 0, iLen = aAttachments.length, oAttachment = null, oItem = null, bAdd = false ; if (Enums.ComposeType.ForwardAsAttachment === sType) { this.addMessageAsAttachment(oMessage); } else { for (; iIndex < iLen; iIndex++) { oItem = aAttachments[iIndex]; bAdd = false; switch (sType) { case Enums.ComposeType.Reply: case Enums.ComposeType.ReplyAll: bAdd = oItem.isLinked; break; case Enums.ComposeType.Forward: case Enums.ComposeType.Draft: case Enums.ComposeType.EditAsNew: bAdd = true; break; } if (bAdd) { oAttachment = new ComposeAttachmentModel( oItem.download, oItem.fileName, oItem.estimatedSize, oItem.isInline, oItem.isLinked, oItem.cid, oItem.contentLocation ); oAttachment.fromMessage = true; oAttachment.cancel = this.cancelAttachmentHelper(oItem.download); oAttachment.waiting(false).uploading(true); this.attachments.push(oAttachment); } } } } };
/** * @param {string} contentLocation * @returns {*} */ findAttachmentByContentLocation(contentLocation) { let result = null; const attachments = this.attachments(); if (isNonEmptyArray(attachments)) { result = _.find(attachments, (item) => contentLocation === item.contentLocation); } return result || null; }
/** * @param {string} cid * @returns {*} */ findAttachmentByCid(cid) { let result = null; const attachments = this.attachments(); if (isNonEmptyArray(attachments)) { cid = cid.replace(/^<+/, '').replace(/>+$/, ''); result = _.find(attachments, (item) => cid === item.cidWithOutTags); } return result || null; }
export const staticCombinedIconClass = (data) => { let result = '', types = []; if (isNonEmptyArray(data)) { result = 'icon-attachment'; types = _.uniq(_.compact(_.map(data, (item) => (item ? staticFileType(getFileExtension(item[0]), item[1]) : '')))); if (types && 1 === types.length && types[0]) { switch (types[0]) { case FileType.Text: case FileType.WordText: result = 'icon-file-text'; break; case FileType.Html: case FileType.Code: result = 'icon-file-code'; break; case FileType.Image: result = 'icon-file-image'; break; case FileType.Audio: result = 'icon-file-music'; break; case FileType.Video: result = 'icon-file-movie'; break; case FileType.Archive: result = 'icon-file-zip'; break; case FileType.Certificate: case FileType.CertificateBin: result = 'icon-file-certificate'; break; case FileType.Sheet: result = 'icon-file-excel'; break; case FileType.Presentation: result = 'icon-file-chart-graph'; break; // no default } } } return result; };
static parseEmailLine(line) { const parsedResult = addressparser(line); if (isNonEmptyArray(parsedResult)) { return _.compact(parsedResult.map( (item) => (item.address ? new EmailModel( item.address.replace(/^[<]+(.*)[>]+$/g, '$1'), item.name || '' ) : null) )); } return []; }
MessageModel.prototype.findAttachmentByContentLocation = function (sContentLocation) { var oResult = null, aAttachments = this.attachments() ; if (Utils.isNonEmptyArray(aAttachments)) { oResult = _.find(aAttachments, function (oAttachment) { return sContentLocation === oAttachment.contentLocation; }); } return oResult || null; };
/** * @constructor * @param {string} iIndex * @param {string} sGuID * @param {string} sID * @param {array} aIDs * @param {array} aUserIDs * @param {array} aEmails * @param {boolean} bIsPrivate * @param {string} sArmor * @param {string} sUserID */ function OpenPgpKeyModel(iIndex, sGuID, sID, aIDs, aUserIDs, aEmails, bIsPrivate, sArmor, sUserID) { AbstractModel.call(this, 'OpenPgpKeyModel'); this.index = iIndex; this.id = sID; this.ids = Utils.isNonEmptyArray(aIDs) ? aIDs : [sID]; this.guid = sGuID; this.users = aUserIDs; this.emails = aEmails; this.armor = sArmor; this.isPrivate = !!bIsPrivate; this.selectUser(sUserID); this.deleteAccess = ko.observable(false); }
MessageModel.prototype.findAttachmentByCid = function (sCid) { var oResult = null, aAttachments = this.attachments() ; if (Utils.isNonEmptyArray(aAttachments)) { sCid = sCid.replace(/^<+/, '').replace(/>+$/, ''); oResult = _.find(aAttachments, function (oAttachment) { return sCid === oAttachment.cidWithOutTags; }); } return oResult || null; };
AppUserStore.prototype.populate = function() { AppStore.prototype.populate.call(this); this.projectHash(Settings.settingsGet('ProjectHash')); this.contactsAutosave(!!Settings.settingsGet('ContactsAutosave')); this.useLocalProxyForExternalImages(!!Settings.settingsGet('UseLocalProxyForExternalImages')); this.contactsIsAllowed(!!Settings.settingsGet('ContactsIsAllowed')); var mAttachmentsActions = Settings.settingsGet('AttachmentsActions'); this.attachmentsActions(Utils.isNonEmptyArray(mAttachmentsActions) ? mAttachmentsActions : []); this.devEmail = Settings.settingsGet('DevEmail'); this.devPassword = Settings.settingsGet('DevPassword'); };
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(', '); };
this.viewFromDkimStatusTitle = ko.computed(function () { var aStatus = this.viewFromDkimData(); if (Utils.isNonEmptyArray(aStatus)) { if (aStatus[0] && aStatus[1]) { return aStatus[1]; } else if (aStatus[0]) { return 'DKIM: ' + aStatus[0]; } } return ''; }, this);
PgpUserStore.prototype.findPrivateKeysByEncryptionKeyIds = function (aEncryptionKeyIds, aRecipients, bReturnWrapKeys) { var self = this, aResult = []; aResult = Utils.isArray(aEncryptionKeyIds) ? _.compact(_.flatten(_.map(aEncryptionKeyIds, function (oId) { var oKey = oId && oId.toHex ? self.findPrivateKeyByHex(oId.toHex()) : null; return oKey ? (bReturnWrapKeys ? [oKey] : oKey.getNativeKeys()) : [null]; }), true)) : []; if (0 === aResult.length && Utils.isNonEmptyArray(aRecipients)) { aResult = _.uniq(_.compact(_.flatten(_.map(aRecipients, function (sEmail) { var aKeys = sEmail ? self.findAllPrivateKeysByEmailNotNative(sEmail) : null; return aKeys ? (bReturnWrapKeys ? aKeys : _.flatten(_.map(aKeys, function (oKey) { return oKey.getNativeKeys(); }), true)) : [null]; }), true)), function (oKey) { return oKey.id; }); } return aResult; };
/** * @param {string} emailAddress * @returns {boolean} */ parse(emailAddress) { emailAddress = trim(emailAddress); if ('' === emailAddress) { return false; } const result = addressparser(emailAddress); if (isNonEmptyArray(result) && result[0]) { this.name = result[0].name || ''; this.email = result[0].address || ''; this.clearDuplicateName(); return true; } return false; }
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(', '); };
self.verifyMessage(oMessage, function (oValidKey, aSigningKeyIds) { if (oValidKey) { self.controlsHelper(mDom, oVerControl, true, Translator.i18n('PGP_NOTIFICATIONS/GOOD_SIGNATURE', { 'USER': oValidKey.user + ' (' + oValidKey.id + ')' }), oMessage.getText()); } else { var aKeyIds = Utils.isNonEmptyArray(aSigningKeyIds) ? aSigningKeyIds : null, sAdditional = aKeyIds ? _.compact(_.map(aKeyIds, function (oItem) { return oItem && oItem.toHex ? oItem.toHex() : null; })).join(', ') : '' ; self.controlsHelper(mDom, oVerControl, false, Translator.i18n('PGP_NOTIFICATIONS/UNVERIFIRED_SIGNATURE') + (sAdditional ? ' (' + sAdditional + ')' : '')); } });
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 splitEmailLine(line) { const parsedResult = addressparser(line); if (isNonEmptyArray(parsedResult)) { const result = []; let exists = false; parsedResult.forEach((item) => { const address = item.address ? new EmailModel( item.address.replace(/^[<]+(.*)[>]+$/g, '$1'), item.name || '' ) : null; if (address && address.email) { exists = true; } result.push(address ? address.toLine(false) : item.name); }); return exists ? result : null; } return null; }