Fix mailto: that i broke in #484

This commit is contained in:
the-djmaze
2022-09-30 11:38:51 +02:00
parent ec24392664
commit 54107ca937
4 changed files with 36 additions and 24 deletions

View File

@@ -1,3 +1,4 @@
import { encodeHtml } from 'Common/Html';
import { AbstractModel } from 'Knoin/AbstractModel';
@@ -332,13 +333,31 @@ export class EmailModel extends AbstractModel {
/**
* @param {boolean} friendlyView = false
* @param {boolean} wrapWithLink = false
* @returns {string}
*/
toLine(friendlyView) {
let result = this.email;
return (result && this.name)
? (friendlyView ? this.name : '"' + this.name + '" <' + result + '>')
: result;
toLine(friendlyView, wrapWithLink) {
let result = this.email,
name = this.name,
toLink = text =>
'<a href="mailto:'
+ encodeHtml(result) + (name ? '?to=' + encodeURIComponent('"' + name + '" <' + result + '>') : '')
+ '" target="_blank" tabindex="-1">'
+ encodeHtml(text || result)
+ '</a>';
if (result) {
if (name) {
result = friendlyView
? (wrapWithLink ? toLink(name) : name)
: (wrapWithLink
? encodeHtml('"' + name + '" <') + toLink() + encodeHtml('>')
: '"' + name + '" <' + result + '>'
);
} else if (wrapWithLink) {
result = toLink();
}
}
return result;
}
static splitEmailLine(line) {

View File

@@ -18,10 +18,8 @@ export class EmailCollectionModel extends AbstractCollectionModel
* @param {boolean=} wrapWithLink = false
* @returns {string}
*/
toString(friendlyView = false, wrapWithLink = false) {
const result = [];
this.forEach(email => result.push(email.toLine(friendlyView, wrapWithLink)));
return result.join(', ');
toString(friendlyView, wrapWithLink) {
return this.map(email => email.toLine(friendlyView, wrapWithLink)).join(', ');
}
/**

View File

@@ -349,21 +349,17 @@ export class MessageModel extends AbstractModel {
}
/**
* @param {boolean} friendlyView
* @param {boolean=} wrapWithLink
* @returns {string}
*/
bccToLine(friendlyView, wrapWithLink) {
return this.bcc.toString(friendlyView, wrapWithLink);
bccToLine() {
return this.bcc.toString();
}
/**
* @param {boolean} friendlyView
* @param {boolean=} wrapWithLink
* @returns {string}
*/
replyToToLine(friendlyView, wrapWithLink) {
return this.replyTo.toString(friendlyView, wrapWithLink);
replyToToLine() {
return this.replyTo.toString();
}
/**
@@ -508,7 +504,7 @@ export class MessageModel extends AbstractModel {
viewPopupMessage(print) {
const timeStampInUTC = this.dateTimeStampInUTC() || 0,
ccLine = this.ccToLine(false),
ccLine = this.ccToLine(),
m = 0 < timeStampInUTC ? new Date(timeStampInUTC * 1000) : null,
win = open(''),
sdoc = win.document;
@@ -520,7 +516,7 @@ export class MessageModel extends AbstractModel {
sdoc.write(PreviewHTML
.replace('<title>', '<title>'+subject)
// eslint-disable-next-line max-len
.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(false))}</div><div>${encodeHtml(i18n('GLOBAL/TO'))}: ${encodeHtml(this.toToLine(false))}</div>${cc}</header><${mode}>${this.bodyAsHTML()}</${mode}>`)
.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}>`)
);
sdoc.close();

View File

@@ -252,11 +252,10 @@ export class MailMessageView extends AbstractViewRight {
ThemeStore.isMobile() && leftPanelDisabled(true);
let el = eqs(event, 'a');
if (el) {
return !(
0 === event.button &&
mailToHelper(el.href)
);
if (el && 0 === event.button && mailToHelper(el.href)) {
event.preventDefault();
event.stopPropagation();
return;
}
if (eqs(event, '.attachmentsPlace .attachmentIconParent')) {