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) {