snappymail/dev/View/Popup/Compose.js

1484 lines
38 KiB
JavaScript
Raw Normal View History

import ko from 'ko';
import {
Scope,
2019-07-05 03:19:24 +08:00
Notification,
UploadErrorCode
} from 'Common/Enums';
2021-01-25 05:58:06 +08:00
import {
ComposeType,
EditorDefaultType,
SetSystemFoldersNotification
} from 'Common/EnumsUser';
2021-07-22 03:34:17 +08:00
import { inFocus, pInt, isArray, arrayLength } from 'Common/Utils';
import { delegateRunOnDestroy } from 'Common/UtilsUser';
import { encodeHtml, HtmlEditor } from 'Common/Html';
2019-07-05 03:19:24 +08:00
import { UNUSED_OPTION_VALUE } from 'Common/Consts';
2021-02-04 18:25:00 +08:00
import { serverRequest } from 'Common/Links';
2019-07-05 03:19:24 +08:00
import { i18n, getNotification, getUploadErrorDescByCode } from 'Common/Translator';
import { timestampToString } from 'Common/Momentor';
import { MessageFlagsCache, setFolderHash } from 'Common/Cache';
import { doc, Settings, SettingsGet } from 'Common/Globals';
import { AppUserStore } from 'Stores/User/App';
import { SettingsUserStore } from 'Stores/User/Settings';
import { IdentityUserStore } from 'Stores/User/Identity';
import { AccountUserStore } from 'Stores/User/Account';
import { FolderUserStore } from 'Stores/User/Folder';
import { PgpUserStore } from 'Stores/User/Pgp';
import { MessageUserStore } from 'Stores/User/Message';
import Remote from 'Remote/User/Fetch';
2019-07-05 03:19:24 +08:00
import { ComposeAttachmentModel } from 'Model/ComposeAttachment';
import { decorateKoCommands, isPopupVisible, showScreenPopup, hideScreenPopup } from 'Knoin/Knoin';
import { AbstractViewPopup } from 'Knoin/AbstractViews';
import { FolderSystemPopupView } from 'View/Popup/FolderSystem';
import { AskPopupView } from 'View/Popup/Ask';
import { ContactsPopupView } from 'View/Popup/Contacts';
import { ComposeOpenPgpPopupView } from 'View/Popup/ComposeOpenPgp';
import { ThemeStore } from 'Stores/Theme';
const
/**
* @param {string} prefix
* @param {string} subject
* @returns {string}
*/
replySubjectAdd = (prefix, subject) => {
prefix = prefix.toUpperCase().trim();
subject = subject.replace(/\s+/g, ' ').trim();
let drop = false,
re = 'RE' === prefix,
fwd = 'FWD' === prefix;
const parts = [],
prefixIsRe = !fwd;
if (subject) {
subject.split(':').forEach(part => {
const trimmedPart = part.trim();
if (!drop && (/^(RE|FWD)$/i.test(trimmedPart) || /^(RE|FWD)[[(][\d]+[\])]$/i.test(trimmedPart))) {
if (!re) {
re = !!/^RE/i.test(trimmedPart);
}
if (!fwd) {
fwd = !!/^FWD/i.test(trimmedPart);
}
} else {
parts.push(part);
drop = true;
}
});
}
if (prefixIsRe) {
re = false;
} else {
fwd = false;
}
return ((prefixIsRe ? 'Re: ' : 'Fwd: ') + (re ? 'Re: ' : '')
+ (fwd ? 'Fwd: ' : '') + parts.join(':').trim()).trim();
};
ko.extenders.toggleSubscribe = (target, options) => {
target.subscribe(options[1], options[0], 'beforeChange');
target.subscribe(options[2], options[0]);
return target;
};
class ComposePopupView extends AbstractViewPopup {
constructor() {
super('Compose');
2014-08-21 23:08:34 +08:00
2019-07-05 03:19:24 +08:00
const fEmailOutInHelper = (context, identity, name, isIn) => {
if (identity && context && identity[name]() && (isIn ? true : context[name]())) {
const identityEmail = identity[name]();
let list = context[name]().trim().split(',');
list = list.filter(email => {
email = email.trim();
return email && identityEmail.trim() !== email;
2019-07-05 03:19:24 +08:00
});
2019-07-05 03:19:24 +08:00
if (isIn) {
list.push(identityEmail);
}
2019-07-05 03:19:24 +08:00
context[name](list.join(','));
}
};
this.oLastMessage = null;
this.oEditor = null;
this.aDraftInfo = null;
this.sInReplyTo = '';
this.bFromDraft = false;
this.sReferences = '';
2014-03-20 06:39:36 +08:00
this.sLastFocusedField = 'to';
2015-02-16 05:55:59 +08:00
this.allowContacts = AppUserStore.allowContacts();
this.bSkipNextHide = false;
2014-12-28 03:48:55 +08:00
this.capaOpenPGP = PgpUserStore.capaOpenPGP;
this.identities = IdentityUserStore;
2014-01-04 08:20:07 +08:00
this.addObservables({
identitiesDropdownTrigger: false,
2015-02-16 05:55:59 +08:00
to: '',
cc: '',
bcc: '',
replyTo: '',
2017-09-28 01:58:15 +08:00
subject: '',
isHtml: false,
requestDsn: false,
requestReadReceipt: false,
markAsImportant: false,
sendError: false,
sendSuccessButSaveError: false,
savedError: false,
sendErrorDesc: '',
savedErrorDesc: '',
savedTime: 0,
emptyToError: false,
2016-04-29 04:32:54 +08:00
attachmentsInProcessError: false,
attachmentsInErrorError: false,
2015-04-07 03:32:19 +08:00
showCc: false,
showBcc: false,
showReplyTo: false,
2015-04-07 03:32:19 +08:00
draftFolder: '',
draftUid: '',
sending: false,
saving: false,
2015-04-07 03:32:19 +08:00
attachmentsPlace: false,
2015-04-07 03:32:19 +08:00
composeUploaderButton: null,
composeUploaderDropPlace: null,
attacheMultipleAllowed: false,
addAttachmentEnabled: false,
// div.textAreaParent
composeEditorArea: null,
2015-04-07 03:32:19 +08:00
currentIdentity: this.identities()[0] ? this.identities()[0] : null
});
// this.to.subscribe((v) => console.log(v));
2013-12-13 07:23:47 +08:00
// Used by ko.bindingHandlers.emailsTags
this.to.focused = ko.observable(false);
this.to.focused.subscribe(value => value && (this.sLastFocusedField = 'to'));
this.cc.focused = ko.observable(false);
this.cc.focused.subscribe(value => value && (this.sLastFocusedField = 'cc'));
this.bcc.focused = ko.observable(false);
this.bcc.focused.subscribe(value => value && (this.sLastFocusedField = 'bcc'));
this.attachments = ko.observableArray();
this.dragAndDropOver = ko.observable(false).extend({ debounce: 1 });
this.dragAndDropVisible = ko.observable(false).extend({ debounce: 1 });
2019-07-05 03:19:24 +08:00
this.currentIdentity.extend({
toggleSubscribe: [
this,
(identity) => {
fEmailOutInHelper(this, identity, 'bcc');
fEmailOutInHelper(this, identity, 'replyTo');
},
(identity) => {
fEmailOutInHelper(this, identity, 'bcc', true);
fEmailOutInHelper(this, identity, 'replyTo', true);
}
]
});
this.bDisabeCloseOnEsc = true;
this.tryToClosePopup = this.tryToClosePopup.debounce(200);
this.iTimer = 0;
this.addComputables({
sendButtonSuccess: () => !this.sendError() && !this.sendSuccessButSaveError(),
savedTimeText: () =>
this.savedTime() ? i18n('COMPOSE/SAVED_TIME', { TIME: this.savedTime().format('LT') }) : '',
emptyToErrorTooltip: () => (this.emptyToError() ? i18n('COMPOSE/EMPTY_TO_ERROR_DESC') : ''),
attachmentsErrorTooltip: () => {
let result = '';
switch (true) {
case this.attachmentsInProcessError():
result = i18n('COMPOSE/ATTACHMENTS_UPLOAD_ERROR_DESC');
break;
case this.attachmentsInErrorError():
result = i18n('COMPOSE/ATTACHMENTS_ERROR_DESC');
break;
// no default
}
return result;
},
attachmentsInProcess: () => this.attachments.filter(item => item && !item.complete()),
attachmentsInError: () => this.attachments.filter(item => item && item.error()),
attachmentsCount: () => this.attachments.length,
attachmentsInErrorCount: () => this.attachmentsInError.length,
attachmentsInProcessCount: () => this.attachmentsInProcess.length,
isDraftFolderMessage: () => this.draftFolder() && this.draftUid(),
identitiesOptions: () =>
IdentityUserStore.map(item => ({
item: item,
optValue: item.id(),
optText: item.formattedName()
})),
currentIdentityView: () => {
const item = this.currentIdentity();
return item ? item.formattedName() : 'unknown';
},
canBeSentOrSaved: () => !this.sending() && !this.saving()
});
this.addSubscribables({
sendError: value => !value && this.sendErrorDesc(''),
savedError: value => !value && this.savedErrorDesc(''),
sendSuccessButSaveError: value => !value && this.savedErrorDesc(''),
cc: value => {
if (false === this.showCc() && value.length) {
this.showCc(true);
}
},
bcc: value => {
if (false === this.showBcc() && value.length) {
this.showBcc(true);
}
},
replyTo: value => {
if (false === this.showReplyTo() && value.length) {
this.showReplyTo(true);
}
},
attachmentsInErrorCount: value => {
if (0 === value) {
this.attachmentsInErrorError(false);
}
},
to: value => {
if (this.emptyToError() && value.length) {
this.emptyToError(false);
}
},
attachmentsInProcess: value => {
2021-07-22 03:34:17 +08:00
if (this.attachmentsInProcessError() && arrayLength(value)) {
this.attachmentsInProcessError(false);
}
}
2016-06-30 08:02:45 +08:00
});
this.resizeObserver = new ResizeObserver(this.resizerTrigger.throttle(50).bind(this));
decorateKoCommands(this, {
sendCommand: self => self.canBeSentOrSaved(),
saveCommand: self => self.canBeSentOrSaved(),
deleteCommand: self => self.isDraftFolderMessage(),
skipCommand: self => self.canBeSentOrSaved(),
contactsCommand: self => self.allowContacts
});
2016-09-10 06:38:16 +08:00
}
getMessageRequestParams(sSaveFolder)
{
let TextIsHtml = this.oEditor.isHtml() ? 1 : 0,
Text = this.oEditor.getData(true);
if (TextIsHtml) {
let l;
do {
l = Text.length;
Text = Text
// Remove Microsoft Office styling
.replace(/(<[^>]+[;"'])\s*mso-[a-z-]+\s*:[^;"']+/gi, '$1')
// Remove hubspot data-hs- attributes
.replace(/(<[^>]+)\s+data-hs-[a-z-]+=("[^"]+"|'[^']+')/gi, '$1');
} while (l != Text.length)
}
return {
IdentityID: this.currentIdentity() ? this.currentIdentity().id() : '',
MessageFolder: this.draftFolder(),
MessageUid: this.draftUid(),
SaveFolder: sSaveFolder,
To: this.to(),
Cc: this.cc(),
Bcc: this.bcc(),
ReplyTo: this.replyTo(),
Subject: this.subject(),
TextIsHtml: TextIsHtml,
Text: Text,
DraftInfo: this.aDraftInfo,
InReplyTo: this.sInReplyTo,
References: this.sReferences,
MarkAsImportant: this.markAsImportant() ? 1 : 0,
Attachments: this.prepearAttachmentsForSendOrSave(),
// Only used at send, not at save:
Dsn: this.requestDsn() ? 1 : 0,
ReadReceiptRequest: this.requestReadReceipt() ? 1 : 0
};
}
2016-09-10 06:38:16 +08:00
sendCommand() {
let sSentFolder = FolderUserStore.sentFolder();
2015-04-10 16:17:49 +08:00
2016-09-10 06:38:16 +08:00
this.attachmentsInProcessError(false);
this.attachmentsInErrorError(false);
this.emptyToError(false);
if (this.attachmentsInProcess().length) {
2016-09-10 06:38:16 +08:00
this.attachmentsInProcessError(true);
this.attachmentsPlace(true);
} else if (this.attachmentsInError().length) {
2016-09-10 06:38:16 +08:00
this.attachmentsInErrorError(true);
this.attachmentsPlace(true);
}
2016-06-30 08:02:45 +08:00
if (!this.to().trim() && !this.cc().trim() && !this.bcc().trim()) {
2016-09-10 06:38:16 +08:00
this.emptyToError(true);
}
2019-07-05 03:19:24 +08:00
if (!this.emptyToError() && !this.attachmentsInErrorError() && !this.attachmentsInProcessError()) {
if (SettingsUserStore.replySameFolder()) {
2019-07-05 03:19:24 +08:00
if (
2021-07-22 03:34:17 +08:00
3 === arrayLength(this.aDraftInfo) &&
null != this.aDraftInfo[2] &&
this.aDraftInfo[2].length
2019-07-05 03:19:24 +08:00
) {
2016-09-10 06:38:16 +08:00
sSentFolder = this.aDraftInfo[2];
}
}
if (!sSentFolder) {
showScreenPopup(FolderSystemPopupView, [SetSystemFoldersNotification.Sent]);
2019-07-05 03:19:24 +08:00
} else {
2016-09-10 06:38:16 +08:00
this.sendError(false);
this.sending(true);
2014-08-21 23:08:34 +08:00
2021-07-22 03:34:17 +08:00
if (3 === arrayLength(this.aDraftInfo)) {
const flagsCache = MessageFlagsCache.getFor(this.aDraftInfo[2], this.aDraftInfo[1]);
2019-07-05 03:19:24 +08:00
if (flagsCache) {
if ('forward' === this.aDraftInfo[0]) {
2016-09-10 06:38:16 +08:00
flagsCache[3] = true;
2019-07-05 03:19:24 +08:00
} else {
2016-09-10 06:38:16 +08:00
flagsCache[2] = true;
}
MessageFlagsCache.setFor(this.aDraftInfo[2], this.aDraftInfo[1], flagsCache);
2020-09-15 15:29:25 +08:00
rl.app.reloadFlagsCurrentMessageListAndMessageFromCache();
2016-09-10 06:38:16 +08:00
setFolderHash(this.aDraftInfo[2], '');
}
}
sSentFolder = UNUSED_OPTION_VALUE === sSentFolder ? '' : sSentFolder;
2016-09-10 06:38:16 +08:00
setFolderHash(this.draftFolder(), '');
setFolderHash(sSentFolder, '');
Remote.sendMessage(
2021-04-23 16:47:24 +08:00
(iError, data) => {
this.sending(false);
if (this.modalVisibility()) {
if (iError) {
if (Notification.CantSaveMessage === iError) {
this.sendSuccessButSaveError(true);
this.savedErrorDesc(i18n('COMPOSE/SAVED_ERROR_ON_SEND').trim());
} else {
this.sendError(true);
this.sendErrorDesc(getNotification(iError, data && data.ErrorMessage)
|| getNotification(Notification.CantSendMessage));
}
} else {
this.closeCommand();
2021-04-23 16:47:24 +08:00
}
}
this.reloadDraftFolder();
},
this.getMessageRequestParams(sSentFolder)
);
}
2016-09-10 06:38:16 +08:00
}
}
2016-09-10 06:38:16 +08:00
saveCommand() {
if (FolderUserStore.draftFolderNotEnabled()) {
showScreenPopup(FolderSystemPopupView, [SetSystemFoldersNotification.Draft]);
2019-07-05 03:19:24 +08:00
} else {
2016-09-10 06:38:16 +08:00
this.savedError(false);
this.saving(true);
2014-07-10 22:44:45 +08:00
2016-09-10 06:38:16 +08:00
this.autosaveStart();
2014-12-28 03:48:55 +08:00
setFolderHash(FolderUserStore.draftFolder(), '');
2014-08-22 23:08:56 +08:00
2016-09-10 06:38:16 +08:00
Remote.saveMessage(
2021-04-23 16:47:24 +08:00
(iError, oData) => {
let result = false;
this.saving(false);
if (!iError) {
if (oData.Result.NewFolder && oData.Result.NewUid) {
result = true;
if (this.bFromDraft) {
const message = MessageUserStore.message();
if (message && this.draftFolder() === message.folder && this.draftUid() === message.uid) {
MessageUserStore.message(null);
}
}
this.draftFolder(oData.Result.NewFolder);
this.draftUid(oData.Result.NewUid);
this.savedTime(new Date);
if (this.bFromDraft) {
setFolderHash(this.draftFolder(), '');
}
}
}
if (!result) {
this.savedError(true);
this.savedErrorDesc(getNotification(Notification.CantSaveMessage));
}
this.reloadDraftFolder();
},
this.getMessageRequestParams(FolderUserStore.draftFolder())
2016-09-10 06:38:16 +08:00
);
}
2016-09-10 06:38:16 +08:00
return true;
}
2016-09-10 06:38:16 +08:00
deleteCommand() {
if (!isPopupVisible(AskPopupView) && this.modalVisibility()) {
showScreenPopup(AskPopupView, [
2019-07-05 03:19:24 +08:00
i18n('POPUPS_ASK/DESC_WANT_DELETE_MESSAGES'),
() => {
if (this.modalVisibility()) {
2020-09-15 15:29:25 +08:00
rl.app.deleteMessagesFromFolderWithoutCheck(this.draftFolder(), [this.draftUid()]);
2019-07-05 03:19:24 +08:00
hideScreenPopup(ComposePopupView);
}
2016-09-10 06:38:16 +08:00
}
2019-07-05 03:19:24 +08:00
]);
2016-09-10 06:38:16 +08:00
}
}
2014-12-28 03:48:55 +08:00
2016-09-10 06:38:16 +08:00
skipCommand() {
this.bSkipNextHide = true;
2016-06-30 08:02:45 +08:00
2019-07-05 03:19:24 +08:00
if (
this.modalVisibility() &&
!this.saving() &&
!this.sending() &&
!FolderUserStore.draftFolderNotEnabled() &&
SettingsUserStore.allowDraftAutosave()
2019-07-05 03:19:24 +08:00
) {
2016-09-10 06:38:16 +08:00
this.saveCommand();
}
2016-06-30 08:02:45 +08:00
2016-09-10 06:38:16 +08:00
this.tryToClosePopup();
}
2016-06-30 08:02:45 +08:00
2016-09-10 06:38:16 +08:00
contactsCommand() {
2019-07-05 03:19:24 +08:00
if (this.allowContacts) {
2016-09-10 06:38:16 +08:00
this.skipCommand();
setTimeout(() => {
showScreenPopup(ContactsPopupView, [true, this.sLastFocusedField]);
2020-08-14 04:58:41 +08:00
}, 200);
2016-09-10 06:38:16 +08:00
}
}
2014-12-28 03:48:55 +08:00
autosaveStart() {
clearTimeout(this.iTimer);
this.iTimer = setTimeout(()=>{
if (this.modalVisibility()
&& !FolderUserStore.draftFolderNotEnabled()
&& SettingsUserStore.allowDraftAutosave()
&& !this.isEmptyForm(false)
&& !this.saving()
&& !this.sending()
&& !this.savedError()
) {
this.saveCommand();
}
2016-06-30 08:02:45 +08:00
this.autosaveStart();
}, 60000);
2016-06-30 08:02:45 +08:00
}
2014-08-22 23:08:56 +08:00
emailsSource(oData, fResponse) {
2020-09-15 15:29:25 +08:00
rl.app.getAutocomplete(oData.term, aData => fResponse(aData.map(oEmailItem => oEmailItem.toLine(false))));
}
2016-06-30 08:02:45 +08:00
openOpenPgpPopup() {
if (PgpUserStore.capaOpenPGP() && !this.oEditor.isHtml()) {
showScreenPopup(ComposeOpenPgpPopupView, [
result => this.editor(editor => editor.setPlain(result)),
this.oEditor.getData(false),
this.currentIdentity(),
this.to(),
this.cc(),
this.bcc()
]);
2014-08-21 23:08:34 +08:00
}
}
reloadDraftFolder() {
const draftFolder = FolderUserStore.draftFolder();
if (draftFolder && UNUSED_OPTION_VALUE !== draftFolder) {
setFolderHash(draftFolder, '');
if (FolderUserStore.currentFolderFullNameRaw() === draftFolder) {
2020-09-15 15:29:25 +08:00
rl.app.reloadMessageList(true);
2019-07-05 03:19:24 +08:00
} else {
2020-09-15 15:29:25 +08:00
rl.app.folderInformation(draftFolder);
}
2014-03-20 00:18:28 +08:00
}
2016-06-30 08:02:45 +08:00
}
2014-08-21 23:08:34 +08:00
findIdentityByMessage(composeType, message) {
2019-07-05 03:19:24 +08:00
let resultIndex = 1000,
resultIdentity = null;
const identities = IdentityUserStore(),
identitiesCache = {},
fEachHelper = (item) => {
2019-07-05 03:19:24 +08:00
if (item && item.email && identitiesCache[item.email]) {
if (!resultIdentity || resultIndex > identitiesCache[item.email][1]) {
resultIdentity = identitiesCache[item.email][0];
resultIndex = identitiesCache[item.email][1];
}
2014-08-21 23:08:34 +08:00
}
};
2014-08-21 23:08:34 +08:00
identities.forEach((item, index) => identitiesCache[item.email()] = [item, index]);
2014-08-21 23:08:34 +08:00
2019-07-05 03:19:24 +08:00
if (message) {
switch (composeType) {
case ComposeType.Empty:
break;
case ComposeType.Reply:
case ComposeType.ReplyAll:
case ComposeType.Forward:
case ComposeType.ForwardAsAttachment:
message.to.concat(message.cc, message.bcc).forEach(fEachHelper);
if (!resultIdentity) {
message.deliveredTo.forEach(fEachHelper);
}
break;
case ComposeType.Draft:
message.from.concat(message.replyTo).forEach(fEachHelper);
break;
// no default
}
2014-08-21 23:08:34 +08:00
}
return resultIdentity || identities[0] || null;
}
selectIdentity(identity) {
2019-07-05 03:19:24 +08:00
if (identity && identity.item) {
this.currentIdentity(identity.item);
this.setSignatureFromIdentity(identity.item);
}
2016-06-30 08:02:45 +08:00
}
2014-08-21 23:08:34 +08:00
onHide() {
// Stop autosave
clearTimeout(this.iTimer);
2014-12-28 03:48:55 +08:00
AppUserStore.composeInEdit(this.bSkipNextHide);
this.bSkipNextHide || this.reset();
2014-12-28 03:48:55 +08:00
this.bSkipNextHide = false;
2014-12-28 03:48:55 +08:00
this.to.focused(false);
2015-03-21 06:22:06 +08:00
rl.route.on();
this.resizeObserver.disconnect();
(doc.fullscreenElement || doc.webkitFullscreenElement) === this.oContent && doc.exitFullscreen();
}
2014-08-21 23:08:34 +08:00
editor(fOnInit) {
if (fOnInit && this.composeEditorArea()) {
if (this.oEditor) {
fOnInit(this.oEditor);
} else {
// setTimeout(() => {
2019-07-05 03:19:24 +08:00
this.oEditor = new HtmlEditor(
this.composeEditorArea(),
null,
() => fOnInit(this.oEditor),
bHtml => this.isHtml(!!bHtml)
2019-07-05 03:19:24 +08:00
);
// }, 1000);
}
2016-06-30 08:02:45 +08:00
}
}
convertSignature(signature) {
let fromLine = this.oLastMessage ? this.emailArrayToStringLineHelper(this.oLastMessage.from, true) : '';
if (fromLine) {
signature = signature.replace(/{{FROM-FULL}}/g, fromLine);
2014-08-21 23:08:34 +08:00
2020-07-21 03:39:00 +08:00
if (!fromLine.includes(' ') && 0 < fromLine.indexOf('@')) {
fromLine = fromLine.replace(/@\S+/, '');
}
2014-08-21 23:08:34 +08:00
signature = signature.replace(/{{FROM}}/g, fromLine);
}
return signature
.replace(/\r/g, '')
.replace(/\s{1,2}?{{FROM}}/g, '')
.replace(/\s{1,2}?{{FROM-FULL}}/g, '')
.replace(/{{DATE}}/g, new Date().format('LLLL'))
.replace(/{{TIME}}/g, new Date().format('LT'))
.replace(/{{MOMENT:[^}]+}}/g, '');
}
2014-08-21 23:08:34 +08:00
2017-07-06 06:31:41 +08:00
setSignatureFromIdentity(identity) {
2019-07-05 03:19:24 +08:00
if (identity) {
this.editor(editor => {
let signature = identity.signature(),
isHtml = signature && ':HTML:' === signature.substr(0, 6);
editor.setSignature(
this.convertSignature(isHtml ? signature.substr(6) : signature),
isHtml, !!identity.signatureInsertBefore());
});
}
2016-06-30 08:02:45 +08:00
}
/**
* @param {string=} type = ComposeType.Empty
* @param {?MessageModel|Array=} oMessageOrArray = null
* @param {Array=} aToEmails = null
* @param {Array=} aCcEmails = null
* @param {Array=} aBccEmails = null
* @param {string=} sCustomSubject = null
* @param {string=} sCustomPlainText = null
*/
onShow(type, oMessageOrArray, aToEmails, aCcEmails, aBccEmails, sCustomSubject, sCustomPlainText) {
rl.route.off();
2014-08-14 21:09:42 +08:00
const ro = this.resizeObserver;
ro.observe(ro.compose);
ro.observe(ro.header);
this.autosaveStart();
2014-12-28 03:48:55 +08:00
this.viewModelDom.dataset.wysiwyg = SettingsUserStore.editorDefaultType();
if (AppUserStore.composeInEdit()) {
type = type || ComposeType.Empty;
2019-07-05 03:19:24 +08:00
if (ComposeType.Empty !== type) {
showScreenPopup(AskPopupView, [
2019-07-05 03:19:24 +08:00
i18n('COMPOSE/DISCARD_UNSAVED_DATA'),
() => {
this.initOnShow(type, oMessageOrArray, aToEmails, aCcEmails, aBccEmails, sCustomSubject, sCustomPlainText);
},
null,
null,
null,
false
]);
} else {
this.addEmailsTo(this.to, aToEmails);
this.addEmailsTo(this.cc, aCcEmails);
this.addEmailsTo(this.bcc, aBccEmails);
if (sCustomSubject && !this.subject()) {
this.subject(sCustomSubject);
}
}
2019-07-05 03:19:24 +08:00
} else {
this.initOnShow(type, oMessageOrArray, aToEmails, aCcEmails, aBccEmails, sCustomSubject, sCustomPlainText);
2014-12-28 03:48:55 +08:00
}
2021-07-16 22:24:07 +08:00
// (navigator.standalone || matchMedia('(display-mode: standalone)').matches || matchMedia('(display-mode: fullscreen)').matches) &&
ThemeStore.isMobile() && this.oContent.requestFullscreen && this.oContent.requestFullscreen();
2016-06-30 08:02:45 +08:00
}
/**
* @param {Function} fKoValue
* @param {Array} emails
*/
addEmailsTo(fKoValue, emails) {
2021-07-22 03:34:17 +08:00
if (arrayLength(emails)) {
const value = fKoValue().trim(),
values = emails.map(item => item ? item.toLine(false) : null)
.validUnique();
fKoValue(value + (value ? ', ' : '') + values.join(', ').trim());
}
2016-06-30 08:02:45 +08:00
}
/**
*
* @param {Array} aList
* @param {boolean} bFriendly
* @returns {string}
*/
emailArrayToStringLineHelper(aList, bFriendly) {
bFriendly = !!bFriendly;
return aList.map(item => item.toLine(bFriendly)).join(', ');
2016-06-30 08:02:45 +08:00
}
2014-12-28 03:48:55 +08:00
isPlainEditor() {
let type = SettingsUserStore.editorDefaultType();
return EditorDefaultType.Html !== type && EditorDefaultType.HtmlForced !== type;
}
/**
* @param {string=} sType = ComposeType.Empty
* @param {?MessageModel|Array=} oMessageOrArray = null
* @param {Array=} aToEmails = null
* @param {Array=} aCcEmails = null
* @param {Array=} aBccEmails = null
* @param {string=} sCustomSubject = null
* @param {string=} sCustomPlainText = null
*/
2019-07-05 03:19:24 +08:00
initOnShow(sType, oMessageOrArray, aToEmails, aCcEmails, aBccEmails, sCustomSubject, sCustomPlainText) {
let sFrom = '',
sTo = '',
sCc = '',
sDate = '',
sSubject = '',
sText = '',
sReplyTitle = '',
identity = null,
aDraftInfo = null,
message = null;
2019-07-05 03:19:24 +08:00
const excludeEmail = {},
mEmail = AccountUserStore.email(),
lineComposeType = sType || ComposeType.Empty;
oMessageOrArray = oMessageOrArray || null;
if (oMessageOrArray) {
2019-07-05 03:19:24 +08:00
message =
2021-07-22 03:34:17 +08:00
1 === arrayLength(oMessageOrArray)
2019-07-05 03:19:24 +08:00
? oMessageOrArray[0]
2021-07-22 03:34:17 +08:00
: isArray(oMessageOrArray)
? null
: oMessageOrArray;
}
2014-08-21 23:08:34 +08:00
this.oLastMessage = message;
2019-07-05 03:19:24 +08:00
if (null !== mEmail) {
excludeEmail[mEmail] = true;
}
this.reset();
identity = this.findIdentityByMessage(lineComposeType, message);
2019-07-05 03:19:24 +08:00
if (identity) {
excludeEmail[identity.email()] = true;
2014-08-21 23:08:34 +08:00
}
2021-07-22 03:34:17 +08:00
if (arrayLength(aToEmails)) {
this.to(this.emailArrayToStringLineHelper(aToEmails));
}
2021-07-22 03:34:17 +08:00
if (arrayLength(aCcEmails)) {
this.cc(this.emailArrayToStringLineHelper(aCcEmails));
}
2021-07-22 03:34:17 +08:00
if (arrayLength(aBccEmails)) {
this.bcc(this.emailArrayToStringLineHelper(aBccEmails));
}
2014-08-21 23:08:34 +08:00
if (lineComposeType && message) {
sDate = timestampToString(message.dateTimeStampInUTC(), 'FULL');
sSubject = message.subject();
aDraftInfo = message.aDraftInfo;
2020-08-27 21:45:47 +08:00
sText = message.bodyAsHTML();
2014-08-21 23:08:34 +08:00
let resplyAllParts = null;
2019-07-05 03:19:24 +08:00
switch (lineComposeType) {
case ComposeType.Empty:
break;
case ComposeType.Reply:
this.to(this.emailArrayToStringLineHelper(message.replyEmails(excludeEmail)));
this.subject(replySubjectAdd('Re', sSubject));
this.prepareMessageAttachments(message, lineComposeType);
2020-10-23 21:15:54 +08:00
this.aDraftInfo = ['reply', message.uid, message.folder];
this.sInReplyTo = message.sMessageId;
this.sReferences = (this.sInReplyTo + ' ' + message.sReferences).trim();
break;
case ComposeType.ReplyAll:
resplyAllParts = message.replyAllEmails(excludeEmail);
this.to(this.emailArrayToStringLineHelper(resplyAllParts[0]));
this.cc(this.emailArrayToStringLineHelper(resplyAllParts[1]));
this.subject(replySubjectAdd('Re', sSubject));
this.prepareMessageAttachments(message, lineComposeType);
2020-10-23 21:15:54 +08:00
this.aDraftInfo = ['reply', message.uid, message.folder];
this.sInReplyTo = message.sMessageId;
2020-10-23 21:15:54 +08:00
this.sReferences = (this.sInReplyTo + ' ' + message.references).trim();
break;
case ComposeType.Forward:
this.subject(replySubjectAdd('Fwd', sSubject));
this.prepareMessageAttachments(message, lineComposeType);
2020-10-23 21:15:54 +08:00
this.aDraftInfo = ['forward', message.uid, message.folder];
this.sInReplyTo = message.sMessageId;
this.sReferences = (this.sInReplyTo + ' ' + message.sReferences).trim();
break;
case ComposeType.ForwardAsAttachment:
this.subject(replySubjectAdd('Fwd', sSubject));
this.prepareMessageAttachments(message, lineComposeType);
2020-10-23 21:15:54 +08:00
this.aDraftInfo = ['forward', message.uid, message.folder];
this.sInReplyTo = message.sMessageId;
this.sReferences = (this.sInReplyTo + ' ' + message.sReferences).trim();
break;
case ComposeType.Draft:
this.to(this.emailArrayToStringLineHelper(message.to));
this.cc(this.emailArrayToStringLineHelper(message.cc));
this.bcc(this.emailArrayToStringLineHelper(message.bcc));
this.replyTo(this.emailArrayToStringLineHelper(message.replyTo));
this.bFromDraft = true;
2014-08-12 20:32:08 +08:00
2020-10-23 21:15:54 +08:00
this.draftFolder(message.folder);
this.draftUid(message.uid);
this.subject(sSubject);
this.prepareMessageAttachments(message, lineComposeType);
2021-07-22 03:34:17 +08:00
this.aDraftInfo = 3 === arrayLength(aDraftInfo) ? aDraftInfo : null;
this.sInReplyTo = message.sInReplyTo;
this.sReferences = message.sReferences;
break;
case ComposeType.EditAsNew:
this.to(this.emailArrayToStringLineHelper(message.to));
this.cc(this.emailArrayToStringLineHelper(message.cc));
this.bcc(this.emailArrayToStringLineHelper(message.bcc));
this.replyTo(this.emailArrayToStringLineHelper(message.replyTo));
this.subject(sSubject);
this.prepareMessageAttachments(message, lineComposeType);
2021-07-22 03:34:17 +08:00
this.aDraftInfo = 3 === arrayLength(aDraftInfo) ? aDraftInfo : null;
this.sInReplyTo = message.sInReplyTo;
this.sReferences = message.sReferences;
break;
// no default
2014-08-21 23:08:34 +08:00
}
2019-07-05 03:19:24 +08:00
switch (lineComposeType) {
case ComposeType.Reply:
case ComposeType.ReplyAll:
sFrom = message.fromToLine(false, true);
sReplyTitle = i18n('COMPOSE/REPLY_MESSAGE_TITLE', {
DATETIME: sDate,
EMAIL: sFrom
});
sText = sText.replace(/<img[^>]+>/g, '').replace(/<a\s[^>]+><\/a>/g, '').trim();
sText = '<br/><br/>' + sReplyTitle + ':<br/><br/><blockquote>' + sText + '</blockquote>';
break;
case ComposeType.Forward:
sFrom = message.fromToLine(false, true);
sTo = message.toToLine(false, true);
sCc = message.ccToLine(false, true);
2019-07-05 03:19:24 +08:00
sText =
'<br/><br/>' +
2019-07-05 03:19:24 +08:00
i18n('COMPOSE/FORWARD_MESSAGE_TOP_TITLE') +
'<br/>' +
2021-01-22 00:21:19 +08:00
i18n('GLOBAL/FROM') +
2019-07-05 03:19:24 +08:00
': ' +
sFrom +
'<br/>' +
2021-01-22 00:21:19 +08:00
i18n('GLOBAL/TO') +
2019-07-05 03:19:24 +08:00
': ' +
sTo +
(sCc.length ? '<br/>' + i18n('GLOBAL/CC') + ': ' + sCc : '') +
'<br/>' +
2019-07-05 03:19:24 +08:00
i18n('COMPOSE/FORWARD_MESSAGE_TOP_SENT') +
': ' +
encodeHtml(sDate) +
'<br/>' +
2021-01-22 00:21:19 +08:00
i18n('GLOBAL/SUBJECT') +
2019-07-05 03:19:24 +08:00
': ' +
encodeHtml(sSubject) +
'<br/><br/>' +
sText.trim() +
'<br/><br/>';
break;
case ComposeType.ForwardAsAttachment:
sText = '';
break;
// no default
2016-06-30 08:02:45 +08:00
}
2014-08-21 23:08:34 +08:00
this.editor(editor => {
editor.setHtml(sText);
2014-08-12 21:51:34 +08:00
2019-07-05 03:19:24 +08:00
if (
EditorDefaultType.PlainForced === SettingsUserStore.editorDefaultType() ||
(!message.isHtml() && EditorDefaultType.HtmlForced !== SettingsUserStore.editorDefaultType())
2019-07-05 03:19:24 +08:00
) {
editor.modePlain();
}
2019-07-05 03:19:24 +08:00
if (identity && ComposeType.Draft !== lineComposeType && ComposeType.EditAsNew !== lineComposeType) {
2017-07-06 06:31:41 +08:00
this.setSignatureFromIdentity(identity);
}
this.setFocusInPopup();
});
2019-07-05 03:19:24 +08:00
} else if (ComposeType.Empty === lineComposeType) {
this.subject(null != sCustomSubject ? '' + sCustomSubject : '');
sText = null != sCustomPlainText ? '' + sCustomPlainText : '';
this.editor(editor => {
editor.setHtml(sText);
if (this.isPlainEditor()) {
editor.modePlain();
}
2019-07-05 03:19:24 +08:00
if (identity) {
2017-07-06 06:31:41 +08:00
this.setSignatureFromIdentity(identity);
}
this.setFocusInPopup();
2016-08-10 01:27:04 +08:00
});
2021-07-22 03:34:17 +08:00
} else if (arrayLength(oMessageOrArray)) {
oMessageOrArray.forEach(item => this.addMessageAsAttachment(item));
this.editor(editor => {
if (this.isPlainEditor()) {
editor.setPlain('')
} else {
editor.setHtml('');
}
2015-02-26 22:47:37 +08:00
2019-07-05 03:19:24 +08:00
if (identity && ComposeType.Draft !== lineComposeType && ComposeType.EditAsNew !== lineComposeType) {
2017-07-06 06:31:41 +08:00
this.setSignatureFromIdentity(identity);
}
this.setFocusInPopup();
});
2019-07-05 03:19:24 +08:00
} else {
this.setFocusInPopup();
}
const downloads = this.getAttachmentsDownloadsForUpload();
2021-07-22 03:34:17 +08:00
if (arrayLength(downloads)) {
Remote.messageUploadAttachments((iError, oData) => {
2021-03-18 21:48:21 +08:00
if (!iError) {
Object.entries(oData.Result).forEach(([tempName, id]) => {
const attachment = this.getAttachmentById(id);
if (attachment) {
attachment.tempName(tempName);
attachment
.waiting(false)
.uploading(false)
.complete(true);
}
});
} else {
this.attachments.forEach(attachment => {
if (attachment && attachment.fromMessage) {
attachment
.waiting(false)
.uploading(false)
.complete(true)
.error(getUploadErrorDescByCode(UploadErrorCode.NoFileUploaded));
}
});
}
}, downloads);
}
2015-02-26 22:47:37 +08:00
2019-07-05 03:19:24 +08:00
if (identity) {
this.currentIdentity(identity);
}
}
setFocusInPopup() {
setTimeout(() => {
if (!this.to()) {
this.to.focused(true);
} else if (!this.to.focused()) {
this.oEditor && this.oEditor.focus();
}
}, 100);
}
2016-06-30 08:02:45 +08:00
tryToClosePopup() {
if (!isPopupVisible(AskPopupView) && this.modalVisibility()) {
2019-07-05 03:19:24 +08:00
if (this.bSkipNextHide || (this.isEmptyForm() && !this.draftUid())) {
this.closeCommand();
2019-07-05 03:19:24 +08:00
} else {
showScreenPopup(AskPopupView, [
2019-07-05 03:19:24 +08:00
i18n('POPUPS_ASK/DESC_WANT_CLOSE_THIS_WINDOW'),
() => {
this.modalVisibility() && this.closeCommand();
}
2019-07-05 03:19:24 +08:00
]);
}
}
}
2016-07-01 06:50:11 +08:00
popupMenu(event) {
if (event.ctrlKey || event.metaKey || 'ContextMenu' == event.key
|| (this.oEditor && !this.oEditor.hasFocus() && !inFocus())) {
this.identitiesDropdownTrigger(true);
return false;
}
}
onBuild(dom) {
2021-08-13 02:17:37 +08:00
// initUploader
if (this.composeUploaderButton()) {
const uploadCache = {},
attachmentSizeLimit = pInt(SettingsGet('AttachmentLimit')),
oJua = new Jua({
action: serverRequest('Upload'),
name: 'uploader',
queueSize: 2,
multipleSizeLimit: 50,
clickElement: this.composeUploaderButton(),
dragAndDropElement: this.composeUploaderDropPlace()
});
oJua
// .on('onLimitReached', (limit) => {
// alert(limit);
// })
.on('onDragEnter', () => {
this.dragAndDropOver(true);
})
.on('onDragLeave', () => {
this.dragAndDropOver(false);
})
.on('onBodyDragEnter', () => {
this.attachmentsPlace(true);
this.dragAndDropVisible(true);
})
.on('onBodyDragLeave', () => {
this.dragAndDropVisible(false);
})
.on('onProgress', (id, loaded, total) => {
let item = uploadCache[id];
if (!item) {
item = this.getAttachmentById(id);
if (item) {
uploadCache[id] = item;
}
}
if (item) {
item.progress(Math.floor((loaded / total) * 100));
}
})
.on('onSelect', (sId, oData) => {
this.dragAndDropOver(false);
const fileName = undefined === oData.FileName ? '' : oData.FileName.toString(),
size = pInt(oData.Size, null),
attachment = new ComposeAttachmentModel(sId, fileName, size);
attachment.cancel = this.cancelAttachmentHelper(sId, oJua);
this.attachments.push(attachment);
this.attachmentsPlace(true);
if (0 < size && 0 < attachmentSizeLimit && attachmentSizeLimit < size) {
attachment
.waiting(false)
.uploading(true)
.complete(true)
.error(i18n('UPLOAD/ERROR_FILE_IS_TOO_BIG'));
return false;
}
return true;
})
.on('onStart', (id) => {
let item = uploadCache[id];
if (!item) {
item = this.getAttachmentById(id);
if (item) {
uploadCache[id] = item;
}
}
if (item) {
item
.waiting(false)
.uploading(true)
.complete(false);
}
})
.on('onComplete', (id, result, data) => {
const attachment = this.getAttachmentById(id),
errorCode = data && data.Result && data.Result.ErrorCode ? data.Result.ErrorCode : null,
attachmentJson = result && data && data.Result && data.Result.Attachment ? data.Result.Attachment : null;
let error = '';
if (null !== errorCode) {
error = getUploadErrorDescByCode(errorCode);
} else if (!attachmentJson) {
error = i18n('UPLOAD/ERROR_UNKNOWN');
}
if (attachment) {
if (error && error.length) {
attachment
.waiting(false)
.uploading(false)
.complete(true)
.error(error);
} else if (attachmentJson) {
attachment
.waiting(false)
.uploading(false)
.complete(true);
attachment.initByUploadJson(attachmentJson);
}
if (undefined === uploadCache[id]) {
delete uploadCache[id];
}
}
});
this.addAttachmentEnabled(true);
}
2014-08-21 23:08:34 +08:00
shortcuts.add('q', 'meta', Scope.Compose, ()=>false);
shortcuts.add('w', 'meta', Scope.Compose, ()=>false);
2016-06-30 08:02:45 +08:00
2021-08-13 16:03:13 +08:00
shortcuts.add('contextmenu', '', Scope.Compose, e => this.popupMenu(e));
shortcuts.add('m', 'meta', Scope.Compose, e => this.popupMenu(e));
shortcuts.add('escape,close', '', Scope.Compose, () => {
this.skipCommand();
return false;
});
shortcuts.add('arrowdown', 'meta', Scope.Compose, () => {
this.skipCommand();
2016-06-30 08:02:45 +08:00
return false;
});
2015-03-21 06:22:06 +08:00
shortcuts.add('s', 'meta', Scope.Compose, () => {
this.saveCommand();
return false;
});
2021-08-13 16:03:13 +08:00
shortcuts.add('save', '', Scope.Compose, () => {
this.saveCommand();
return false;
});
if (Settings.app('allowCtrlEnterOnCompose')) {
shortcuts.add('enter', 'meta', Scope.Compose, () => {
this.sendCommand();
return false;
});
}
shortcuts.add('mailsend', '', Scope.Compose, () => {
this.sendCommand();
return false;
});
shortcuts.add('escape,close', 'shift', Scope.Compose, () => {
this.modalVisibility() && this.tryToClosePopup();
return false;
});
const ro = this.resizeObserver;
ro.compose = dom.querySelector('.b-compose');
ro.header = dom.querySelector('.b-header');
ro.toolbar = dom.querySelector('.b-header-toolbar');
ro.els = [dom.querySelector('.textAreaParent'), dom.querySelector('.attachmentAreaParent')];
2021-04-23 06:12:42 +08:00
this.editor(editor => editor[this.isPlainEditor()?'modePlain':'modeWysiwyg']());
// Fullscreen must be on app, else other popups fail
const el = doc.getElementById('rl-app');
let event = 'fullscreenchange';
if (!el.requestFullscreen && el.webkitRequestFullscreen) {
el.requestFullscreen = el.webkitRequestFullscreen;
event = 'webkit' + event;
}
if (el.requestFullscreen) {
if (!doc.exitFullscreen && doc.webkitExitFullscreen) {
doc.exitFullscreen = doc.webkitExitFullscreen;
}
this.oContent = el;
el.addEventListener(event, () =>
ThemeStore.isMobile()
&& this.modalVisibility()
&& (doc.fullscreenElement || doc.webkitFullscreenElement) !== el
&& this.skipCommand()
);
}
}
/**
* @param {string} id
* @returns {?Object}
*/
getAttachmentById(id) {
return this.attachments.find(item => item && id === item.id);
}
2014-10-04 19:58:01 +08:00
cancelAttachmentHelper(id, oJua) {
return () => {
const attachment = this.getAttachmentById(id);
2019-07-05 03:19:24 +08:00
if (attachment) {
this.attachments.remove(attachment);
delegateRunOnDestroy(attachment);
oJua && oJua.cancel(id);
}
};
}
2014-10-04 19:58:01 +08:00
/**
* @returns {Object}
*/
prepearAttachmentsForSendOrSave() {
const result = {};
this.attachments.forEach(item => {
if (item && item.complete() && item.tempName() && item.enabled()) {
2019-07-05 03:19:24 +08:00
result[item.tempName()] = [item.fileName(), item.isInline ? '1' : '0', item.CID, item.contentLocation];
}
});
2016-06-30 08:02:45 +08:00
return result;
}
2014-08-21 23:08:34 +08:00
/**
* @param {MessageModel} message
*/
addMessageAsAttachment(message) {
2019-07-05 03:19:24 +08:00
if (message) {
let temp = message.subject();
temp = '.eml' === temp.substr(-4).toLowerCase() ? temp : temp + '.eml';
2016-08-10 03:52:30 +08:00
2019-07-05 03:19:24 +08:00
const attachment = new ComposeAttachmentModel(message.requestHash, temp, message.size());
attachment.fromMessage = true;
attachment.cancel = this.cancelAttachmentHelper(message.requestHash);
2019-07-05 03:19:24 +08:00
attachment
.waiting(false)
.uploading(true)
.complete(true);
this.attachments.push(attachment);
}
2016-06-30 08:02:45 +08:00
}
/**
* @param {string} url
* @param {string} name
* @param {number} size
* @returns {ComposeAttachmentModel}
*/
addAttachmentHelper(url, name, size) {
const attachment = new ComposeAttachmentModel(url, name, size);
attachment.fromMessage = false;
attachment.cancel = this.cancelAttachmentHelper(url);
2019-07-05 03:19:24 +08:00
attachment
.waiting(false)
.uploading(true)
.complete(false);
2014-07-29 18:28:02 +08:00
this.attachments.push(attachment);
2014-07-29 18:28:02 +08:00
this.attachmentsPlace(true);
2016-08-10 02:58:34 +08:00
return attachment;
2016-06-30 08:02:45 +08:00
}
/**
* @param {MessageModel} message
* @param {string} type
*/
prepareMessageAttachments(message, type) {
2019-07-05 03:19:24 +08:00
if (message) {
if (ComposeType.ForwardAsAttachment === type) {
this.addMessageAsAttachment(message);
2019-07-05 03:19:24 +08:00
} else {
message.attachments.forEach(item => {
let add = false;
2019-07-05 03:19:24 +08:00
switch (type) {
case ComposeType.Reply:
case ComposeType.ReplyAll:
break;
2016-06-30 08:02:45 +08:00
case ComposeType.Forward:
case ComposeType.Draft:
case ComposeType.EditAsNew:
add = true;
break;
// no default
}
2019-07-05 03:19:24 +08:00
if (add) {
2020-09-19 19:53:14 +08:00
const attachment = ComposeAttachmentModel.fromAttachment(item);
attachment.cancel = this.cancelAttachmentHelper(item.download);
2019-07-05 03:19:24 +08:00
attachment
.waiting(false)
.uploading(true)
.complete(false);
2014-08-21 23:08:34 +08:00
this.attachments.push(attachment);
}
});
}
2016-06-30 08:02:45 +08:00
}
}
/**
* @param {boolean=} includeAttachmentInProgress = true
* @returns {boolean}
*/
isEmptyForm(includeAttachmentInProgress = true) {
2019-07-05 03:19:24 +08:00
const withoutAttachment = includeAttachmentInProgress
? !this.attachments.length
: !this.attachments.some(item => item && item.complete());
2019-07-05 03:19:24 +08:00
return (
!this.to.length &&
!this.cc.length &&
!this.bcc.length &&
!this.replyTo.length &&
!this.subject.length &&
withoutAttachment &&
(!this.oEditor || !this.oEditor.getData())
2019-07-05 03:19:24 +08:00
);
2016-06-30 08:02:45 +08:00
}
2014-08-21 23:08:34 +08:00
reset() {
this.to('');
this.cc('');
this.bcc('');
this.replyTo('');
this.subject('');
2016-06-30 08:02:45 +08:00
this.requestDsn(false);
this.requestReadReceipt(false);
this.markAsImportant(false);
2016-06-30 08:02:45 +08:00
this.attachmentsPlace(false);
2016-06-30 08:02:45 +08:00
this.aDraftInfo = null;
this.sInReplyTo = '';
this.bFromDraft = false;
this.sReferences = '';
2016-06-30 08:02:45 +08:00
this.sendError(false);
this.sendSuccessButSaveError(false);
this.savedError(false);
this.savedTime(0);
this.emptyToError(false);
this.attachmentsInProcessError(false);
2016-06-30 08:02:45 +08:00
this.showCc(false);
this.showBcc(false);
this.showReplyTo(false);
2016-06-30 08:02:45 +08:00
delegateRunOnDestroy(this.attachments());
this.attachments([]);
2016-06-30 08:02:45 +08:00
this.dragAndDropOver(false);
this.dragAndDropVisible(false);
2016-06-30 08:02:45 +08:00
this.draftFolder('');
this.draftUid('');
2016-06-30 08:02:45 +08:00
this.sending(false);
this.saving(false);
2016-06-30 08:02:45 +08:00
this.oEditor && this.oEditor.clear();
2016-06-30 08:02:45 +08:00
}
/**
* @returns {Array}
*/
getAttachmentsDownloadsForUpload() {
return this.attachments.filter(item => item && !item.tempName()).map(
item => item.id
2019-12-25 03:05:46 +08:00
);
}
resizerTrigger() {
let ro = this.resizeObserver,
height = Math.max(200, ro.compose.clientHeight - ro.header.offsetHeight - ro.toolbar.offsetHeight) + 'px';
if (ro.height !== height) {
ro.height = height;
ro.els.forEach(element => element.style.height = height);
this.oEditor && this.oEditor.resize();
}
}
}
2016-06-30 08:02:45 +08:00
2019-07-05 03:19:24 +08:00
export { ComposePopupView, ComposePopupView as default };