2016-08-17 06:01:20 +08:00
|
|
|
import ko from 'ko';
|
|
|
|
|
|
|
|
import {
|
2019-07-05 03:19:24 +08:00
|
|
|
Notification,
|
2016-08-17 06:01:20 +08:00
|
|
|
UploadErrorCode
|
|
|
|
} from 'Common/Enums';
|
|
|
|
|
2021-01-25 05:58:06 +08:00
|
|
|
import {
|
|
|
|
ComposeType,
|
|
|
|
EditorDefaultType,
|
|
|
|
SetSystemFoldersNotification
|
|
|
|
} from 'Common/EnumsUser';
|
|
|
|
|
2021-12-01 21:23:37 +08:00
|
|
|
import { inFocus, pInt, isArray, arrayLength, forEachObjectEntry } from 'Common/Utils';
|
2022-02-17 19:48:57 +08:00
|
|
|
import { initFullscreen } from 'Common/UtilsUser';
|
2022-02-03 23:51:35 +08:00
|
|
|
import { encodeHtml, HtmlEditor, htmlToPlain } from 'Common/Html';
|
2022-02-17 19:48:57 +08:00
|
|
|
import { koArrayWithDestroy } from 'External/ko';
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
import { UNUSED_OPTION_VALUE } from 'Common/Consts';
|
2022-02-24 02:26:52 +08:00
|
|
|
import { messagesDeleteHelper } from 'Common/Folders';
|
2021-02-04 18:25:00 +08:00
|
|
|
import { serverRequest } from 'Common/Links';
|
2022-02-24 02:26:52 +08:00
|
|
|
import { i18n, getNotification, getUploadErrorDescByCode, timestampToString } from 'Common/Translator';
|
2020-10-25 20:50:26 +08:00
|
|
|
import { MessageFlagsCache, setFolderHash } from 'Common/Cache';
|
2022-02-03 23:51:35 +08:00
|
|
|
import { doc, Settings, SettingsGet, getFullscreenElement, exitFullscreen, elementById } from 'Common/Globals';
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2021-03-11 05:41:35 +08:00
|
|
|
import { AppUserStore } from 'Stores/User/App';
|
|
|
|
import { SettingsUserStore } from 'Stores/User/Settings';
|
2021-02-17 21:40:21 +08:00
|
|
|
import { IdentityUserStore } from 'Stores/User/Identity';
|
2021-03-11 05:41:35 +08:00
|
|
|
import { AccountUserStore } from 'Stores/User/Account';
|
|
|
|
import { FolderUserStore } from 'Stores/User/Folder';
|
|
|
|
import { PgpUserStore } from 'Stores/User/Pgp';
|
2022-01-30 09:35:53 +08:00
|
|
|
import { OpenPGPUserStore } from 'Stores/User/OpenPGP';
|
2022-02-09 17:53:55 +08:00
|
|
|
import { GnuPGUserStore } from 'Stores/User/GnuPG';
|
2021-03-11 05:41:35 +08:00
|
|
|
import { MessageUserStore } from 'Stores/User/Message';
|
2022-02-24 02:26:52 +08:00
|
|
|
import { MessagelistUserStore } from 'Stores/User/Messagelist';
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2020-09-15 01:40:56 +08:00
|
|
|
import Remote from 'Remote/User/Fetch';
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
import { ComposeAttachmentModel } from 'Model/ComposeAttachment';
|
2022-01-20 01:24:07 +08:00
|
|
|
import { EmailModel } from 'Model/Email';
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2022-02-04 16:49:55 +08:00
|
|
|
import { decorateKoCommands, showScreenPopup } from 'Knoin/Knoin';
|
2021-01-24 17:25:23 +08:00
|
|
|
import { AbstractViewPopup } from 'Knoin/AbstractViews';
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2021-01-26 05:00:13 +08:00
|
|
|
import { FolderSystemPopupView } from 'View/Popup/FolderSystem';
|
|
|
|
import { AskPopupView } from 'View/Popup/Ask';
|
|
|
|
import { ContactsPopupView } from 'View/Popup/Contacts';
|
|
|
|
|
2021-07-16 03:01:41 +08:00
|
|
|
import { ThemeStore } from 'Stores/Theme';
|
|
|
|
|
2021-01-27 07:26:31 +08:00
|
|
|
const
|
2022-02-24 18:19:19 +08:00
|
|
|
ScopeCompose = 'Compose',
|
|
|
|
|
2022-02-07 18:32:53 +08:00
|
|
|
base64_encode = text => btoa(text).match(/.{1,76}/g).join('\r\n'),
|
2022-02-04 06:36:12 +08:00
|
|
|
|
2022-02-15 17:22:52 +08:00
|
|
|
email = new EmailModel(),
|
|
|
|
getEmail = value => {
|
|
|
|
email.clear();
|
|
|
|
email.parse(value.trim());
|
|
|
|
return email.email || false;
|
|
|
|
},
|
|
|
|
|
2020-10-03 05:54:15 +08:00
|
|
|
/**
|
|
|
|
* @param {string} prefix
|
|
|
|
* @param {string} subject
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
replySubjectAdd = (prefix, subject) => {
|
|
|
|
prefix = prefix.toUpperCase().trim();
|
2021-03-12 18:41:44 +08:00
|
|
|
subject = subject.replace(/\s+/g, ' ').trim();
|
2020-10-03 05:54:15 +08:00
|
|
|
|
|
|
|
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();
|
|
|
|
};
|
2020-09-04 18:05:17 +08:00
|
|
|
|
2020-09-17 06:02:35 +08:00
|
|
|
ko.extenders.toggleSubscribe = (target, options) => {
|
|
|
|
target.subscribe(options[1], options[0], 'beforeChange');
|
|
|
|
target.subscribe(options[2], options[0]);
|
|
|
|
return target;
|
|
|
|
};
|
|
|
|
|
2022-02-07 18:32:53 +08:00
|
|
|
class MimePart {
|
|
|
|
constructor() {
|
|
|
|
this.headers = {};
|
|
|
|
this.body = '';
|
2022-02-09 20:44:17 +08:00
|
|
|
this.boundary = '';
|
2022-02-07 18:32:53 +08:00
|
|
|
this.children = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
toString() {
|
|
|
|
const hasSub = this.children.length,
|
2022-02-09 20:44:17 +08:00
|
|
|
boundary = this.boundary || (this.boundary = 'part' + Jua.randomId()),
|
2022-02-07 18:32:53 +08:00
|
|
|
headers = this.headers;
|
|
|
|
if (hasSub) {
|
2022-02-09 20:44:17 +08:00
|
|
|
headers['Content-Type'] += `; boundary="${boundary}"`;
|
|
|
|
}
|
|
|
|
let result = Object.entries(headers).map(([key, value]) => `${key}: ${value}`).join('\r\n') + '\r\n';
|
|
|
|
if (this.body) {
|
|
|
|
result += '\r\n' + this.body.replace(/\r?\n/g, '\r\n');
|
2022-02-07 18:32:53 +08:00
|
|
|
}
|
|
|
|
if (hasSub) {
|
2022-02-09 20:44:17 +08:00
|
|
|
this.children.forEach(part => result += '\r\n--' + boundary + '\r\n' + part);
|
|
|
|
result += '\r\n--' + boundary + '--\r\n';
|
2022-02-07 18:32:53 +08:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-24 21:01:41 +08:00
|
|
|
export class ComposePopupView extends AbstractViewPopup {
|
2016-08-17 06:01:20 +08:00
|
|
|
constructor() {
|
2021-01-24 17:25:23 +08:00
|
|
|
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]();
|
2021-03-12 18:41:44 +08:00
|
|
|
let list = context[name]().trim().split(',');
|
2015-02-06 23:26:20 +08:00
|
|
|
|
2020-07-21 03:29:44 +08:00
|
|
|
list = list.filter(email => {
|
2020-08-07 00:24:46 +08:00
|
|
|
email = email.trim();
|
|
|
|
return email && identityEmail.trim() !== email;
|
2019-07-05 03:19:24 +08:00
|
|
|
});
|
2015-02-06 23:26:20 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
if (isIn) {
|
|
|
|
list.push(identityEmail);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2019-07-05 03:19:24 +08:00
|
|
|
|
|
|
|
context[name](list.join(','));
|
|
|
|
}
|
|
|
|
};
|
2015-02-01 03:00:10 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.oLastMessage = null;
|
|
|
|
this.oEditor = null;
|
|
|
|
this.aDraftInfo = null;
|
|
|
|
this.sInReplyTo = '';
|
|
|
|
this.bFromDraft = false;
|
|
|
|
this.sReferences = '';
|
2014-03-20 06:39:36 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.sLastFocusedField = 'to';
|
2015-02-16 05:55:59 +08:00
|
|
|
|
2021-03-17 17:05:22 +08:00
|
|
|
this.allowContacts = AppUserStore.allowContacts();
|
2014-12-31 20:21:43 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.bSkipNextHide = false;
|
2014-12-28 03:48:55 +08:00
|
|
|
|
2020-10-26 19:54:03 +08:00
|
|
|
this.addObservables({
|
|
|
|
identitiesDropdownTrigger: false,
|
2015-02-16 05:55:59 +08:00
|
|
|
|
2022-02-15 17:22:52 +08:00
|
|
|
from: '',
|
2020-10-26 19:54:03 +08:00
|
|
|
to: '',
|
|
|
|
cc: '',
|
|
|
|
bcc: '',
|
|
|
|
replyTo: '',
|
2017-09-28 01:58:15 +08:00
|
|
|
|
2020-10-26 19:54:03 +08:00
|
|
|
subject: '',
|
|
|
|
|
|
|
|
isHtml: false,
|
2015-02-06 23:26:20 +08:00
|
|
|
|
2020-10-26 19:54:03 +08:00
|
|
|
requestDsn: false,
|
|
|
|
requestReadReceipt: false,
|
|
|
|
markAsImportant: false,
|
2015-08-31 02:12:51 +08:00
|
|
|
|
2020-10-26 19:54:03 +08:00
|
|
|
sendError: false,
|
|
|
|
sendSuccessButSaveError: false,
|
|
|
|
savedError: false,
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2020-10-26 19:54:03 +08:00
|
|
|
sendErrorDesc: '',
|
|
|
|
savedErrorDesc: '',
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2020-10-26 19:54:03 +08:00
|
|
|
savedTime: 0,
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2020-10-26 19:54:03 +08:00
|
|
|
emptyToError: false,
|
2016-04-29 04:32:54 +08:00
|
|
|
|
2020-10-26 19:54:03 +08:00
|
|
|
attachmentsInProcessError: false,
|
|
|
|
attachmentsInErrorError: false,
|
2015-04-07 03:32:19 +08:00
|
|
|
|
2020-10-26 19:54:03 +08:00
|
|
|
showCc: false,
|
|
|
|
showBcc: false,
|
|
|
|
showReplyTo: false,
|
2015-04-07 03:32:19 +08:00
|
|
|
|
2022-01-20 01:24:07 +08:00
|
|
|
pgpSign: false,
|
|
|
|
canPgpSign: false,
|
2022-02-07 18:32:53 +08:00
|
|
|
pgpEncrypt: false,
|
2022-01-20 01:24:07 +08:00
|
|
|
canPgpEncrypt: false,
|
2022-02-03 23:51:35 +08:00
|
|
|
canMailvelope: false,
|
2022-01-20 01:24:07 +08:00
|
|
|
|
2021-12-01 20:54:35 +08:00
|
|
|
draftsFolder: '',
|
2021-09-10 22:28:29 +08:00
|
|
|
draftUid: 0,
|
2020-10-26 19:54:03 +08:00
|
|
|
sending: false,
|
|
|
|
saving: false,
|
2015-04-07 03:32:19 +08:00
|
|
|
|
2022-02-03 23:51:35 +08:00
|
|
|
viewArea: 'body',
|
2015-04-07 03:32:19 +08:00
|
|
|
|
2020-10-26 19:54:03 +08:00
|
|
|
attacheMultipleAllowed: false,
|
|
|
|
addAttachmentEnabled: false,
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2022-02-03 23:51:35 +08:00
|
|
|
editorArea: null, // initDom
|
2015-04-07 03:32:19 +08:00
|
|
|
|
2022-02-15 17:22:52 +08:00
|
|
|
currentIdentity: IdentityUserStore()[0]
|
2020-10-26 19:54:03 +08:00
|
|
|
});
|
|
|
|
|
2022-02-15 17:22:52 +08:00
|
|
|
this.from(IdentityUserStore()[0].formattedName());
|
|
|
|
|
2020-10-26 19:54:03 +08:00
|
|
|
// this.to.subscribe((v) => console.log(v));
|
2013-12-13 07:23:47 +08:00
|
|
|
|
2021-02-01 21:34:24 +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'));
|
2015-02-01 03:00:10 +08:00
|
|
|
|
2022-02-17 19:48:57 +08:00
|
|
|
this.attachments = koArrayWithDestroy();
|
2015-02-01 03:00:10 +08:00
|
|
|
|
2021-02-10 19:12:36 +08:00
|
|
|
this.dragAndDropOver = ko.observable(false).extend({ debounce: 1 });
|
|
|
|
this.dragAndDropVisible = ko.observable(false).extend({ debounce: 1 });
|
2015-01-05 03:30:07 +08:00
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
2015-01-05 03:30:07 +08:00
|
|
|
|
2020-10-26 19:54:03 +08:00
|
|
|
this.bDisabeCloseOnEsc = true;
|
|
|
|
|
|
|
|
this.tryToClosePopup = this.tryToClosePopup.debounce(200);
|
|
|
|
|
|
|
|
this.iTimer = 0;
|
|
|
|
|
|
|
|
this.addComputables({
|
|
|
|
sendButtonSuccess: () => !this.sendError() && !this.sendSuccessButSaveError(),
|
|
|
|
|
|
|
|
savedTimeText: () =>
|
2021-03-25 04:26:40 +08:00
|
|
|
this.savedTime() ? i18n('COMPOSE/SAVED_TIME', { TIME: this.savedTime().format('LT') }) : '',
|
2020-10-26 19:54:03 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
},
|
|
|
|
|
2021-01-22 19:23:20 +08:00
|
|
|
attachmentsInProcess: () => this.attachments.filter(item => item && !item.complete()),
|
|
|
|
attachmentsInError: () => this.attachments.filter(item => item && item.error()),
|
2020-10-26 19:54:03 +08:00
|
|
|
|
2021-01-22 19:23:20 +08:00
|
|
|
attachmentsCount: () => this.attachments.length,
|
|
|
|
attachmentsInErrorCount: () => this.attachmentsInError.length,
|
|
|
|
attachmentsInProcessCount: () => this.attachmentsInProcess.length,
|
2021-12-01 20:54:35 +08:00
|
|
|
isDraftFolderMessage: () => this.draftsFolder() && this.draftUid(),
|
2020-10-26 19:54:03 +08:00
|
|
|
|
|
|
|
identitiesOptions: () =>
|
2021-02-17 21:40:21 +08:00
|
|
|
IdentityUserStore.map(item => ({
|
2021-03-25 04:26:40 +08:00
|
|
|
item: item,
|
|
|
|
optValue: item.id(),
|
|
|
|
optText: item.formattedName()
|
2020-10-26 19:54:03 +08:00
|
|
|
})),
|
|
|
|
|
|
|
|
canBeSentOrSaved: () => !this.sending() && !this.saving()
|
2016-08-17 06:01:20 +08:00
|
|
|
});
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2020-10-26 19:54:03 +08:00
|
|
|
this.addSubscribables({
|
|
|
|
sendError: value => !value && this.sendErrorDesc(''),
|
|
|
|
|
|
|
|
savedError: value => !value && this.savedErrorDesc(''),
|
|
|
|
|
|
|
|
sendSuccessButSaveError: value => !value && this.savedErrorDesc(''),
|
|
|
|
|
2022-02-15 17:22:52 +08:00
|
|
|
currentIdentity: value => value && this.from(value.formattedName()),
|
|
|
|
|
|
|
|
from: value => {
|
2022-01-20 01:24:07 +08:00
|
|
|
this.canPgpSign(false);
|
2022-02-15 17:22:52 +08:00
|
|
|
value = getEmail(value);
|
|
|
|
value && PgpUserStore.getKeyForSigning(value).then(result => {
|
2022-02-04 23:21:29 +08:00
|
|
|
console.log({
|
2022-02-15 17:22:52 +08:00
|
|
|
email: value,
|
2022-02-04 23:21:29 +08:00
|
|
|
canPgpSign:result
|
|
|
|
});
|
2022-02-02 23:50:27 +08:00
|
|
|
this.canPgpSign(result)
|
2022-01-20 01:24:07 +08:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2020-10-26 19:54:03 +08:00
|
|
|
cc: value => {
|
|
|
|
if (false === this.showCc() && value.length) {
|
|
|
|
this.showCc(true);
|
|
|
|
}
|
2022-01-20 01:24:07 +08:00
|
|
|
this.initPgpEncrypt();
|
2020-10-26 19:54:03 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
bcc: value => {
|
|
|
|
if (false === this.showBcc() && value.length) {
|
|
|
|
this.showBcc(true);
|
|
|
|
}
|
2022-01-20 01:24:07 +08:00
|
|
|
this.initPgpEncrypt();
|
2020-10-26 19:54:03 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2022-01-20 01:24:07 +08:00
|
|
|
this.initPgpEncrypt();
|
2020-10-26 19:54:03 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
attachmentsInProcess: value => {
|
2021-07-22 03:34:17 +08:00
|
|
|
if (this.attachmentsInProcessError() && arrayLength(value)) {
|
2020-10-26 19:54:03 +08:00
|
|
|
this.attachmentsInProcessError(false);
|
|
|
|
}
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
});
|
2015-01-05 03:30:07 +08:00
|
|
|
|
2021-02-19 19:09:20 +08:00
|
|
|
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
|
|
|
}
|
2015-01-05 03:30:07 +08:00
|
|
|
|
2022-02-04 16:00:28 +08:00
|
|
|
async getMessageRequestParams(sSaveFolder, draft)
|
2020-08-18 03:32:57 +08:00
|
|
|
{
|
2022-02-09 20:44:17 +08:00
|
|
|
const
|
2022-02-04 16:00:28 +08:00
|
|
|
identity = this.currentIdentity(),
|
|
|
|
params = {
|
|
|
|
IdentityID: identity.id(),
|
|
|
|
MessageFolder: this.draftsFolder(),
|
|
|
|
MessageUid: this.draftUid(),
|
|
|
|
SaveFolder: sSaveFolder,
|
2022-02-15 17:22:52 +08:00
|
|
|
From: this.from(),
|
2022-02-04 16:00:28 +08:00
|
|
|
To: this.to(),
|
|
|
|
Cc: this.cc(),
|
|
|
|
Bcc: this.bcc(),
|
|
|
|
ReplyTo: this.replyTo(),
|
|
|
|
Subject: this.subject(),
|
|
|
|
DraftInfo: this.aDraftInfo,
|
|
|
|
InReplyTo: this.sInReplyTo,
|
|
|
|
References: this.sReferences,
|
|
|
|
MarkAsImportant: this.markAsImportant() ? 1 : 0,
|
|
|
|
Attachments: this.prepareAttachmentsForSendOrSave(),
|
|
|
|
// Only used at send, not at save:
|
|
|
|
Dsn: this.requestDsn() ? 1 : 0,
|
|
|
|
ReadReceiptRequest: this.requestReadReceipt() ? 1 : 0
|
|
|
|
},
|
|
|
|
recipients = draft ? [identity.email()] : this.allRecipients(),
|
|
|
|
sign = !draft && this.pgpSign() && this.canPgpSign(),
|
|
|
|
encrypt = this.pgpEncrypt() && this.canPgpEncrypt(),
|
2022-02-09 20:44:17 +08:00
|
|
|
TextIsHtml = this.oEditor.isHtml();
|
|
|
|
|
|
|
|
let Text = this.oEditor.getData();
|
2021-03-12 18:41:44 +08:00
|
|
|
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)
|
2022-02-09 20:44:17 +08:00
|
|
|
params.Html = Text;
|
|
|
|
} else {
|
|
|
|
params.Text = Text;
|
2021-03-12 18:41:44 +08:00
|
|
|
}
|
2022-02-09 20:44:17 +08:00
|
|
|
|
2022-02-04 16:00:28 +08:00
|
|
|
if (this.mailvelope && 'mailvelope' === this.viewArea()) {
|
|
|
|
params.Encrypted = draft
|
|
|
|
? await this.mailvelope.createDraft()
|
|
|
|
: await this.mailvelope.encrypt(recipients);
|
2022-02-09 20:44:17 +08:00
|
|
|
} else if (sign || encrypt) {
|
2022-02-07 18:32:53 +08:00
|
|
|
let data = new MimePart;
|
|
|
|
data.headers['Content-Type'] = 'text/'+(TextIsHtml?'html':'plain')+'; charset="utf-8"';
|
|
|
|
data.headers['Content-Transfer-Encoding'] = 'base64';
|
|
|
|
data.body = base64_encode(Text);
|
2022-02-09 20:44:17 +08:00
|
|
|
if (TextIsHtml) {
|
|
|
|
let alternative = new MimePart;
|
|
|
|
alternative.headers['Content-Type'] = 'multipart/alternative';
|
|
|
|
alternative.children.push(data);
|
|
|
|
data = new MimePart;
|
|
|
|
data.headers['Content-Type'] = 'text/plain; charset="utf-8"';
|
|
|
|
data.headers['Content-Transfer-Encoding'] = 'base64';
|
|
|
|
data.body = base64_encode(htmlToPlain(Text));
|
|
|
|
alternative.children.push(data);
|
|
|
|
data = alternative;
|
2022-02-04 16:00:28 +08:00
|
|
|
}
|
2022-02-09 20:44:17 +08:00
|
|
|
if (sign && !draft && sign[1]) {
|
|
|
|
if ('openpgp' == sign[0]) {
|
|
|
|
// Doesn't sign attachments
|
2022-02-10 05:58:47 +08:00
|
|
|
params.Html = params.Text = '';
|
2022-02-09 20:44:17 +08:00
|
|
|
let signed = new MimePart;
|
|
|
|
signed.headers['Content-Type'] =
|
|
|
|
'multipart/signed; micalg="pgp-sha256"; protocol="application/pgp-signature"';
|
|
|
|
signed.headers['Content-Transfer-Encoding'] = '7Bit';
|
|
|
|
signed.children.push(data);
|
|
|
|
let signature = new MimePart;
|
|
|
|
signature.headers['Content-Type'] = 'application/pgp-signature; name="signature.asc"';
|
|
|
|
signature.headers['Content-Transfer-Encoding'] = '7Bit';
|
|
|
|
signature.body = await OpenPGPUserStore.sign(data.toString(), sign[1], 1);
|
|
|
|
signed.children.push(signature);
|
2022-02-10 05:58:47 +08:00
|
|
|
params.Signed = signed.toString();
|
|
|
|
params.Boundary = signed.boundary;
|
2022-02-09 20:44:17 +08:00
|
|
|
data = signed;
|
2022-02-10 05:58:47 +08:00
|
|
|
} else if ('gnupg' == sign[0]) {
|
2022-02-09 20:44:17 +08:00
|
|
|
// TODO: sign in PHP fails
|
2022-02-10 05:58:47 +08:00
|
|
|
// params.SignData = data.toString();
|
2022-02-09 20:44:17 +08:00
|
|
|
params.SignFingerprint = sign[1].fingerprint;
|
|
|
|
params.SignPassphrase = await GnuPGUserStore.sign(sign[1]);
|
|
|
|
} else {
|
|
|
|
throw 'Signing with ' + sign[0] + ' not yet implemented';
|
|
|
|
}
|
2022-02-07 18:59:47 +08:00
|
|
|
}
|
2022-02-09 17:53:55 +08:00
|
|
|
if (encrypt) {
|
2022-02-09 20:44:17 +08:00
|
|
|
if ('openpgp' == encrypt) {
|
|
|
|
// Doesn't encrypt attachments
|
|
|
|
params.Encrypted = await OpenPGPUserStore.encrypt(data.toString(), recipients);
|
|
|
|
params.Signed = '';
|
|
|
|
} else if ('gnupg' == encrypt) {
|
|
|
|
// Does encrypt attachments
|
|
|
|
params.EncryptFingerprints = JSON.stringify(GnuPGUserStore.getPublicKeyFingerprints(recipients));
|
|
|
|
} else {
|
|
|
|
throw 'Encryption with ' + encrypt + ' not yet implemented';
|
|
|
|
}
|
2022-02-09 17:53:55 +08:00
|
|
|
}
|
2022-02-04 16:00:28 +08:00
|
|
|
}
|
|
|
|
return params;
|
2020-08-18 03:32:57 +08:00
|
|
|
}
|
|
|
|
|
2016-09-10 06:38:16 +08:00
|
|
|
sendCommand() {
|
2021-03-11 05:41:35 +08:00
|
|
|
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);
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2020-07-28 18:35:41 +08:00
|
|
|
if (this.attachmentsInProcess().length) {
|
2016-09-10 06:38:16 +08:00
|
|
|
this.attachmentsInProcessError(true);
|
2022-02-03 23:51:35 +08:00
|
|
|
this.attachmentsArea();
|
2020-07-28 18:35:41 +08:00
|
|
|
} else if (this.attachmentsInError().length) {
|
2016-09-10 06:38:16 +08:00
|
|
|
this.attachmentsInErrorError(true);
|
2022-02-03 23:51:35 +08:00
|
|
|
this.attachmentsArea();
|
2016-09-10 06:38:16 +08:00
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2020-08-18 03:32:57 +08:00
|
|
|
if (!this.to().trim() && !this.cc().trim() && !this.bcc().trim()) {
|
2016-09-10 06:38:16 +08:00
|
|
|
this.emptyToError(true);
|
|
|
|
}
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
if (!this.emptyToError() && !this.attachmentsInErrorError() && !this.attachmentsInProcessError()) {
|
2021-03-11 05:41:35 +08:00
|
|
|
if (SettingsUserStore.replySameFolder()) {
|
2019-07-05 03:19:24 +08:00
|
|
|
if (
|
2021-07-22 03:34:17 +08:00
|
|
|
3 === arrayLength(this.aDraftInfo) &&
|
2020-08-18 03:57:56 +08:00
|
|
|
null != this.aDraftInfo[2] &&
|
2020-07-28 18:35:41 +08:00
|
|
|
this.aDraftInfo[2].length
|
2019-07-05 03:19:24 +08:00
|
|
|
) {
|
2016-09-10 06:38:16 +08:00
|
|
|
sSentFolder = this.aDraftInfo[2];
|
|
|
|
}
|
|
|
|
}
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2020-07-28 23:20:14 +08:00
|
|
|
if (!sSentFolder) {
|
2021-01-26 05:00:13 +08:00
|
|
|
showScreenPopup(FolderSystemPopupView, [SetSystemFoldersNotification.Sent]);
|
2022-02-02 23:50:27 +08:00
|
|
|
} else try {
|
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)) {
|
2020-10-30 23:46:18 +08:00
|
|
|
const flagsCache = MessageFlagsCache.getFor(this.aDraftInfo[2], this.aDraftInfo[1]);
|
2021-12-07 07:05:55 +08:00
|
|
|
if (isArray(flagsCache)) {
|
|
|
|
flagsCache.push(('forward' === this.aDraftInfo[0]) ? '$forwarded' : '\\answered');
|
2020-10-25 20:50:26 +08:00
|
|
|
MessageFlagsCache.setFor(this.aDraftInfo[2], this.aDraftInfo[1], flagsCache);
|
2022-02-24 02:26:52 +08:00
|
|
|
MessagelistUserStore.reloadFlagsAndCachedMessage();
|
2016-09-10 06:38:16 +08:00
|
|
|
setFolderHash(this.aDraftInfo[2], '');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sSentFolder = UNUSED_OPTION_VALUE === sSentFolder ? '' : sSentFolder;
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2022-02-04 16:00:28 +08:00
|
|
|
this.getMessageRequestParams(sSentFolder).then(params => {
|
|
|
|
Remote.request('SendMessage',
|
|
|
|
(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());
|
2022-01-20 16:59:56 +08:00
|
|
|
} else {
|
2022-02-04 16:00:28 +08:00
|
|
|
this.sendError(true);
|
|
|
|
this.sendErrorDesc(getNotification(iError, data && data.ErrorMessage)
|
|
|
|
|| getNotification(Notification.CantSendMessage));
|
2022-01-20 16:59:56 +08:00
|
|
|
}
|
2022-02-04 16:00:28 +08:00
|
|
|
} else {
|
|
|
|
this.closeCommand();
|
2021-04-23 16:47:24 +08:00
|
|
|
}
|
2022-02-04 06:36:12 +08:00
|
|
|
}
|
2022-02-04 16:00:28 +08:00
|
|
|
setFolderHash(this.draftsFolder(), '');
|
|
|
|
setFolderHash(sSentFolder, '');
|
|
|
|
this.reloadDraftFolder();
|
|
|
|
},
|
|
|
|
params,
|
|
|
|
30000
|
|
|
|
);
|
|
|
|
}).catch(e => {
|
|
|
|
console.error(e);
|
|
|
|
this.sendError(true);
|
|
|
|
this.sendErrorDesc(e);
|
|
|
|
this.sending(false);
|
|
|
|
});
|
2022-02-02 23:50:27 +08:00
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
this.sendError(true);
|
|
|
|
this.sendErrorDesc(e);
|
|
|
|
this.sending(false);
|
2013-11-16 06:21:12 +08:00
|
|
|
}
|
2016-09-10 06:38:16 +08:00
|
|
|
}
|
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-09-10 06:38:16 +08:00
|
|
|
saveCommand() {
|
2021-12-01 20:54:35 +08:00
|
|
|
if (FolderUserStore.draftsFolderNotEnabled()) {
|
2021-01-26 05:00:13 +08:00
|
|
|
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);
|
|
|
|
this.autosaveStart();
|
2022-02-04 16:00:28 +08:00
|
|
|
this.getMessageRequestParams(FolderUserStore.draftsFolder(), 1).then(params => {
|
|
|
|
Remote.request('SaveMessage',
|
|
|
|
(iError, oData) => {
|
|
|
|
let result = false;
|
2014-12-28 03:48:55 +08:00
|
|
|
|
2022-02-04 16:00:28 +08:00
|
|
|
this.saving(false);
|
2014-08-22 23:08:56 +08:00
|
|
|
|
2022-02-04 16:00:28 +08:00
|
|
|
if (!iError) {
|
|
|
|
if (oData.Result.NewFolder && oData.Result.NewUid) {
|
|
|
|
result = true;
|
2021-04-23 16:47:24 +08:00
|
|
|
|
2022-02-04 16:00:28 +08:00
|
|
|
if (this.bFromDraft) {
|
|
|
|
const message = MessageUserStore.message();
|
|
|
|
if (message && this.draftsFolder() === message.folder && this.draftUid() == message.uid) {
|
|
|
|
MessageUserStore.message(null);
|
2022-02-03 23:51:35 +08:00
|
|
|
}
|
2022-02-04 16:00:28 +08:00
|
|
|
}
|
2021-04-23 16:47:24 +08:00
|
|
|
|
2022-02-04 16:00:28 +08:00
|
|
|
this.draftsFolder(oData.Result.NewFolder);
|
|
|
|
this.draftUid(oData.Result.NewUid);
|
2021-04-23 16:47:24 +08:00
|
|
|
|
2022-02-04 16:00:28 +08:00
|
|
|
this.savedTime(new Date);
|
2021-04-23 16:47:24 +08:00
|
|
|
|
2022-02-04 16:00:28 +08:00
|
|
|
if (this.bFromDraft) {
|
|
|
|
setFolderHash(this.draftsFolder(), '');
|
2022-02-03 23:51:35 +08:00
|
|
|
}
|
2022-02-04 16:00:28 +08:00
|
|
|
setFolderHash(FolderUserStore.draftsFolder(), '');
|
2021-04-23 16:47:24 +08:00
|
|
|
}
|
2022-02-04 16:00:28 +08:00
|
|
|
}
|
2021-04-23 16:47:24 +08:00
|
|
|
|
2022-02-04 16:00:28 +08:00
|
|
|
if (!result) {
|
|
|
|
this.savedError(true);
|
|
|
|
this.savedErrorDesc(getNotification(Notification.CantSaveMessage));
|
|
|
|
}
|
2022-02-03 23:51:35 +08:00
|
|
|
|
2022-02-04 16:00:28 +08:00
|
|
|
this.reloadDraftFolder();
|
|
|
|
},
|
|
|
|
params,
|
|
|
|
200000
|
|
|
|
);
|
2022-02-07 18:32:53 +08:00
|
|
|
}).catch(e => {
|
|
|
|
this.saving(false);
|
|
|
|
this.savedError(true);
|
|
|
|
this.savedErrorDesc(getNotification(Notification.CantSaveMessage) + ': ' + e);
|
2022-02-04 16:00:28 +08:00
|
|
|
});
|
2016-09-10 06:38:16 +08:00
|
|
|
}
|
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-09-10 06:38:16 +08:00
|
|
|
deleteCommand() {
|
2022-02-04 16:49:55 +08:00
|
|
|
if (AskPopupView.hidden() && this.modalVisibility()) {
|
2021-01-26 05:00:13 +08:00
|
|
|
showScreenPopup(AskPopupView, [
|
2019-07-05 03:19:24 +08:00
|
|
|
i18n('POPUPS_ASK/DESC_WANT_DELETE_MESSAGES'),
|
|
|
|
() => {
|
|
|
|
if (this.modalVisibility()) {
|
2022-02-08 00:27:25 +08:00
|
|
|
const
|
|
|
|
sFromFolderFullName = this.draftsFolder(),
|
|
|
|
aUidForRemove = [this.draftUid()];
|
2022-02-24 02:26:52 +08:00
|
|
|
messagesDeleteHelper(sFromFolderFullName, aUidForRemove);
|
|
|
|
MessagelistUserStore.removeMessagesFromList(sFromFolderFullName, aUidForRemove);
|
2021-11-07 05:08:45 +08:00
|
|
|
this.closeCommand();
|
2019-07-05 03:19:24 +08:00
|
|
|
}
|
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() &&
|
2021-12-01 20:54:35 +08:00
|
|
|
!FolderUserStore.draftsFolderNotEnabled() &&
|
2021-03-11 05:41:35 +08:00
|
|
|
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();
|
2020-07-23 02:28:25 +08:00
|
|
|
setTimeout(() => {
|
2021-01-26 05:00:13 +08:00
|
|
|
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
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
autosaveStart() {
|
2020-07-30 03:49:41 +08:00
|
|
|
clearTimeout(this.iTimer);
|
2021-03-17 17:03:57 +08:00
|
|
|
this.iTimer = setTimeout(()=>{
|
|
|
|
if (this.modalVisibility()
|
2021-12-01 20:54:35 +08:00
|
|
|
&& !FolderUserStore.draftsFolderNotEnabled()
|
2021-03-17 17:03:57 +08:00
|
|
|
&& SettingsUserStore.allowDraftAutosave()
|
|
|
|
&& !this.isEmptyForm(false)
|
|
|
|
&& !this.saving()
|
|
|
|
&& !this.sending()
|
|
|
|
&& !this.savedError()
|
|
|
|
) {
|
|
|
|
this.saveCommand();
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2021-03-17 17:03:57 +08:00
|
|
|
this.autosaveStart();
|
|
|
|
}, 60000);
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2014-08-22 23:08:56 +08:00
|
|
|
|
2022-02-24 02:26:52 +08:00
|
|
|
// getAutocomplete
|
2016-08-17 06:01:20 +08:00
|
|
|
emailsSource(oData, fResponse) {
|
2022-02-24 06:11:12 +08:00
|
|
|
Remote.request('Suggestions',
|
|
|
|
(iError, data) => {
|
|
|
|
if (!iError && isArray(data.Result)) {
|
|
|
|
fResponse(
|
|
|
|
data.Result.map(item => (item && item[0] ? (new EmailModel(item[0], item[1])).toLine(false) : null))
|
|
|
|
.filter(v => v)
|
|
|
|
);
|
|
|
|
} else if (Notification.RequestAborted !== iError) {
|
|
|
|
fResponse([]);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Query: oData.term
|
|
|
|
// ,Page: 1
|
|
|
|
},
|
|
|
|
null,
|
|
|
|
'',
|
|
|
|
['Suggestions']
|
|
|
|
);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
reloadDraftFolder() {
|
2021-12-01 20:54:35 +08:00
|
|
|
const draftsFolder = FolderUserStore.draftsFolder();
|
|
|
|
if (draftsFolder && UNUSED_OPTION_VALUE !== draftsFolder) {
|
|
|
|
setFolderHash(draftsFolder, '');
|
|
|
|
if (FolderUserStore.currentFolderFullName() === draftsFolder) {
|
2022-02-24 02:26:52 +08:00
|
|
|
MessagelistUserStore.reload(true);
|
2019-07-05 03:19:24 +08:00
|
|
|
} else {
|
2021-12-01 20:54:35 +08:00
|
|
|
rl.app.folderInformation(draftsFolder);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2014-03-20 00:18:28 +08:00
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
findIdentityByMessage(composeType, message) {
|
2022-02-23 00:21:08 +08:00
|
|
|
let resultIdentity = null;
|
|
|
|
const find = addresses => {
|
|
|
|
addresses = addresses.map(item => item.email);
|
|
|
|
return IdentityUserStore.find(item => addresses.includes(item.email()));
|
|
|
|
};
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
if (message) {
|
|
|
|
switch (composeType) {
|
2016-08-17 06:01:20 +08:00
|
|
|
case ComposeType.Reply:
|
|
|
|
case ComposeType.ReplyAll:
|
|
|
|
case ComposeType.Forward:
|
|
|
|
case ComposeType.ForwardAsAttachment:
|
2022-02-23 00:21:08 +08:00
|
|
|
resultIdentity = find(message.to.concat(message.cc, message.bcc))/* || find(message.deliveredTo)*/;
|
2016-08-17 06:01:20 +08:00
|
|
|
break;
|
|
|
|
case ComposeType.Draft:
|
2022-02-23 00:21:08 +08:00
|
|
|
resultIdentity = find(message.from.concat(message.replyTo));
|
2016-08-17 06:01:20 +08:00
|
|
|
break;
|
|
|
|
// no default
|
2022-02-23 00:21:08 +08:00
|
|
|
// case ComposeType.Empty:
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2022-02-23 00:21:08 +08:00
|
|
|
return resultIdentity || IdentityUserStore()[0] || null;
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
selectIdentity(identity) {
|
2022-02-15 17:22:52 +08:00
|
|
|
identity = identity && identity.item;
|
|
|
|
if (identity) {
|
|
|
|
this.currentIdentity(identity);
|
|
|
|
this.setSignatureFromIdentity(identity);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
onHide() {
|
2021-03-17 17:03:57 +08:00
|
|
|
// Stop autosave
|
|
|
|
clearTimeout(this.iTimer);
|
2014-12-28 03:48:55 +08:00
|
|
|
|
2021-03-17 17:03:57 +08:00
|
|
|
AppUserStore.composeInEdit(this.bSkipNextHide);
|
|
|
|
|
|
|
|
this.bSkipNextHide || this.reset();
|
2014-12-28 03:48:55 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.bSkipNextHide = false;
|
2014-12-28 03:48:55 +08:00
|
|
|
|
2021-02-01 21:34:24 +08:00
|
|
|
this.to.focused(false);
|
2015-03-21 06:22:06 +08:00
|
|
|
|
2020-09-17 02:35:29 +08:00
|
|
|
rl.route.on();
|
2020-08-19 17:30:31 +08:00
|
|
|
|
2021-09-01 17:01:13 +08:00
|
|
|
(getFullscreenElement() === this.oContent) && exitFullscreen();
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2022-02-03 23:51:35 +08:00
|
|
|
dropMailvelope() {
|
|
|
|
if (this.mailvelope) {
|
|
|
|
elementById('mailvelope-editor').textContent = '';
|
|
|
|
this.mailvelope = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
editor(fOnInit) {
|
2022-02-03 23:51:35 +08:00
|
|
|
if (fOnInit && this.editorArea()) {
|
2021-03-12 18:41:44 +08:00
|
|
|
if (this.oEditor) {
|
|
|
|
fOnInit(this.oEditor);
|
|
|
|
} else {
|
2020-07-23 02:28:25 +08:00
|
|
|
// setTimeout(() => {
|
2019-07-05 03:19:24 +08:00
|
|
|
this.oEditor = new HtmlEditor(
|
2022-02-03 23:51:35 +08:00
|
|
|
this.editorArea(),
|
2019-07-05 03:19:24 +08:00
|
|
|
null,
|
2020-09-09 23:03:44 +08:00
|
|
|
() => fOnInit(this.oEditor),
|
|
|
|
bHtml => this.isHtml(!!bHtml)
|
2019-07-05 03:19:24 +08:00
|
|
|
);
|
2017-06-25 03:26:27 +08:00
|
|
|
// }, 1000);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
|
|
|
}
|
2014-02-07 07:22:39 +08:00
|
|
|
|
2017-07-06 06:31:41 +08:00
|
|
|
setSignatureFromIdentity(identity) {
|
2019-07-05 03:19:24 +08:00
|
|
|
if (identity) {
|
2021-02-02 19:23:32 +08:00
|
|
|
this.editor(editor => {
|
2022-02-04 20:40:59 +08:00
|
|
|
let signature = identity.signature() || '',
|
|
|
|
isHtml = ':HTML:' === signature.slice(0, 6),
|
|
|
|
fromLine = this.oLastMessage ? this.emailArrayToStringLineHelper(this.oLastMessage.from, true) : '';
|
|
|
|
if (fromLine) {
|
|
|
|
signature = signature.replace(/{{FROM-FULL}}/g, fromLine);
|
|
|
|
if (!fromLine.includes(' ') && 0 < fromLine.indexOf('@')) {
|
|
|
|
fromLine = fromLine.replace(/@\S+/, '');
|
|
|
|
}
|
|
|
|
signature = signature.replace(/{{FROM}}/g, fromLine);
|
|
|
|
}
|
|
|
|
signature = (isHtml ? signature.slice(6) : 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, '');
|
|
|
|
editor.setSignature(signature, isHtml, !!identity.signatureInsertBefore());
|
2016-08-17 06:01:20 +08:00
|
|
|
});
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
|
|
|
|
2016-08-17 06:01:20 +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) {
|
2020-09-17 02:35:29 +08:00
|
|
|
rl.route.off();
|
2014-08-14 21:09:42 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.autosaveStart();
|
2014-12-28 03:48:55 +08:00
|
|
|
|
2021-08-17 00:09:54 +08:00
|
|
|
this.viewModelDom.dataset.wysiwyg = SettingsUserStore.editorDefaultType();
|
|
|
|
|
2021-03-11 05:41:35 +08:00
|
|
|
if (AppUserStore.composeInEdit()) {
|
2016-08-17 06:01:20 +08:00
|
|
|
type = type || ComposeType.Empty;
|
2019-07-05 03:19:24 +08:00
|
|
|
if (ComposeType.Empty !== type) {
|
2021-01-26 05:00:13 +08:00
|
|
|
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,
|
|
|
|
false
|
|
|
|
]);
|
|
|
|
} else {
|
2016-08-17 06:01:20 +08:00
|
|
|
this.addEmailsTo(this.to, aToEmails);
|
|
|
|
this.addEmailsTo(this.cc, aCcEmails);
|
|
|
|
this.addEmailsTo(this.bcc, aBccEmails);
|
|
|
|
|
2020-08-18 03:57:56 +08:00
|
|
|
if (sCustomSubject && !this.subject()) {
|
2016-08-17 06:01:20 +08:00
|
|
|
this.subject(sCustomSubject);
|
|
|
|
}
|
|
|
|
}
|
2019-07-05 03:19:24 +08:00
|
|
|
} else {
|
2016-08-17 06:01:20 +08:00
|
|
|
this.initOnShow(type, oMessageOrArray, aToEmails, aCcEmails, aBccEmails, sCustomSubject, sCustomPlainText);
|
2014-12-28 03:48:55 +08:00
|
|
|
}
|
2021-07-16 03:01:41 +08:00
|
|
|
|
2021-07-16 22:24:07 +08:00
|
|
|
// (navigator.standalone || matchMedia('(display-mode: standalone)').matches || matchMedia('(display-mode: fullscreen)').matches) &&
|
2021-07-16 03:01:41 +08:00
|
|
|
ThemeStore.isMobile() && this.oContent.requestFullscreen && this.oContent.requestFullscreen();
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2014-12-31 20:21:43 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
/**
|
|
|
|
* @param {Function} fKoValue
|
|
|
|
* @param {Array} emails
|
|
|
|
*/
|
|
|
|
addEmailsTo(fKoValue, emails) {
|
2021-07-22 03:34:17 +08:00
|
|
|
if (arrayLength(emails)) {
|
2020-08-07 00:24:46 +08:00
|
|
|
const value = fKoValue().trim(),
|
2020-07-23 22:06:16 +08:00
|
|
|
values = emails.map(item => item ? item.toLine(false) : null)
|
2020-10-03 05:54:15 +08:00
|
|
|
.validUnique();
|
2015-02-08 09:11:13 +08:00
|
|
|
|
2020-08-07 00:24:46 +08:00
|
|
|
fKoValue(value + (value ? ', ' : '') + values.join(', ').trim());
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2015-02-08 09:11:13 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {Array} aList
|
|
|
|
* @param {boolean} bFriendly
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
emailArrayToStringLineHelper(aList, bFriendly) {
|
|
|
|
bFriendly = !!bFriendly;
|
2020-07-23 02:09:31 +08:00
|
|
|
return aList.map(item => item.toLine(bFriendly)).join(', ');
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2014-12-28 03:48:55 +08:00
|
|
|
|
2021-02-02 19:23:32 +08:00
|
|
|
isPlainEditor() {
|
2021-08-17 00:09:54 +08:00
|
|
|
let type = SettingsUserStore.editorDefaultType();
|
2021-02-02 19:23:32 +08:00
|
|
|
return EditorDefaultType.Html !== type && EditorDefaultType.HtmlForced !== type;
|
|
|
|
}
|
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
/**
|
|
|
|
* @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 = '',
|
2016-08-17 06:01:20 +08:00
|
|
|
sTo = '',
|
|
|
|
sCc = '',
|
|
|
|
sDate = '',
|
|
|
|
sSubject = '',
|
|
|
|
sText = '',
|
|
|
|
identity = null,
|
|
|
|
aDraftInfo = null,
|
|
|
|
message = null;
|
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
const excludeEmail = {},
|
2021-03-11 05:41:35 +08:00
|
|
|
mEmail = AccountUserStore.email(),
|
2016-08-17 06:01:20 +08:00
|
|
|
lineComposeType = sType || ComposeType.Empty;
|
|
|
|
|
|
|
|
oMessageOrArray = oMessageOrArray || null;
|
2020-08-18 03:57:56 +08:00
|
|
|
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;
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.oLastMessage = message;
|
2015-02-08 09:11:13 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
if (null !== mEmail) {
|
2016-08-17 06:01:20 +08:00
|
|
|
excludeEmail[mEmail] = true;
|
|
|
|
}
|
2014-05-24 06:37:10 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.reset();
|
2015-02-08 09:11:13 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
identity = this.findIdentityByMessage(lineComposeType, message);
|
2019-07-05 03:19:24 +08:00
|
|
|
if (identity) {
|
2016-08-17 06:01:20 +08:00
|
|
|
excludeEmail[identity.email()] = true;
|
2014-08-21 23:08:34 +08:00
|
|
|
}
|
|
|
|
|
2021-07-22 03:34:17 +08:00
|
|
|
if (arrayLength(aToEmails)) {
|
2016-08-17 06:01:20 +08:00
|
|
|
this.to(this.emailArrayToStringLineHelper(aToEmails));
|
2015-02-01 03:00:10 +08:00
|
|
|
}
|
|
|
|
|
2021-07-22 03:34:17 +08:00
|
|
|
if (arrayLength(aCcEmails)) {
|
2016-08-17 06:01:20 +08:00
|
|
|
this.cc(this.emailArrayToStringLineHelper(aCcEmails));
|
2015-02-01 03:00:10 +08:00
|
|
|
}
|
|
|
|
|
2021-07-22 03:34:17 +08:00
|
|
|
if (arrayLength(aBccEmails)) {
|
2016-08-17 06:01:20 +08:00
|
|
|
this.bcc(this.emailArrayToStringLineHelper(aBccEmails));
|
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2020-07-28 23:20:14 +08:00
|
|
|
if (lineComposeType && message) {
|
2021-01-27 07:26:31 +08:00
|
|
|
sDate = timestampToString(message.dateTimeStampInUTC(), 'FULL');
|
2016-08-17 06:01:20 +08:00
|
|
|
sSubject = message.subject();
|
|
|
|
aDraftInfo = message.aDraftInfo;
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
let resplyAllParts = null;
|
2019-07-05 03:19:24 +08:00
|
|
|
switch (lineComposeType) {
|
2016-08-17 06:01:20 +08:00
|
|
|
case ComposeType.Empty:
|
|
|
|
break;
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
case ComposeType.Reply:
|
|
|
|
this.to(this.emailArrayToStringLineHelper(message.replyEmails(excludeEmail)));
|
|
|
|
this.subject(replySubjectAdd('Re', sSubject));
|
2020-09-23 17:20:18 +08:00
|
|
|
this.prepareMessageAttachments(message, lineComposeType);
|
2020-10-23 21:15:54 +08:00
|
|
|
this.aDraftInfo = ['reply', message.uid, message.folder];
|
2016-08-17 06:01:20 +08:00
|
|
|
this.sInReplyTo = message.sMessageId;
|
2020-08-07 00:24:46 +08:00
|
|
|
this.sReferences = (this.sInReplyTo + ' ' + message.sReferences).trim();
|
2016-08-17 06:01:20 +08:00
|
|
|
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));
|
2020-09-23 17:20:18 +08:00
|
|
|
this.prepareMessageAttachments(message, lineComposeType);
|
2020-10-23 21:15:54 +08:00
|
|
|
this.aDraftInfo = ['reply', message.uid, message.folder];
|
2016-08-17 06:01:20 +08:00
|
|
|
this.sInReplyTo = message.sMessageId;
|
2020-10-23 21:15:54 +08:00
|
|
|
this.sReferences = (this.sInReplyTo + ' ' + message.references).trim();
|
2016-08-17 06:01:20 +08:00
|
|
|
break;
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
case ComposeType.Forward:
|
|
|
|
this.subject(replySubjectAdd('Fwd', sSubject));
|
2020-09-23 17:20:18 +08:00
|
|
|
this.prepareMessageAttachments(message, lineComposeType);
|
2020-10-23 21:15:54 +08:00
|
|
|
this.aDraftInfo = ['forward', message.uid, message.folder];
|
2016-08-17 06:01:20 +08:00
|
|
|
this.sInReplyTo = message.sMessageId;
|
2020-08-07 00:24:46 +08:00
|
|
|
this.sReferences = (this.sInReplyTo + ' ' + message.sReferences).trim();
|
2016-08-17 06:01:20 +08:00
|
|
|
break;
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
case ComposeType.ForwardAsAttachment:
|
|
|
|
this.subject(replySubjectAdd('Fwd', sSubject));
|
2020-09-23 17:20:18 +08:00
|
|
|
this.prepareMessageAttachments(message, lineComposeType);
|
2020-10-23 21:15:54 +08:00
|
|
|
this.aDraftInfo = ['forward', message.uid, message.folder];
|
2016-08-17 06:01:20 +08:00
|
|
|
this.sInReplyTo = message.sMessageId;
|
2020-08-07 00:24:46 +08:00
|
|
|
this.sReferences = (this.sInReplyTo + ' ' + message.sReferences).trim();
|
2016-08-17 06:01:20 +08:00
|
|
|
break;
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
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));
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.bFromDraft = true;
|
2014-08-12 20:32:08 +08:00
|
|
|
|
2021-12-01 20:54:35 +08:00
|
|
|
this.draftsFolder(message.folder);
|
2016-08-17 06:01:20 +08:00
|
|
|
this.draftUid(message.uid);
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.subject(sSubject);
|
2020-09-23 17:20:18 +08:00
|
|
|
this.prepareMessageAttachments(message, lineComposeType);
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2021-07-22 03:34:17 +08:00
|
|
|
this.aDraftInfo = 3 === arrayLength(aDraftInfo) ? aDraftInfo : null;
|
2016-08-17 06:01:20 +08:00
|
|
|
this.sInReplyTo = message.sInReplyTo;
|
|
|
|
this.sReferences = message.sReferences;
|
|
|
|
break;
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
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));
|
2014-02-07 07:22:39 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.subject(sSubject);
|
2020-09-23 17:20:18 +08:00
|
|
|
this.prepareMessageAttachments(message, lineComposeType);
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2021-07-22 03:34:17 +08:00
|
|
|
this.aDraftInfo = 3 === arrayLength(aDraftInfo) ? aDraftInfo : null;
|
2016-08-17 06:01:20 +08:00
|
|
|
this.sInReplyTo = message.sInReplyTo;
|
|
|
|
this.sReferences = message.sReferences;
|
|
|
|
break;
|
|
|
|
// no default
|
2014-08-21 23:08:34 +08:00
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2022-02-04 20:40:59 +08:00
|
|
|
sText = message.bodyAsHTML();
|
|
|
|
let encrypted;
|
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
switch (lineComposeType) {
|
2016-08-17 06:01:20 +08:00
|
|
|
case ComposeType.Reply:
|
|
|
|
case ComposeType.ReplyAll:
|
|
|
|
sFrom = message.fromToLine(false, true);
|
2022-02-04 20:40:59 +08:00
|
|
|
sText = '<div><p>' + i18n('COMPOSE/REPLY_MESSAGE_TITLE', { DATETIME: sDate, EMAIL: sFrom })
|
|
|
|
+ ':</p><blockquote>'
|
|
|
|
+ sText.replace(/<img[^>]+>/g, '').replace(/<a\s[^>]+><\/a>/g, '').trim()
|
|
|
|
+ '</blockquote></div>';
|
2016-08-17 06:01:20 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ComposeType.Forward:
|
|
|
|
sFrom = message.fromToLine(false, true);
|
|
|
|
sTo = message.toToLine(false, true);
|
|
|
|
sCc = message.ccToLine(false, true);
|
2022-02-04 20:40:59 +08:00
|
|
|
sText = '<div><p>' + i18n('COMPOSE/FORWARD_MESSAGE_TOP_TITLE') + '</p>'
|
|
|
|
+ i18n('GLOBAL/FROM') + ': ' + sFrom
|
|
|
|
+ '<br>'
|
|
|
|
+ i18n('GLOBAL/TO') + ': ' + sTo
|
|
|
|
+ (sCc.length ? '<br>' + i18n('GLOBAL/CC') + ': ' + sCc : '')
|
|
|
|
+ '<br>'
|
|
|
|
+ i18n('COMPOSE/FORWARD_MESSAGE_TOP_SENT')
|
|
|
|
+ ': '
|
|
|
|
+ encodeHtml(sDate)
|
|
|
|
+ '<br>'
|
|
|
|
+ i18n('GLOBAL/SUBJECT')
|
|
|
|
+ ': '
|
|
|
|
+ encodeHtml(sSubject)
|
|
|
|
+ '<br><br>'
|
|
|
|
+ sText.trim()
|
|
|
|
+ '</div>';
|
2016-08-17 06:01:20 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ComposeType.ForwardAsAttachment:
|
|
|
|
sText = '';
|
|
|
|
break;
|
2022-02-04 20:40:59 +08:00
|
|
|
default:
|
|
|
|
encrypted = PgpUserStore.isEncrypted(sText);
|
|
|
|
if (encrypted) {
|
|
|
|
sText = message.plain();
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2021-02-02 19:23:32 +08:00
|
|
|
this.editor(editor => {
|
2022-02-04 20:40:59 +08:00
|
|
|
encrypted || editor.setHtml(sText);
|
2014-08-12 21:51:34 +08:00
|
|
|
|
2022-02-04 20:40:59 +08:00
|
|
|
if (encrypted
|
|
|
|
|| EditorDefaultType.PlainForced === SettingsUserStore.editorDefaultType()
|
|
|
|
|| (!message.isHtml() && EditorDefaultType.HtmlForced !== SettingsUserStore.editorDefaultType())
|
2019-07-05 03:19:24 +08:00
|
|
|
) {
|
2021-02-02 19:23:32 +08:00
|
|
|
editor.modePlain();
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2015-02-08 09:11:13 +08:00
|
|
|
|
2022-02-04 20:40:59 +08:00
|
|
|
!encrypted || editor.setPlain(sText);
|
|
|
|
|
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);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2015-02-08 09:11:13 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.setFocusInPopup();
|
|
|
|
});
|
2019-07-05 03:19:24 +08:00
|
|
|
} else if (ComposeType.Empty === lineComposeType) {
|
2020-08-18 03:57:56 +08:00
|
|
|
this.subject(null != sCustomSubject ? '' + sCustomSubject : '');
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2020-08-18 03:57:56 +08:00
|
|
|
sText = null != sCustomPlainText ? '' + sCustomPlainText : '';
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2021-02-02 19:23:32 +08:00
|
|
|
this.editor(editor => {
|
|
|
|
editor.setHtml(sText);
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2021-02-02 19:23:32 +08:00
|
|
|
if (this.isPlainEditor()) {
|
|
|
|
editor.modePlain();
|
2015-02-08 09:11:13 +08:00
|
|
|
}
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
if (identity) {
|
2017-07-06 06:31:41 +08:00
|
|
|
this.setSignatureFromIdentity(identity);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
this.setFocusInPopup();
|
2016-08-10 01:27:04 +08:00
|
|
|
});
|
2021-07-22 03:34:17 +08:00
|
|
|
} else if (arrayLength(oMessageOrArray)) {
|
2021-02-02 19:23:32 +08:00
|
|
|
oMessageOrArray.forEach(item => this.addMessageAsAttachment(item));
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2021-02-02 19:23:32 +08:00
|
|
|
this.editor(editor => {
|
|
|
|
if (this.isPlainEditor()) {
|
|
|
|
editor.setPlain('')
|
|
|
|
} else {
|
|
|
|
editor.setHtml('');
|
2015-02-08 09:11:13 +08:00
|
|
|
}
|
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);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2015-02-08 09:11:13 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.setFocusInPopup();
|
|
|
|
});
|
2019-07-05 03:19:24 +08:00
|
|
|
} else {
|
2016-08-17 06:01:20 +08:00
|
|
|
this.setFocusInPopup();
|
|
|
|
}
|
2015-02-08 09:11:13 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
const downloads = this.getAttachmentsDownloadsForUpload();
|
2021-07-22 03:34:17 +08:00
|
|
|
if (arrayLength(downloads)) {
|
2021-12-03 06:15:24 +08:00
|
|
|
Remote.request('MessageUploadAttachments',
|
|
|
|
(iError, oData) => {
|
|
|
|
if (!iError) {
|
|
|
|
forEachObjectEntry(oData.Result, (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));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Attachments: downloads
|
|
|
|
},
|
|
|
|
999000
|
|
|
|
);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2015-02-26 22:47:37 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
if (identity) {
|
2016-08-17 06:01:20 +08:00
|
|
|
this.currentIdentity(identity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setFocusInPopup() {
|
2020-09-30 18:31:34 +08:00
|
|
|
setTimeout(() => {
|
|
|
|
if (!this.to()) {
|
2021-02-01 21:34:24 +08:00
|
|
|
this.to.focused(true);
|
2021-03-12 18:41:44 +08:00
|
|
|
} else if (!this.to.focused()) {
|
|
|
|
this.oEditor && this.oEditor.focus();
|
2020-09-30 18:31:34 +08:00
|
|
|
}
|
|
|
|
}, 100);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
tryToClosePopup() {
|
2022-02-04 16:49:55 +08:00
|
|
|
if (AskPopupView.hidden() && this.modalVisibility()) {
|
2019-07-05 03:19:24 +08:00
|
|
|
if (this.bSkipNextHide || (this.isEmptyForm() && !this.draftUid())) {
|
2021-07-16 03:01:41 +08:00
|
|
|
this.closeCommand();
|
2019-07-05 03:19:24 +08:00
|
|
|
} else {
|
2021-01-26 05:00:13 +08:00
|
|
|
showScreenPopup(AskPopupView, [
|
2019-07-05 03:19:24 +08:00
|
|
|
i18n('POPUPS_ASK/DESC_WANT_CLOSE_THIS_WINDOW'),
|
2021-11-07 05:08:45 +08:00
|
|
|
() => this.closeCommand()
|
2019-07-05 03:19:24 +08:00
|
|
|
]);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2015-03-14 07:10:00 +08:00
|
|
|
}
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2016-07-01 06:50:11 +08:00
|
|
|
|
2020-10-09 21:00:26 +08:00
|
|
|
popupMenu(event) {
|
|
|
|
if (event.ctrlKey || event.metaKey || 'ContextMenu' == event.key
|
|
|
|
|| (this.oEditor && !this.oEditor.hasFocus() && !inFocus())) {
|
|
|
|
this.identitiesDropdownTrigger(true);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-04 23:21:29 +08:00
|
|
|
onBuild(dom) {
|
2021-08-13 02:17:37 +08:00
|
|
|
// initUploader
|
2022-02-04 23:21:29 +08:00
|
|
|
const oJua = new Jua({
|
|
|
|
action: serverRequest('Upload'),
|
|
|
|
clickElement: dom.querySelector('#composeUploadButton'),
|
|
|
|
dragAndDropElement: dom.querySelector('.b-attachment-place')
|
|
|
|
}),
|
|
|
|
uploadCache = {},
|
|
|
|
attachmentSizeLimit = pInt(SettingsGet('AttachmentLimit'));
|
|
|
|
|
|
|
|
oJua
|
|
|
|
// .on('onLimitReached', (limit) => {
|
|
|
|
// alert(limit);
|
|
|
|
// })
|
|
|
|
.on('onDragEnter', () => {
|
|
|
|
this.dragAndDropOver(true);
|
|
|
|
})
|
|
|
|
.on('onDragLeave', () => {
|
|
|
|
this.dragAndDropOver(false);
|
|
|
|
})
|
|
|
|
.on('onBodyDragEnter', () => {
|
|
|
|
this.attachmentsArea();
|
|
|
|
this.dragAndDropVisible(true);
|
|
|
|
})
|
|
|
|
.on('onBodyDragLeave', () => {
|
|
|
|
this.dragAndDropVisible(false);
|
|
|
|
})
|
|
|
|
.on('onProgress', (id, loaded, total) => {
|
|
|
|
let item = uploadCache[id];
|
|
|
|
if (!item) {
|
|
|
|
item = this.getAttachmentById(id);
|
2021-08-13 02:17:37 +08:00
|
|
|
if (item) {
|
2022-02-04 23:21:29 +08:00
|
|
|
uploadCache[id] = item;
|
2021-08-13 02:17:37 +08:00
|
|
|
}
|
2022-02-04 23:21:29 +08:00
|
|
|
}
|
2021-08-13 02:17:37 +08:00
|
|
|
|
2022-02-04 23:21:29 +08:00
|
|
|
if (item) {
|
|
|
|
item.progress(Math.floor((loaded / total) * 100));
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.on('onSelect', (sId, oData) => {
|
|
|
|
this.dragAndDropOver(false);
|
2021-08-13 02:17:37 +08:00
|
|
|
|
2022-02-04 23:21:29 +08:00
|
|
|
const fileName = undefined === oData.FileName ? '' : oData.FileName.toString(),
|
|
|
|
size = pInt(oData.Size, null),
|
|
|
|
attachment = new ComposeAttachmentModel(sId, fileName, size);
|
2021-08-13 02:17:37 +08:00
|
|
|
|
2022-02-04 23:21:29 +08:00
|
|
|
attachment.cancel = this.cancelAttachmentHelper(sId, oJua);
|
2021-08-13 02:17:37 +08:00
|
|
|
|
2022-02-04 23:21:29 +08:00
|
|
|
this.attachments.push(attachment);
|
2021-08-13 02:17:37 +08:00
|
|
|
|
2022-02-04 23:21:29 +08:00
|
|
|
this.attachmentsArea();
|
2021-08-13 02:17:37 +08:00
|
|
|
|
2022-02-04 23:21:29 +08:00
|
|
|
if (0 < size && 0 < attachmentSizeLimit && attachmentSizeLimit < size) {
|
|
|
|
attachment
|
|
|
|
.waiting(false)
|
|
|
|
.uploading(true)
|
|
|
|
.complete(true)
|
|
|
|
.error(i18n('UPLOAD/ERROR_FILE_IS_TOO_BIG'));
|
2021-08-13 02:17:37 +08:00
|
|
|
|
2022-02-04 23:21:29 +08:00
|
|
|
return false;
|
|
|
|
}
|
2021-08-13 02:17:37 +08:00
|
|
|
|
2022-02-04 23:21:29 +08:00
|
|
|
return true;
|
|
|
|
})
|
|
|
|
.on('onStart', (id) => {
|
|
|
|
let item = uploadCache[id];
|
|
|
|
if (!item) {
|
|
|
|
item = this.getAttachmentById(id);
|
2021-08-13 02:17:37 +08:00
|
|
|
if (item) {
|
2022-02-04 23:21:29 +08:00
|
|
|
uploadCache[id] = item;
|
2021-08-13 02:17:37 +08:00
|
|
|
}
|
2022-02-04 23:21:29 +08:00
|
|
|
}
|
2021-08-13 02:17:37 +08:00
|
|
|
|
2022-02-04 23:21:29 +08:00
|
|
|
if (item) {
|
|
|
|
item
|
|
|
|
.waiting(false)
|
|
|
|
.uploading(true)
|
|
|
|
.complete(false);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.on('onComplete', (id, result, data) => {
|
|
|
|
const attachment = this.getAttachmentById(id),
|
|
|
|
response = (data && data.Result) || {},
|
|
|
|
errorCode = response.ErrorCode,
|
|
|
|
attachmentJson = result && response.Attachment;
|
|
|
|
|
|
|
|
let error = '';
|
|
|
|
if (null != errorCode) {
|
|
|
|
error = getUploadErrorDescByCode(errorCode);
|
|
|
|
} else if (!attachmentJson) {
|
|
|
|
error = i18n('UPLOAD/ERROR_UNKNOWN');
|
|
|
|
}
|
2021-08-13 02:17:37 +08:00
|
|
|
|
2022-02-04 23:21:29 +08:00
|
|
|
if (attachment) {
|
|
|
|
if (error) {
|
|
|
|
attachment
|
|
|
|
.waiting(false)
|
|
|
|
.uploading(false)
|
|
|
|
.complete(true)
|
|
|
|
.error(error + '\n' + response.ErrorMessage);
|
|
|
|
} else if (attachmentJson) {
|
|
|
|
attachment
|
|
|
|
.waiting(false)
|
|
|
|
.uploading(false)
|
|
|
|
.complete(true);
|
|
|
|
|
|
|
|
attachment.initByUploadJson(attachmentJson);
|
2021-08-13 02:17:37 +08:00
|
|
|
}
|
|
|
|
|
2022-02-04 23:21:29 +08:00
|
|
|
if (undefined === uploadCache[id]) {
|
|
|
|
delete uploadCache[id];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this.addAttachmentEnabled(true);
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2022-02-24 18:19:19 +08:00
|
|
|
shortcuts.add('q', 'meta', ScopeCompose, ()=>false);
|
|
|
|
shortcuts.add('w', 'meta', ScopeCompose, ()=>false);
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2022-02-24 18:19:19 +08:00
|
|
|
shortcuts.add('contextmenu', '', ScopeCompose, e => this.popupMenu(e));
|
|
|
|
shortcuts.add('m', 'meta', ScopeCompose, e => this.popupMenu(e));
|
2015-03-14 07:10:00 +08:00
|
|
|
|
2022-02-24 18:19:19 +08:00
|
|
|
shortcuts.add('escape,close', '', ScopeCompose, () => {
|
2020-09-26 06:02:29 +08:00
|
|
|
this.skipCommand();
|
|
|
|
return false;
|
|
|
|
});
|
2022-02-24 18:19:19 +08:00
|
|
|
shortcuts.add('arrowdown', 'meta', ScopeCompose, () => {
|
2016-08-17 06:01:20 +08:00
|
|
|
this.skipCommand();
|
2016-06-30 08:02:45 +08:00
|
|
|
return false;
|
|
|
|
});
|
2015-03-21 06:22:06 +08:00
|
|
|
|
2022-02-24 18:19:19 +08:00
|
|
|
shortcuts.add('s', 'meta', ScopeCompose, () => {
|
2021-03-06 17:07:54 +08:00
|
|
|
this.saveCommand();
|
|
|
|
return false;
|
|
|
|
});
|
2022-02-24 18:19:19 +08:00
|
|
|
shortcuts.add('save', '', ScopeCompose, () => {
|
2021-03-06 17:07:54 +08:00
|
|
|
this.saveCommand();
|
|
|
|
return false;
|
|
|
|
});
|
2014-02-12 08:08:31 +08:00
|
|
|
|
2020-09-04 18:05:17 +08:00
|
|
|
if (Settings.app('allowCtrlEnterOnCompose')) {
|
2022-02-24 18:19:19 +08:00
|
|
|
shortcuts.add('enter', 'meta', ScopeCompose, () => {
|
2016-08-17 06:01:20 +08:00
|
|
|
this.sendCommand();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
2022-02-24 18:19:19 +08:00
|
|
|
shortcuts.add('mailsend', '', ScopeCompose, () => {
|
2020-10-09 16:31:44 +08:00
|
|
|
this.sendCommand();
|
|
|
|
return false;
|
|
|
|
});
|
2013-12-14 07:27:12 +08:00
|
|
|
|
2022-02-24 18:19:19 +08:00
|
|
|
shortcuts.add('escape,close', 'shift', ScopeCompose, () => {
|
2020-10-09 16:31:44 +08:00
|
|
|
this.modalVisibility() && this.tryToClosePopup();
|
2016-08-17 06:01:20 +08:00
|
|
|
return false;
|
2015-08-31 02:12:51 +08:00
|
|
|
});
|
2020-09-02 15:32:28 +08:00
|
|
|
|
2021-08-17 00:09:54 +08:00
|
|
|
this.editor(editor => editor[this.isPlainEditor()?'modePlain':'modeWysiwyg']());
|
2021-07-16 03:01:41 +08:00
|
|
|
|
|
|
|
// Fullscreen must be on app, else other popups fail
|
|
|
|
const el = doc.getElementById('rl-app');
|
2021-11-16 20:15:02 +08:00
|
|
|
this.oContent = initFullscreen(el, () =>
|
|
|
|
ThemeStore.isMobile()
|
|
|
|
&& this.modalVisibility()
|
|
|
|
&& (getFullscreenElement() !== el)
|
|
|
|
&& this.skipCommand()
|
|
|
|
);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} id
|
|
|
|
* @returns {?Object}
|
|
|
|
*/
|
|
|
|
getAttachmentById(id) {
|
2021-01-22 19:23:20 +08:00
|
|
|
return this.attachments.find(item => item && id === item.id);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2014-10-04 19:58:01 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
cancelAttachmentHelper(id, oJua) {
|
|
|
|
return () => {
|
2020-09-15 21:08:08 +08:00
|
|
|
const attachment = this.getAttachmentById(id);
|
2019-07-05 03:19:24 +08:00
|
|
|
if (attachment) {
|
2016-08-17 06:01:20 +08:00
|
|
|
this.attachments.remove(attachment);
|
2020-10-26 19:54:03 +08:00
|
|
|
oJua && oJua.cancel(id);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2014-10-04 19:58:01 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
/**
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
2022-01-20 16:59:56 +08:00
|
|
|
prepareAttachmentsForSendOrSave() {
|
2016-08-17 06:01:20 +08:00
|
|
|
const result = {};
|
2021-03-08 22:21:54 +08:00
|
|
|
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-08-17 06:01:20 +08:00
|
|
|
}
|
|
|
|
});
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
return result;
|
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
/**
|
|
|
|
* @param {MessageModel} message
|
|
|
|
*/
|
|
|
|
addMessageAsAttachment(message) {
|
2019-07-05 03:19:24 +08:00
|
|
|
if (message) {
|
2016-08-17 06:01:20 +08:00
|
|
|
let temp = message.subject();
|
2021-12-08 18:35:41 +08:00
|
|
|
temp = '.eml' === temp.slice(-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());
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
attachment.fromMessage = true;
|
|
|
|
attachment.cancel = this.cancelAttachmentHelper(message.requestHash);
|
2019-07-05 03:19:24 +08:00
|
|
|
attachment
|
|
|
|
.waiting(false)
|
|
|
|
.uploading(true)
|
|
|
|
.complete(true);
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.attachments.push(attachment);
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2015-01-05 03:30:07 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
/**
|
|
|
|
* @param {string} url
|
|
|
|
* @param {string} name
|
|
|
|
* @param {number} size
|
|
|
|
* @returns {ComposeAttachmentModel}
|
|
|
|
*/
|
|
|
|
addAttachmentHelper(url, name, size) {
|
|
|
|
const attachment = new ComposeAttachmentModel(url, name, size);
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
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
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.attachments.push(attachment);
|
2014-07-29 18:28:02 +08:00
|
|
|
|
2022-02-03 23:51:35 +08:00
|
|
|
this.attachmentsArea();
|
2016-08-10 02:58:34 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
return attachment;
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
/**
|
|
|
|
* @param {MessageModel} message
|
|
|
|
* @param {string} type
|
|
|
|
*/
|
2020-09-23 17:20:18 +08:00
|
|
|
prepareMessageAttachments(message, type) {
|
2019-07-05 03:19:24 +08:00
|
|
|
if (message) {
|
|
|
|
if (ComposeType.ForwardAsAttachment === type) {
|
2016-08-17 06:01:20 +08:00
|
|
|
this.addMessageAsAttachment(message);
|
2019-07-05 03:19:24 +08:00
|
|
|
} else {
|
2021-01-22 19:23:20 +08:00
|
|
|
message.attachments.forEach(item => {
|
2016-08-17 06:01:20 +08:00
|
|
|
let add = false;
|
2019-07-05 03:19:24 +08:00
|
|
|
switch (type) {
|
2016-08-17 06:01:20 +08:00
|
|
|
case ComposeType.Reply:
|
|
|
|
case ComposeType.ReplyAll:
|
|
|
|
break;
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
case ComposeType.Forward:
|
|
|
|
case ComposeType.Draft:
|
|
|
|
case ComposeType.EditAsNew:
|
|
|
|
add = true;
|
|
|
|
break;
|
|
|
|
// no default
|
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
if (add) {
|
2020-09-19 19:53:14 +08:00
|
|
|
const attachment = ComposeAttachmentModel.fromAttachment(item);
|
2016-08-17 06:01:20 +08:00
|
|
|
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
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.attachments.push(attachment);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
/**
|
|
|
|
* @param {boolean=} includeAttachmentInProgress = true
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
isEmptyForm(includeAttachmentInProgress = true) {
|
2019-07-05 03:19:24 +08:00
|
|
|
const withoutAttachment = includeAttachmentInProgress
|
2021-01-22 19:23:20 +08:00
|
|
|
? !this.attachments.length
|
2021-03-08 22:21:54 +08:00
|
|
|
: !this.attachments.some(item => item && item.complete());
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
return (
|
2021-01-22 19:23:20 +08:00
|
|
|
!this.to.length &&
|
|
|
|
!this.cc.length &&
|
|
|
|
!this.bcc.length &&
|
|
|
|
!this.replyTo.length &&
|
|
|
|
!this.subject.length &&
|
2016-08-17 06:01:20 +08:00
|
|
|
withoutAttachment &&
|
2020-07-28 23:20:14 +08:00
|
|
|
(!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
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
reset() {
|
|
|
|
this.to('');
|
|
|
|
this.cc('');
|
|
|
|
this.bcc('');
|
|
|
|
this.replyTo('');
|
|
|
|
this.subject('');
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.requestDsn(false);
|
|
|
|
this.requestReadReceipt(false);
|
|
|
|
this.markAsImportant(false);
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2022-02-03 23:51:35 +08:00
|
|
|
this.bodyArea();
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.aDraftInfo = null;
|
|
|
|
this.sInReplyTo = '';
|
|
|
|
this.bFromDraft = false;
|
|
|
|
this.sReferences = '';
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +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
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.showCc(false);
|
|
|
|
this.showBcc(false);
|
|
|
|
this.showReplyTo(false);
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2022-01-20 01:24:07 +08:00
|
|
|
this.pgpSign(false);
|
|
|
|
this.pgpEncrypt(false);
|
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.attachments([]);
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.dragAndDropOver(false);
|
|
|
|
this.dragAndDropVisible(false);
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2021-12-01 20:54:35 +08:00
|
|
|
this.draftsFolder('');
|
2021-09-10 22:28:29 +08:00
|
|
|
this.draftUid(0);
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.sending(false);
|
|
|
|
this.saving(false);
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2021-03-12 18:41:44 +08:00
|
|
|
this.oEditor && this.oEditor.clear();
|
2022-02-03 23:51:35 +08:00
|
|
|
|
|
|
|
this.dropMailvelope();
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
/**
|
|
|
|
* @returns {Array}
|
|
|
|
*/
|
|
|
|
getAttachmentsDownloadsForUpload() {
|
2021-01-22 19:23:20 +08:00
|
|
|
return this.attachments.filter(item => item && !item.tempName()).map(
|
2020-07-23 02:09:31 +08:00
|
|
|
item => item.id
|
2019-12-25 03:05:46 +08:00
|
|
|
);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2022-01-20 01:24:07 +08:00
|
|
|
|
2022-02-03 23:51:35 +08:00
|
|
|
mailvelopeArea() {
|
2022-02-04 16:00:28 +08:00
|
|
|
if (!this.mailvelope) {
|
|
|
|
/**
|
|
|
|
* Creates an iframe with an editor for a new encrypted mail.
|
|
|
|
* The iframe will be injected into the container identified by selector.
|
|
|
|
* https://mailvelope.github.io/mailvelope/Editor.html
|
|
|
|
*/
|
2022-02-04 20:40:59 +08:00
|
|
|
let text = this.oEditor.getData(),
|
|
|
|
encrypted = PgpUserStore.isEncrypted(text),
|
2022-02-04 16:00:28 +08:00
|
|
|
size = SettingsGet('PhpUploadSizes')['post_max_size'],
|
|
|
|
quota = pInt(size);
|
|
|
|
switch (size.slice(-1)) {
|
|
|
|
case 'G': quota *= 1024; // fallthrough
|
|
|
|
case 'M': quota *= 1024; // fallthrough
|
|
|
|
case 'K': quota *= 1024;
|
|
|
|
}
|
2022-02-08 20:48:11 +08:00
|
|
|
// Issue: can't select signing key
|
|
|
|
// this.pgpSign(this.pgpSign() || confirm('Sign this message?'));
|
2022-02-03 23:51:35 +08:00
|
|
|
mailvelope.createEditorContainer('#mailvelope-editor', PgpUserStore.mailvelopeKeyring, {
|
|
|
|
// https://mailvelope.github.io/mailvelope/global.html#EditorContainerOptions
|
|
|
|
quota: Math.max(2048, (quota / 1024)) - 48, // (text + attachments) limit in kilobytes
|
2022-02-04 16:00:28 +08:00
|
|
|
armoredDraft: encrypted ? text : '', // Ascii Armored PGP Text Block
|
|
|
|
predefinedText: encrypted ? '' : (this.oEditor.isHtml() ? htmlToPlain(text) : text),
|
2022-02-03 23:51:35 +08:00
|
|
|
/*
|
|
|
|
quotedMail: '', // Ascii Armored PGP Text Block mail that should be quoted
|
|
|
|
quotedMailIndent: true, // if true the quoted mail will be indented (default: true)
|
|
|
|
quotedMailHeader: '', // header to be added before the quoted mail
|
|
|
|
keepAttachments: false, // add attachments of quotedMail to editor (default: false)
|
2022-02-08 20:48:11 +08:00
|
|
|
// Issue: can't select signing key
|
|
|
|
signMsg: this.pgpSign()
|
2022-02-03 23:51:35 +08:00
|
|
|
*/
|
|
|
|
}).then(editor => this.mailvelope = editor);
|
2022-02-04 16:00:28 +08:00
|
|
|
}
|
2022-02-03 23:51:35 +08:00
|
|
|
this.viewArea('mailvelope');
|
|
|
|
}
|
|
|
|
attachmentsArea() {
|
|
|
|
this.viewArea('attachments');
|
|
|
|
}
|
|
|
|
bodyArea() {
|
|
|
|
this.viewArea('body');
|
|
|
|
}
|
|
|
|
|
2022-01-20 16:59:56 +08:00
|
|
|
allRecipients() {
|
|
|
|
return [
|
2022-01-27 23:00:52 +08:00
|
|
|
// From/sender is also recipient (Sent mailbox)
|
2022-02-15 17:22:52 +08:00
|
|
|
// this.currentIdentity().email(),
|
|
|
|
this.from(),
|
2022-01-20 01:24:07 +08:00
|
|
|
this.to(),
|
|
|
|
this.cc(),
|
|
|
|
this.bcc()
|
2022-02-15 17:22:52 +08:00
|
|
|
].join(',').split(',').map(value => getEmail(value.trim())).validUnique();
|
2022-01-20 16:59:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
initPgpEncrypt() {
|
2022-02-04 23:21:29 +08:00
|
|
|
const recipients = this.allRecipients();
|
|
|
|
PgpUserStore.hasPublicKeyForEmails(recipients).then(result => {
|
2022-02-03 23:51:35 +08:00
|
|
|
console.log({canPgpEncrypt:result});
|
|
|
|
this.canPgpEncrypt(result);
|
|
|
|
});
|
2022-02-04 23:21:29 +08:00
|
|
|
PgpUserStore.mailvelopeHasPublicKeyForEmails(recipients).then(result => {
|
2022-02-03 23:51:35 +08:00
|
|
|
console.log({canMailvelope:result});
|
|
|
|
this.canMailvelope(result);
|
|
|
|
if (!result) {
|
|
|
|
'mailvelope' === this.viewArea() && this.bodyArea();
|
|
|
|
// this.dropMailvelope();
|
|
|
|
}
|
|
|
|
});
|
2022-01-20 01:24:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
togglePgpSign() {
|
|
|
|
this.pgpSign(!this.pgpSign()/* && this.canPgpSign()*/);
|
|
|
|
}
|
|
|
|
|
|
|
|
togglePgpEncrypt() {
|
|
|
|
this.pgpEncrypt(!this.pgpEncrypt()/* && this.canPgpEncrypt()*/);
|
|
|
|
}
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|