Always show option to view as plain, by converting message HTML when plain is missing

This commit is contained in:
the-djmaze 2022-10-17 09:33:28 +02:00
parent e6fc06b346
commit a5bff8674a
2 changed files with 9 additions and 6 deletions

View file

@ -4,7 +4,7 @@ import { MessagePriority } from 'Common/EnumsUser';
import { i18n } from 'Common/Translator';
import { doc, SettingsGet } from 'Common/Globals';
import { encodeHtml, plainToHtml, cleanHtml } from 'Common/Html';
import { encodeHtml, plainToHtml, htmlToPlain, cleanHtml } from 'Common/Html';
import { arrayLength, forEachObjectEntry } from 'Common/Utils';
import { serverRequestRaw, proxy } from 'Common/Links';
@ -407,13 +407,16 @@ export class MessageModel extends AbstractModel {
viewPlain() {
const body = this.body;
if (body && this.plain()) {
if (body) {
body.classList.toggle('html', 0);
body.classList.toggle('plain', 1);
body.innerHTML = plainToHtml(
this.plain()
.replace(/-----BEGIN PGP (SIGNED MESSAGE-----(\r?\n[a-z][^\r\n]+)+|SIGNATURE-----[\s\S]*)/, '')
.trim()
(this.plain()
? this.plain()
.replace(/-----BEGIN PGP (SIGNED MESSAGE-----(\r?\n[a-z][^\r\n]+)+|SIGNATURE-----[\s\S]*)/, '')
.trim()
: htmlToPlain(body.innerHTML)
)
);
this.isHtml(false);
this.hasImages(false);

View file

@ -100,7 +100,7 @@
<li role="presentation" data-bind="visible: html() && !isHtml()">
<a href="#" tabindex="-1" data-bind="click: viewHtml" data-icon="👁" data-i18n="MESSAGE/HTML_VIEW"></a>
</li>
<li role="presentation" data-bind="visible: plain() && isHtml()">
<li role="presentation" data-bind="visible: isHtml()">
<a href="#" tabindex="-1" data-bind="click: viewPlain" data-icon="👁" data-i18n="MESSAGE/PLAIN_VIEW"></a>
</li>
<li class="dividerbar" role="presentation">