').parent().html() : ''; }; /** * Parses attachments. * * @param {object} oData * @param {number} iAccountId */ CMessageModel.prototype.parseAttachments = function (oData, iAccountId) { var aCollection = oData ? oData['@Collection'] : []; this.attachments([]); if (Types.isNonEmptyArray(aCollection)) { this.attachments(_.map(aCollection, function (oRawAttach) { var oAttachment = new CAttachmentModel(iAccountId); oAttachment.setMessageData(this.folder(), this.uid()); oAttachment.parse(oRawAttach, this.folder(), this.longUid()); return oAttachment; }, this)); } }; /** * Parses an array of email addresses. * * @param {Array} aData * @return {Array} */ CMessageModel.prototype.parseAddressArray = function (aData) { var aAddresses = [] ; if (_.isArray(aData)) { aAddresses = _.map(aData, function (oRawAddress) { var oAddress = new CAddressModel(); oAddress.parse(oRawAddress); return oAddress; }); } return aAddresses; }; /** * Displays embedded images, which have cid on the list. * * @param {string} sAppPath */ CMessageModel.prototype.showInlinePictures = function (sAppPath) { var aAttachments = _.map(this.attachments(), function (oAttachment) { return { CID: oAttachment.cid(), ContentLocation: oAttachment.contentLocation(), ViewLink: oAttachment.getActionUrl('view') }; }); MessageUtils.showInlinePictures(this.$text, aAttachments, this.foundCids(), sAppPath); }; /** * Displays external images. */ CMessageModel.prototype.showExternalPictures = function () { MessageUtils.showExternalPictures(this.$text); this.isExternalsShown(true); }; /** * Sets a flag that external images are always displayed. * @param {boolean} bForcedShowPictures */ CMessageModel.prototype.alwaysShowExternalPicturesForSender = function (bForcedShowPictures = false) { this.isExternalsAlwaysShown(true); if (this.completelyFilled() && (bForcedShowPictures || !this.isExternalsShown())) { this.showExternalPictures(); } }; CMessageModel.prototype.openThread = function () { if (this.threadCountVisible()) { var sFolder = this.folder(); this.threadOpened(!this.threadOpened()); this.requireMailCache(); if (this.threadOpened()) { MailCache.showOpenedThreads(sFolder); } else { MailCache.hideThreads(this); setTimeout(function () { MailCache.showOpenedThreads(sFolder); }, 500); } } }; /** * @param {Object} oResponse * @param {Object} oRequest */ CMessageModel.prototype.onSaveAttachmentsToFilesResponse = function (oResponse, oRequest) { var oParameters = oRequest.Parameters, iSavedCount = 0, iTotalCount = oParameters.Attachments.length ; if (oResponse.Result) { _.each(oParameters.Attachments, function (sHash) { if (oResponse.Result[sHash] !== undefined) { iSavedCount++; } }); } if (iSavedCount === 0) { Screens.showError(TextUtils.i18n('%MODULENAME%/ERROR_CANT_SAVE_ATTACHMENTS_TO_FILES')); } else if (iSavedCount < iTotalCount) { Screens.showError(TextUtils.i18n('%MODULENAME%/ERROR_SOME_ATTACHMENTS_WERE_NOT_SAVED', { 'SAVED_COUNT': iSavedCount, 'TOTAL_COUNT': iTotalCount })); } else { Screens.showReport(TextUtils.i18n('%MODULENAME%/REPORT_ATTACHMENTS_SAVED_TO_FILES')); } }; CMessageModel.prototype.downloadAllAttachmentsSeparately = function () { _.each(this.attachments(), function (oAttach) { if (!oAttach.linked()) { oAttach.executeAction('download'); } }); }; /** * Uses for logging. * * @returns {Object} */ CMessageModel.prototype.toJSON = function () { return { uid: this.uid(), longUid: this.longUid(), accountId: this.accountId(), to: this.to(), subject: this.subject(), threadPart: this.threadPart(), threadUids: this.threadUids(), threadOpened: this.threadOpened() }; }; CMessageModel.prototype.getHeaderValue = function (sHeaderName) { var reg = new RegExp(sHeaderName + ':\s*(.+)(\n|$)', 'gm'), aResult = reg.exec(this.sourceHeaders()) ; return $.trim(Types.pString(aResult && aResult[1])); }; module.exports = CMessageModel;