diff --git a/dev/App/User.js b/dev/App/User.js index d8ac6a6f9..b46f9a23e 100644 --- a/dev/App/User.js +++ b/dev/App/User.js @@ -18,7 +18,6 @@ import { import { doc, elementById, - createElement, $htmlCL, Settings, SettingsGet, @@ -546,23 +545,6 @@ class AppUser extends AbstractApp { }, query); } - /** - * @param {string} link - * @returns {boolean} - */ - download(link) { - if (ThemeStore.isMobile()) { - open(link, '_self'); - focus(); - } else { - const oLink = createElement('a'); - oLink.href = link; - doc.body.appendChild(oLink).click(); - oLink.remove(); - } - return true; - } - logout() { Remote.request('Logout', () => rl.logoutReload()); } diff --git a/dev/Common/UtilsUser.js b/dev/Common/UtilsUser.js index bbc4b28a3..492f3cb07 100644 --- a/dev/Common/UtilsUser.js +++ b/dev/Common/UtilsUser.js @@ -1,11 +1,12 @@ import { ComposeType/*, FolderType*/ } from 'Common/EnumsUser'; import { EmailModel } from 'Model/Email'; import { isArray } from 'Common/Utils'; -import { createElement } from 'Common/Globals'; +import { doc, createElement } from 'Common/Globals'; import { FolderUserStore } from 'Stores/User/Folder'; import { SettingsUserStore } from 'Stores/User/Settings'; import * as Local from 'Storage/Client'; import { plainToHtml } from 'Common/Html'; +import { ThemeStore } from 'Stores/Theme'; export const @@ -20,6 +21,24 @@ sortFolders = folders => { } }, +/** + * @param {string} link + * @returns {boolean} + */ +download = (link, name = "") => { + if (ThemeStore.isMobile()) { + open(link, '_self'); + focus(); + } else { + const oLink = createElement('a'); + oLink.href = link; + oLink.target = '_blank'; + oLink.download = name; + doc.body.appendChild(oLink).click(); + oLink.remove(); + } +}, + /** * @param {Array=} aDisabled * @param {Array=} aHeaderLines diff --git a/dev/Model/Attachment.js b/dev/Model/Attachment.js index db264acee..dc777a24f 100644 --- a/dev/Model/Attachment.js +++ b/dev/Model/Attachment.js @@ -21,7 +21,6 @@ export class AttachmentModel extends AbstractModel { this.fileNameExt = ''; this.fileType = FileType.Unknown; this.friendlySize = ''; - this.isInline = false; this.isLinked = false; this.isThumbnail = false; this.cid = ''; @@ -29,8 +28,13 @@ export class AttachmentModel extends AbstractModel { this.download = ''; this.folder = ''; this.uid = ''; + this.url = ''; this.mimeIndex = ''; this.framed = false; + + this.addObservables({ + isInline: false + }); } /** @@ -124,14 +128,14 @@ export class AttachmentModel extends AbstractModel { * @returns {string} */ linkDownload() { - return attachmentDownload(this.download); + return this.url || attachmentDownload(this.download); } /** * @returns {string} */ linkPreview() { - return serverRequestRaw('View', this.download); + return this.url || serverRequestRaw('View', this.download); } /** diff --git a/dev/View/Popup/Contacts.js b/dev/View/Popup/Contacts.js index b2f5807ec..e80fc8f4e 100644 --- a/dev/View/Popup/Contacts.js +++ b/dev/View/Popup/Contacts.js @@ -8,7 +8,7 @@ import { import { ComposeType } from 'Common/EnumsUser'; import { arrayLength, pInt } from 'Common/Utils'; -import { delegateRunOnDestroy, computedPaginatorHelper, showMessageComposer } from 'Common/UtilsUser'; +import { download, delegateRunOnDestroy, computedPaginatorHelper, showMessageComposer } from 'Common/UtilsUser'; import { Selector } from 'Common/Selector'; import { serverRequestRaw, serverRequest } from 'Common/Links'; @@ -317,11 +317,11 @@ class ContactsPopupView extends AbstractViewPopup { } exportVcf() { - rl.app.download(serverRequestRaw('ContactsVcf')); + download(serverRequestRaw('ContactsVcf'), 'contacts.vcf'); } exportCsv() { - rl.app.download(serverRequestRaw('ContactsCsv')); + download(serverRequestRaw('ContactsCsv'), 'contacts.csv'); } removeCheckedOrSelectedContactsFromList() { diff --git a/dev/View/User/MailBox/MessageView.js b/dev/View/User/MailBox/MessageView.js index d9ca5dd81..f03dad77b 100644 --- a/dev/View/User/MailBox/MessageView.js +++ b/dev/View/User/MailBox/MessageView.js @@ -27,7 +27,7 @@ import { } from 'Common/Globals'; import { arrayLength, inFocus } from 'Common/Utils'; -import { mailToHelper, showMessageComposer, initFullscreen } from 'Common/UtilsUser'; +import { download, mailToHelper, showMessageComposer, initFullscreen } from 'Common/UtilsUser'; import { SMAudio } from 'Common/Audio'; @@ -95,7 +95,7 @@ const attachment.cid = cid ? cid.value : ''; if (cid && html) { let cid = 'cid:' + attachment.contentId(); - attachment.isInline = html.includes(cid); + attachment.isInline(html.includes(cid)); html = html .replace('src="' + cid + '"', 'src="' + attachment.url + '"') .replace("src='" + cid + "'", "src='" + attachment.url + "'"); @@ -379,7 +379,7 @@ export class MailMessageView extends AbstractViewRight { el = eqs(event, '.attachmentsPlace .attachmentItem .attachmentNameParent'); if (el) { const attachment = ko.dataFor(el); - attachment && attachment.download && rl.app.download(attachment.linkDownload()); + attachment && attachment.linkDownload() && download(attachment.linkDownload(), attachment.fileName); } if (eqs(event, '.messageItemHeader .subjectParent .flagParent')) { @@ -587,8 +587,9 @@ export class MailMessageView extends AbstractViewRight { if (hashes.length) { Remote.attachmentsActions('Zip', hashes, this.downloadAsZipLoading) .then(result => { - if (result && result.Result && result.Result.FileHash) { - rl.app.download(attachmentDownload(result.Result.FileHash)); + let hash = result && result.Result && result.Result.FileHash; + if (hash) { + download(attachmentDownload(hash), hash+'.zip'); } else { this.downloadAsZipError(true); }