2016-07-07 05:03:30 +08:00
|
|
|
import ko from 'ko';
|
|
|
|
|
2021-01-25 05:58:06 +08:00
|
|
|
import { MessagePriority } from 'Common/EnumsUser';
|
2019-07-05 03:19:24 +08:00
|
|
|
import { i18n } from 'Common/Translator';
|
2016-07-07 05:03:30 +08:00
|
|
|
|
2022-08-26 17:11:19 +08:00
|
|
|
import { doc, SettingsGet } from 'Common/Globals';
|
2022-02-10 17:25:21 +08:00
|
|
|
import { encodeHtml, plainToHtml, cleanHtml } from 'Common/Html';
|
2021-12-01 21:23:37 +08:00
|
|
|
import { isArray, arrayLength, forEachObjectEntry } from 'Common/Utils';
|
2022-08-26 17:11:19 +08:00
|
|
|
import { serverRequestRaw, proxy } from 'Common/Links';
|
2016-07-07 05:03:30 +08:00
|
|
|
|
2021-03-11 05:41:35 +08:00
|
|
|
import { FolderUserStore } from 'Stores/User/Folder';
|
2022-01-15 00:13:17 +08:00
|
|
|
import { SettingsUserStore } from 'Stores/User/Settings';
|
2016-09-13 04:50:21 +08:00
|
|
|
|
2021-02-17 21:40:21 +08:00
|
|
|
import { FileInfo } from 'Common/File';
|
2020-09-15 21:08:08 +08:00
|
|
|
import { AttachmentCollectionModel } from 'Model/AttachmentCollection';
|
2020-09-15 15:43:53 +08:00
|
|
|
import { EmailCollectionModel } from 'Model/EmailCollection';
|
2019-07-05 03:19:24 +08:00
|
|
|
import { AbstractModel } from 'Knoin/AbstractModel';
|
2016-07-07 05:03:30 +08:00
|
|
|
|
2021-01-26 05:00:13 +08:00
|
|
|
import PreviewHTML from 'Html/PreviewMessage.html';
|
|
|
|
|
2022-06-07 21:48:16 +08:00
|
|
|
//import { MessageFlagsCache } from 'Common/Cache';
|
2022-06-03 19:47:04 +08:00
|
|
|
import Remote from 'Remote/User/Fetch';
|
|
|
|
|
2021-01-27 07:26:31 +08:00
|
|
|
const
|
2022-01-15 00:13:17 +08:00
|
|
|
hcont = Element.fromHTML('<div area="hidden" style="position:absolute;left:-5000px"></div>'),
|
|
|
|
getRealHeight = el => {
|
|
|
|
hcont.innerHTML = el.outerHTML;
|
|
|
|
const result = hcont.clientHeight;
|
|
|
|
hcont.innerHTML = '';
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
2022-06-08 20:54:51 +08:00
|
|
|
ignoredTags = [
|
2022-06-10 07:06:17 +08:00
|
|
|
// rfc5788
|
2022-06-08 20:54:51 +08:00
|
|
|
'$forwarded',
|
2022-06-10 06:35:13 +08:00
|
|
|
'$mdnsent',
|
2022-06-10 07:06:17 +08:00
|
|
|
'$submitpending',
|
|
|
|
'$submitted',
|
|
|
|
// rfc9051
|
|
|
|
'$junk',
|
|
|
|
'$notjunk',
|
|
|
|
'$phishing',
|
2022-06-08 20:54:51 +08:00
|
|
|
// Mailo
|
|
|
|
'sent',
|
|
|
|
// KMail
|
2022-06-10 07:06:17 +08:00
|
|
|
'$attachment',
|
|
|
|
'$encrypted',
|
2022-06-08 20:54:51 +08:00
|
|
|
'$error',
|
2022-06-10 07:06:17 +08:00
|
|
|
'$ignored',
|
|
|
|
'$invitation',
|
2022-06-08 20:54:51 +08:00
|
|
|
'$queued',
|
2022-06-10 07:06:17 +08:00
|
|
|
'$replied',
|
|
|
|
'$sent',
|
|
|
|
'$signed',
|
|
|
|
'$todo',
|
|
|
|
'$watched',
|
2022-06-08 20:54:51 +08:00
|
|
|
// GMail
|
|
|
|
'$replied',
|
|
|
|
'$attachment',
|
|
|
|
'$notphishing',
|
|
|
|
'junk',
|
2022-06-10 07:06:17 +08:00
|
|
|
'nonjunk',
|
|
|
|
// Others
|
|
|
|
'$readreceipt'
|
2022-06-08 20:54:51 +08:00
|
|
|
],
|
|
|
|
|
2022-06-03 19:47:04 +08:00
|
|
|
toggleTag = (message, keyword) => {
|
|
|
|
const lower = keyword.toLowerCase(),
|
|
|
|
isSet = message.flags().includes(lower);
|
|
|
|
Remote.request('MessageSetKeyword', iError => {
|
|
|
|
if (!iError) {
|
|
|
|
if (isSet) {
|
|
|
|
message.flags.remove(lower);
|
|
|
|
} else {
|
|
|
|
message.flags.push(lower);
|
|
|
|
}
|
2022-06-07 21:48:16 +08:00
|
|
|
// MessageFlagsCache.setFor(message.folder, message.uid, message.flags());
|
2022-06-03 19:47:04 +08:00
|
|
|
}
|
|
|
|
}, {
|
|
|
|
Folder: message.folder,
|
|
|
|
Uids: message.uid,
|
|
|
|
Keyword: keyword,
|
|
|
|
SetAction: isSet ? 0 : 1
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2022-08-25 20:08:19 +08:00
|
|
|
/**
|
|
|
|
* @param {EmailCollectionModel} emails
|
|
|
|
* @param {Object} unic
|
|
|
|
* @param {Map} localEmails
|
|
|
|
*/
|
2022-09-27 15:45:35 +08:00
|
|
|
replyHelper = (emails, unic, localEmails) =>
|
2020-09-15 15:43:53 +08:00
|
|
|
emails.forEach(email => {
|
2022-08-25 20:08:19 +08:00
|
|
|
if (!unic[email.email] && !localEmails.has(email.email)) {
|
|
|
|
localEmails.set(email.email, email);
|
2020-09-15 15:43:53 +08:00
|
|
|
}
|
|
|
|
});
|
2020-08-12 06:25:36 +08:00
|
|
|
|
2022-01-15 00:13:17 +08:00
|
|
|
doc.body.append(hcont);
|
|
|
|
|
2021-01-22 23:32:08 +08:00
|
|
|
export class MessageModel extends AbstractModel {
|
2016-07-16 05:29:42 +08:00
|
|
|
constructor() {
|
2020-10-19 01:19:45 +08:00
|
|
|
super();
|
2016-07-07 05:03:30 +08:00
|
|
|
|
2020-09-15 15:43:53 +08:00
|
|
|
this._reset();
|
|
|
|
|
2020-10-25 18:46:58 +08:00
|
|
|
this.addObservables({
|
|
|
|
subject: '',
|
2022-01-15 00:13:17 +08:00
|
|
|
plain: '',
|
|
|
|
html: '',
|
2020-10-25 18:46:58 +08:00
|
|
|
size: 0,
|
2021-04-08 21:56:46 +08:00
|
|
|
spamScore: 0,
|
2021-04-09 15:01:48 +08:00
|
|
|
spamResult: '',
|
2021-04-08 21:56:46 +08:00
|
|
|
isSpam: false,
|
2021-09-02 18:09:16 +08:00
|
|
|
hasVirus: null, // or boolean when scanned
|
2020-10-25 18:46:58 +08:00
|
|
|
dateTimeStampInUTC: 0,
|
|
|
|
priority: MessagePriority.Normal,
|
|
|
|
|
|
|
|
senderEmailsString: '',
|
|
|
|
senderClearEmailsString: '',
|
|
|
|
|
|
|
|
deleted: false,
|
|
|
|
|
2022-09-09 16:02:40 +08:00
|
|
|
// Also used by Selector
|
2020-10-25 18:46:58 +08:00
|
|
|
focused: false,
|
|
|
|
selected: false,
|
|
|
|
checked: false,
|
|
|
|
|
|
|
|
isHtml: false,
|
|
|
|
hasImages: false,
|
2022-01-15 00:13:17 +08:00
|
|
|
hasExternals: false,
|
2020-10-25 18:46:58 +08:00
|
|
|
|
2022-01-18 00:16:25 +08:00
|
|
|
pgpSigned: null,
|
2022-02-02 21:36:49 +08:00
|
|
|
pgpVerified: null,
|
2020-10-25 18:46:58 +08:00
|
|
|
|
2022-02-17 17:18:47 +08:00
|
|
|
pgpEncrypted: null,
|
|
|
|
pgpDecrypted: false,
|
|
|
|
|
2020-10-25 18:46:58 +08:00
|
|
|
readReceipt: '',
|
|
|
|
|
|
|
|
hasUnseenSubMessage: false,
|
|
|
|
hasFlaggedSubMessage: false
|
|
|
|
});
|
2016-07-07 05:03:30 +08:00
|
|
|
|
2020-10-25 18:46:58 +08:00
|
|
|
this.attachments = ko.observableArray(new AttachmentCollectionModel);
|
2021-01-22 19:23:20 +08:00
|
|
|
this.threads = ko.observableArray();
|
2021-09-01 22:10:44 +08:00
|
|
|
this.unsubsribeLinks = ko.observableArray();
|
2021-12-06 23:08:58 +08:00
|
|
|
this.flags = ko.observableArray();
|
2016-07-07 05:03:30 +08:00
|
|
|
|
2020-10-25 21:14:14 +08:00
|
|
|
this.addComputables({
|
2021-12-16 22:54:43 +08:00
|
|
|
attachmentIconClass: () => FileInfo.getAttachmentsIconClass(this.attachments()),
|
2021-03-08 22:21:54 +08:00
|
|
|
threadsLen: () => this.threads().length,
|
2022-10-04 02:15:12 +08:00
|
|
|
listAttachments: () => this.attachments()
|
|
|
|
.filter(item => SettingsUserStore.listInlineAttachments() || !item.isLinked()),
|
|
|
|
hasAttachments: () => this.listAttachments().length,
|
2021-12-06 23:08:58 +08:00
|
|
|
|
2022-06-01 02:38:35 +08:00
|
|
|
isUnseen: () => !this.flags().includes('\\seen'),
|
2021-12-06 23:08:58 +08:00
|
|
|
isFlagged: () => this.flags().includes('\\flagged'),
|
2022-06-03 03:26:57 +08:00
|
|
|
isReadReceipt: () => this.flags().includes('$mdnsent'),
|
2021-12-06 23:08:58 +08:00
|
|
|
// isJunk: () => this.flags().includes('$junk') && !this.flags().includes('$nonjunk'),
|
2022-06-03 03:26:57 +08:00
|
|
|
// isPhishing: () => this.flags().includes('$phishing'),
|
|
|
|
|
2022-06-03 05:13:20 +08:00
|
|
|
tagsToHTML: () => this.flags().map(value =>
|
2022-06-08 20:54:51 +08:00
|
|
|
('\\' == value[0] || ignoredTags.includes(value))
|
2022-06-03 03:26:57 +08:00
|
|
|
? ''
|
2022-06-03 05:13:20 +08:00
|
|
|
: '<span class="focused msgflag-'+value+'">' + i18n('MESSAGE_TAGS/'+value,0,value) + '</span>'
|
2022-06-03 19:47:04 +08:00
|
|
|
).join(' '),
|
|
|
|
|
|
|
|
tagOptions: () => {
|
|
|
|
const tagOptions = [];
|
|
|
|
FolderUserStore.currentFolder().permanentFlags.forEach(value => {
|
|
|
|
let lower = value.toLowerCase();
|
|
|
|
if ('\\' != value[0] && !ignoredTags.includes(lower)) {
|
|
|
|
tagOptions.push({
|
|
|
|
css: 'msgflag-' + lower,
|
|
|
|
value: value,
|
|
|
|
checked: this.flags().includes(lower),
|
|
|
|
label: i18n('MESSAGE_TAGS/'+lower, 0, lower),
|
|
|
|
toggle: (/*obj*/) => toggleTag(this, value)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return tagOptions
|
|
|
|
}
|
|
|
|
|
2020-10-25 21:14:14 +08:00
|
|
|
});
|
2016-07-07 05:03:30 +08:00
|
|
|
}
|
|
|
|
|
2020-09-15 15:43:53 +08:00
|
|
|
_reset() {
|
2020-10-23 21:15:54 +08:00
|
|
|
this.folder = '';
|
2021-09-10 22:28:29 +08:00
|
|
|
this.uid = 0;
|
2016-07-07 05:03:30 +08:00
|
|
|
this.hash = '';
|
|
|
|
this.requestHash = '';
|
2020-09-15 15:43:53 +08:00
|
|
|
this.emails = [];
|
|
|
|
this.from = new EmailCollectionModel;
|
|
|
|
this.to = new EmailCollectionModel;
|
|
|
|
this.cc = new EmailCollectionModel;
|
|
|
|
this.bcc = new EmailCollectionModel;
|
|
|
|
this.replyTo = new EmailCollectionModel;
|
|
|
|
this.deliveredTo = new EmailCollectionModel;
|
|
|
|
this.body = null;
|
2020-10-23 21:15:54 +08:00
|
|
|
this.draftInfo = [];
|
|
|
|
this.messageId = '';
|
|
|
|
this.inReplyTo = '';
|
|
|
|
this.references = '';
|
2020-09-15 15:43:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
clear() {
|
|
|
|
this._reset();
|
2016-07-07 05:03:30 +08:00
|
|
|
this.subject('');
|
2022-01-15 00:13:17 +08:00
|
|
|
this.html('');
|
|
|
|
this.plain('');
|
2016-07-07 05:03:30 +08:00
|
|
|
this.size(0);
|
2021-04-08 21:56:46 +08:00
|
|
|
this.spamScore(0);
|
2021-04-09 15:01:48 +08:00
|
|
|
this.spamResult('');
|
2021-04-08 21:56:46 +08:00
|
|
|
this.isSpam(false);
|
2021-09-02 18:09:16 +08:00
|
|
|
this.hasVirus(null);
|
2016-07-07 05:03:30 +08:00
|
|
|
this.dateTimeStampInUTC(0);
|
|
|
|
this.priority(MessagePriority.Normal);
|
|
|
|
|
|
|
|
this.senderEmailsString('');
|
|
|
|
this.senderClearEmailsString('');
|
|
|
|
|
|
|
|
this.deleted(false);
|
|
|
|
|
|
|
|
this.selected(false);
|
|
|
|
this.checked(false);
|
|
|
|
|
|
|
|
this.isHtml(false);
|
|
|
|
this.hasImages(false);
|
2022-01-15 00:13:17 +08:00
|
|
|
this.hasExternals(false);
|
2020-09-18 04:14:51 +08:00
|
|
|
this.attachments(new AttachmentCollectionModel);
|
2016-07-07 05:03:30 +08:00
|
|
|
|
2022-01-17 22:58:23 +08:00
|
|
|
this.pgpSigned(null);
|
2022-02-02 21:36:49 +08:00
|
|
|
this.pgpVerified(null);
|
2016-07-07 05:03:30 +08:00
|
|
|
|
2022-02-17 17:18:47 +08:00
|
|
|
this.pgpEncrypted(null);
|
|
|
|
this.pgpDecrypted(false);
|
|
|
|
|
2016-07-07 05:03:30 +08:00
|
|
|
this.priority(MessagePriority.Normal);
|
|
|
|
this.readReceipt('');
|
|
|
|
|
|
|
|
this.threads([]);
|
2021-09-01 22:10:44 +08:00
|
|
|
this.unsubsribeLinks([]);
|
2016-07-07 05:03:30 +08:00
|
|
|
|
|
|
|
this.hasUnseenSubMessage(false);
|
|
|
|
this.hasFlaggedSubMessage(false);
|
|
|
|
}
|
|
|
|
|
2022-02-02 20:02:48 +08:00
|
|
|
spamStatus() {
|
|
|
|
let spam = this.spamResult();
|
|
|
|
return spam ? i18n(this.isSpam() ? 'GLOBAL/SPAM' : 'GLOBAL/NOT_SPAM') + ': ' + spam : '';
|
|
|
|
}
|
|
|
|
|
2016-07-07 05:03:30 +08:00
|
|
|
/**
|
|
|
|
* @param {Array} properties
|
|
|
|
* @returns {Array}
|
|
|
|
*/
|
|
|
|
getEmails(properties) {
|
2020-07-23 22:06:16 +08:00
|
|
|
return properties.reduce((carry, property) => carry.concat(this[property]), []).map(
|
|
|
|
oItem => oItem ? oItem.email : ''
|
2020-10-03 05:54:15 +08:00
|
|
|
).validUnique();
|
2016-07-07 05:03:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
friendlySize() {
|
2021-02-17 21:40:21 +08:00
|
|
|
return FileInfo.friendlySize(this.size());
|
2016-07-07 05:03:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
computeSenderEmail() {
|
2021-12-01 20:54:35 +08:00
|
|
|
const list = [FolderUserStore.sentFolder(), FolderUserStore.draftsFolder()].includes(this.folder) ? 'to' : 'from';
|
2020-10-23 21:15:54 +08:00
|
|
|
this.senderEmailsString(this[list].toString(true));
|
|
|
|
this.senderClearEmailsString(this[list].toStringClear());
|
2016-07-07 05:03:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-10-19 01:46:47 +08:00
|
|
|
* @param {FetchJsonMessage} json
|
2016-07-07 05:03:30 +08:00
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2020-10-23 21:15:54 +08:00
|
|
|
revivePropertiesFromJson(json) {
|
2021-09-10 22:28:29 +08:00
|
|
|
if ('Priority' in json && ![MessagePriority.High, MessagePriority.Low].includes(json.Priority)) {
|
|
|
|
json.Priority = MessagePriority.Normal;
|
2020-10-23 21:15:54 +08:00
|
|
|
}
|
|
|
|
if (super.revivePropertiesFromJson(json)) {
|
2021-12-06 23:08:58 +08:00
|
|
|
// this.foundCIDs = isArray(json.FoundCIDs) ? json.FoundCIDs : [];
|
|
|
|
// this.attachments(AttachmentCollectionModel.reviveFromJson(json.Attachments, this.foundCIDs));
|
2016-07-07 05:03:30 +08:00
|
|
|
|
|
|
|
this.computeSenderEmail();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-17 23:03:38 +08:00
|
|
|
/**
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
hasUnsubsribeLinks() {
|
2021-09-01 22:10:44 +08:00
|
|
|
return this.unsubsribeLinks().length;
|
2016-07-17 23:03:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
getFirstUnsubsribeLink() {
|
2021-09-01 22:10:44 +08:00
|
|
|
return this.unsubsribeLinks()[0] || '';
|
2016-07-17 23:03:38 +08:00
|
|
|
}
|
|
|
|
|
2016-07-07 05:03:30 +08:00
|
|
|
/**
|
|
|
|
* @param {boolean} friendlyView
|
2021-04-07 22:35:46 +08:00
|
|
|
* @param {boolean=} wrapWithLink
|
2016-07-07 05:03:30 +08:00
|
|
|
* @returns {string}
|
|
|
|
*/
|
2021-04-07 22:35:46 +08:00
|
|
|
fromToLine(friendlyView, wrapWithLink) {
|
2020-09-15 15:43:53 +08:00
|
|
|
return this.from.toString(friendlyView, wrapWithLink);
|
2016-07-07 05:03:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
fromDkimData() {
|
|
|
|
let result = ['none', ''];
|
2022-09-02 17:52:07 +08:00
|
|
|
if (1 === arrayLength(this.from) && this.from[0]?.dkimStatus) {
|
2016-07-07 05:03:30 +08:00
|
|
|
result = [this.from[0].dkimStatus, this.from[0].dkimValue || ''];
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {boolean} friendlyView
|
2021-04-07 22:35:46 +08:00
|
|
|
* @param {boolean=} wrapWithLink
|
2016-07-07 05:03:30 +08:00
|
|
|
* @returns {string}
|
|
|
|
*/
|
2021-04-07 22:35:46 +08:00
|
|
|
toToLine(friendlyView, wrapWithLink) {
|
2020-09-15 15:43:53 +08:00
|
|
|
return this.to.toString(friendlyView, wrapWithLink);
|
2016-07-07 05:03:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {boolean} friendlyView
|
2021-04-07 22:35:46 +08:00
|
|
|
* @param {boolean=} wrapWithLink
|
2016-07-07 05:03:30 +08:00
|
|
|
* @returns {string}
|
|
|
|
*/
|
2021-04-07 22:35:46 +08:00
|
|
|
ccToLine(friendlyView, wrapWithLink) {
|
2020-09-15 15:43:53 +08:00
|
|
|
return this.cc.toString(friendlyView, wrapWithLink);
|
2016-07-07 05:03:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
2022-09-30 17:38:51 +08:00
|
|
|
bccToLine() {
|
|
|
|
return this.bcc.toString();
|
2016-07-07 05:03:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
2022-09-30 17:38:51 +08:00
|
|
|
replyToToLine() {
|
|
|
|
return this.replyTo.toString();
|
2016-07-07 05:03:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2022-09-13 05:13:04 +08:00
|
|
|
lineAsCss(flags=1) {
|
2020-08-12 07:47:24 +08:00
|
|
|
let classes = [];
|
2021-12-01 21:23:37 +08:00
|
|
|
forEachObjectEntry({
|
2021-03-25 04:26:40 +08:00
|
|
|
deleted: this.deleted(),
|
|
|
|
selected: this.selected(),
|
|
|
|
checked: this.checked(),
|
|
|
|
unseen: this.isUnseen(),
|
|
|
|
focused: this.focused(),
|
2022-09-13 05:13:04 +08:00
|
|
|
priorityHigh: this.priority() === MessagePriority.High,
|
2022-02-01 00:29:41 +08:00
|
|
|
withAttachments: !!this.attachments().length,
|
2021-03-25 04:26:40 +08:00
|
|
|
// hasChildrenMessage: 1 < this.threadsLen(),
|
|
|
|
hasUnseenSubMessage: this.hasUnseenSubMessage(),
|
|
|
|
hasFlaggedSubMessage: this.hasFlaggedSubMessage()
|
2021-12-01 21:23:37 +08:00
|
|
|
}, (key, value) => value && classes.push(key));
|
2022-09-13 05:13:04 +08:00
|
|
|
flags && this.flags().forEach(value => classes.push('msgflag-'+value));
|
2020-08-12 07:47:24 +08:00
|
|
|
return classes.join(' ');
|
2016-07-07 05:03:30 +08:00
|
|
|
}
|
|
|
|
|
2022-05-31 23:12:29 +08:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
* https://datatracker.ietf.org/doc/html/rfc5788
|
|
|
|
*/
|
|
|
|
keywords() {
|
|
|
|
return this.flags().filter(value => '\\' !== value[0]);
|
|
|
|
}
|
|
|
|
|
2016-07-07 05:03:30 +08:00
|
|
|
/**
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
fromAsSingleEmail() {
|
2022-09-02 17:52:07 +08:00
|
|
|
return (isArray(this.from) && this.from[0]?.email) || '';
|
2016-07-07 05:03:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
viewLink() {
|
2021-02-04 18:25:00 +08:00
|
|
|
return serverRequestRaw('ViewAsPlain', this.requestHash);
|
2016-07-07 05:03:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
downloadLink() {
|
2021-02-04 18:25:00 +08:00
|
|
|
return serverRequestRaw('Download', this.requestHash);
|
2016-07-07 05:03:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Object} excludeEmails
|
|
|
|
* @returns {Array}
|
|
|
|
*/
|
2022-08-25 20:08:19 +08:00
|
|
|
replyEmails(excludeEmails) {
|
|
|
|
const
|
|
|
|
result = new Map(),
|
|
|
|
unic = excludeEmails || {};
|
2016-07-07 05:03:30 +08:00
|
|
|
replyHelper(this.replyTo, unic, result);
|
2022-08-25 20:08:19 +08:00
|
|
|
result.size || replyHelper(this.from, unic, result);
|
|
|
|
return result.size ? [...result.values()] : [this.to[0]];
|
2016-07-07 05:03:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Object} excludeEmails
|
|
|
|
* @returns {Array.<Array>}
|
|
|
|
*/
|
2022-08-25 20:08:19 +08:00
|
|
|
replyAllEmails(excludeEmails) {
|
|
|
|
const
|
|
|
|
toResult = new Map(),
|
|
|
|
ccResult = new Map(),
|
|
|
|
unic = excludeEmails || {};
|
2016-07-07 05:03:30 +08:00
|
|
|
|
|
|
|
replyHelper(this.replyTo, unic, toResult);
|
2022-09-27 15:45:35 +08:00
|
|
|
toResult.size || replyHelper(this.from, unic, toResult);
|
|
|
|
|
2016-07-07 05:03:30 +08:00
|
|
|
replyHelper(this.to, unic, toResult);
|
|
|
|
|
2022-08-25 20:08:19 +08:00
|
|
|
replyHelper(this.cc, unic, ccResult);
|
2016-07-07 05:03:30 +08:00
|
|
|
|
2022-08-31 03:42:05 +08:00
|
|
|
return [[...toResult.values()], [...ccResult.values()]];
|
2016-07-07 05:03:30 +08:00
|
|
|
}
|
|
|
|
|
2022-01-15 00:13:17 +08:00
|
|
|
viewHtml() {
|
|
|
|
const body = this.body;
|
|
|
|
if (body && this.html()) {
|
2022-09-23 19:41:01 +08:00
|
|
|
let result = cleanHtml(this.html(), this.attachments());
|
2022-02-02 20:02:48 +08:00
|
|
|
this.hasExternals(result.hasExternals);
|
|
|
|
this.hasImages(body.rlHasImages = !!result.hasExternals);
|
|
|
|
|
|
|
|
body.innerHTML = result.html;
|
2022-01-15 00:13:17 +08:00
|
|
|
|
|
|
|
body.classList.toggle('html', 1);
|
|
|
|
body.classList.toggle('plain', 0);
|
|
|
|
|
|
|
|
if (SettingsUserStore.showImages()) {
|
|
|
|
this.showExternalImages();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.isHtml(true);
|
|
|
|
this.initView();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
viewPlain() {
|
|
|
|
const body = this.body;
|
|
|
|
if (body && this.plain()) {
|
|
|
|
body.classList.toggle('html', 0);
|
|
|
|
body.classList.toggle('plain', 1);
|
2022-02-03 01:43:55 +08:00
|
|
|
body.innerHTML = plainToHtml(
|
|
|
|
this.plain()
|
2022-02-11 18:01:07 +08:00
|
|
|
.replace(/-----BEGIN PGP (SIGNED MESSAGE-----(\r?\n[a-z][^\r\n]+)+|SIGNATURE-----[\s\S]*)/, '')
|
2022-02-03 01:43:55 +08:00
|
|
|
.trim()
|
2022-10-03 18:45:35 +08:00
|
|
|
);
|
2022-01-15 00:13:17 +08:00
|
|
|
this.isHtml(false);
|
2022-02-02 20:02:48 +08:00
|
|
|
this.hasImages(false);
|
2022-01-15 00:13:17 +08:00
|
|
|
this.initView();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
initView() {
|
|
|
|
// init BlockquoteSwitcher
|
2022-09-26 17:06:42 +08:00
|
|
|
this.body.querySelectorAll('blockquote').forEach(node => {
|
2022-09-26 05:55:24 +08:00
|
|
|
if (node.textContent.trim()) {
|
2022-01-15 00:13:17 +08:00
|
|
|
let h = node.clientHeight || getRealHeight(node);
|
|
|
|
if (0 === h || 100 < h) {
|
2022-09-26 17:06:42 +08:00
|
|
|
const el = Element.fromHTML('<details class="sm-bq-switcher"><summary>•••</summary></details>');
|
|
|
|
node.replaceWith(el);
|
|
|
|
el.append(node);
|
2022-01-15 00:13:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-04-07 22:35:46 +08:00
|
|
|
viewPopupMessage(print) {
|
2019-07-05 03:19:24 +08:00
|
|
|
const timeStampInUTC = this.dateTimeStampInUTC() || 0,
|
2022-09-30 17:38:51 +08:00
|
|
|
ccLine = this.ccToLine(),
|
2020-08-27 21:45:47 +08:00
|
|
|
m = 0 < timeStampInUTC ? new Date(timeStampInUTC * 1000) : null,
|
|
|
|
win = open(''),
|
2022-02-14 03:01:21 +08:00
|
|
|
sdoc = win.document;
|
|
|
|
let subject = encodeHtml(this.subject()),
|
|
|
|
mode = this.isHtml() ? 'div' : 'pre',
|
|
|
|
cc = ccLine ? `<div>${encodeHtml(i18n('GLOBAL/CC'))}: ${encodeHtml(ccLine)}</div>` : '',
|
|
|
|
style = getComputedStyle(doc.querySelector('.messageView')),
|
|
|
|
prop = property => style.getPropertyValue(property);
|
|
|
|
sdoc.write(PreviewHTML
|
|
|
|
.replace('<title>', '<title>'+subject)
|
|
|
|
// eslint-disable-next-line max-len
|
2022-09-30 17:38:51 +08:00
|
|
|
.replace('<body>', `<body style="background-color:${prop('background-color')};color:${prop('color')}"><header><h1>${subject}</h1><time>${encodeHtml(m ? m.format('LLL') : '')}</time><div>${encodeHtml(this.fromToLine())}</div><div>${encodeHtml(i18n('GLOBAL/TO'))}: ${encodeHtml(this.toToLine())}</div>${cc}</header><${mode}>${this.bodyAsHTML()}</${mode}>`)
|
2019-07-05 03:19:24 +08:00
|
|
|
);
|
2022-02-14 03:01:21 +08:00
|
|
|
sdoc.close();
|
2020-08-27 21:45:47 +08:00
|
|
|
|
|
|
|
if (print) {
|
|
|
|
setTimeout(() => win.print(), 100);
|
|
|
|
}
|
2016-07-07 05:03:30 +08:00
|
|
|
}
|
|
|
|
|
2022-02-02 20:02:48 +08:00
|
|
|
/**
|
|
|
|
* @param {boolean=} print = false
|
|
|
|
*/
|
|
|
|
popupMessage() {
|
|
|
|
this.viewPopupMessage(false);
|
|
|
|
}
|
|
|
|
|
2016-07-07 05:03:30 +08:00
|
|
|
printMessage() {
|
|
|
|
this.viewPopupMessage(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
generateUid() {
|
2020-10-23 21:15:54 +08:00
|
|
|
return this.folder + '/' + this.uid;
|
2016-07-07 05:03:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {MessageModel} message
|
|
|
|
* @returns {MessageModel}
|
|
|
|
*/
|
2022-02-24 02:26:52 +08:00
|
|
|
static fromMessageListItem(message) {
|
|
|
|
let self = new MessageModel();
|
2022-01-15 00:13:17 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
if (message) {
|
2022-02-24 02:26:52 +08:00
|
|
|
self.folder = message.folder;
|
|
|
|
self.uid = message.uid;
|
|
|
|
self.hash = message.hash;
|
|
|
|
self.requestHash = message.requestHash;
|
|
|
|
self.subject(message.subject());
|
|
|
|
self.plain(message.plain());
|
|
|
|
self.html(message.html());
|
|
|
|
|
|
|
|
self.size(message.size());
|
|
|
|
self.spamScore(message.spamScore());
|
|
|
|
self.spamResult(message.spamResult());
|
|
|
|
self.isSpam(message.isSpam());
|
|
|
|
self.hasVirus(message.hasVirus());
|
|
|
|
self.dateTimeStampInUTC(message.dateTimeStampInUTC());
|
|
|
|
self.priority(message.priority());
|
|
|
|
|
|
|
|
self.hasExternals(message.hasExternals());
|
|
|
|
|
|
|
|
self.emails = message.emails;
|
|
|
|
|
|
|
|
self.from = message.from;
|
|
|
|
self.to = message.to;
|
|
|
|
self.cc = message.cc;
|
|
|
|
self.bcc = message.bcc;
|
|
|
|
self.replyTo = message.replyTo;
|
|
|
|
self.deliveredTo = message.deliveredTo;
|
|
|
|
self.unsubsribeLinks(message.unsubsribeLinks);
|
|
|
|
|
|
|
|
self.flags(message.flags());
|
|
|
|
|
|
|
|
self.priority(message.priority());
|
|
|
|
|
|
|
|
self.selected(message.selected());
|
|
|
|
self.checked(message.checked());
|
|
|
|
self.attachments(message.attachments());
|
|
|
|
|
|
|
|
self.threads(message.threads());
|
2016-07-07 05:03:30 +08:00
|
|
|
}
|
|
|
|
|
2022-02-24 02:26:52 +08:00
|
|
|
self.computeSenderEmail();
|
2016-07-07 05:03:30 +08:00
|
|
|
|
2022-02-24 02:26:52 +08:00
|
|
|
return self;
|
2016-07-07 05:03:30 +08:00
|
|
|
}
|
|
|
|
|
2020-08-27 21:45:47 +08:00
|
|
|
showExternalImages() {
|
2022-01-15 00:13:17 +08:00
|
|
|
const body = this.body;
|
|
|
|
if (body && this.hasImages()) {
|
2016-07-07 05:03:30 +08:00
|
|
|
this.hasImages(false);
|
2022-01-15 00:13:17 +08:00
|
|
|
body.rlHasImages = false;
|
2016-07-07 05:03:30 +08:00
|
|
|
|
2022-08-26 17:11:19 +08:00
|
|
|
let attr = 'data-x-src',
|
|
|
|
src, useProxy = !!SettingsGet('UseLocalProxyForExternalImages');
|
|
|
|
body.querySelectorAll('img[' + attr + ']').forEach(node => {
|
|
|
|
src = node.getAttribute(attr);
|
|
|
|
node.src = useProxy ? proxy(src) : src;
|
2016-07-07 05:03:30 +08:00
|
|
|
});
|
|
|
|
|
2022-02-02 20:02:48 +08:00
|
|
|
body.querySelectorAll('[data-x-style-url]').forEach(node => {
|
2022-08-26 17:11:19 +08:00
|
|
|
JSON.parse(node.dataset.xStyleUrl).forEach(data =>
|
|
|
|
node.style[data[0]] = "url('" + (useProxy ? proxy(data[1]) : data[1]) + "')"
|
|
|
|
);
|
2016-07-07 05:03:30 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-27 21:45:47 +08:00
|
|
|
/**
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
bodyAsHTML() {
|
2022-09-23 19:41:01 +08:00
|
|
|
if (this.body) {
|
2022-02-04 20:40:59 +08:00
|
|
|
let clone = this.body.cloneNode(true);
|
2022-09-26 17:06:42 +08:00
|
|
|
clone.querySelectorAll('.sm-bq-switcher').forEach(
|
|
|
|
node => node.replaceWith(node.lastElementChild)
|
2020-08-27 21:45:47 +08:00
|
|
|
);
|
|
|
|
return clone.innerHTML;
|
2016-07-07 05:03:30 +08:00
|
|
|
}
|
2022-09-23 19:41:01 +08:00
|
|
|
let result = cleanHtml(this.html(), this.attachments())
|
2022-05-12 05:13:24 +08:00
|
|
|
return result.html || plainToHtml(this.plain());
|
2016-07-07 05:03:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|