mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-07 08:27:03 +03:00
Put OpenPGP check outside "plain".
This allows also for checking HTML messages (but errors for now)
This commit is contained in:
parent
b1bbd58e21
commit
464e766fcc
4 changed files with 64 additions and 109 deletions
|
|
@ -460,7 +460,7 @@ export class MessageModel extends AbstractModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
showExternalImages() {
|
showExternalImages() {
|
||||||
if (this.body && this.body.rlHasImages) {
|
if (this.body && this.hasImages()) {
|
||||||
this.hasImages(false);
|
this.hasImages(false);
|
||||||
this.body.rlHasImages = false;
|
this.body.rlHasImages = false;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import { koComputable } from 'External/ko';
|
||||||
|
|
||||||
import { Scope, Notification } from 'Common/Enums';
|
import { Scope, Notification } from 'Common/Enums';
|
||||||
import { MessageSetAction } from 'Common/EnumsUser';
|
import { MessageSetAction } from 'Common/EnumsUser';
|
||||||
import { doc, $htmlCL, createElement, elementById } from 'Common/Globals';
|
import { doc, $htmlCL, elementById } from 'Common/Globals';
|
||||||
import { arrayLength, pInt, pString, addObservablesTo, addComputablesTo, addSubscribablesTo } from 'Common/Utils';
|
import { arrayLength, pInt, pString, addObservablesTo, addComputablesTo, addSubscribablesTo } from 'Common/Utils';
|
||||||
import { plainToHtml } from 'Common/UtilsUser';
|
import { plainToHtml } from 'Common/UtilsUser';
|
||||||
|
|
||||||
|
|
@ -358,33 +358,6 @@ export const MessageUserStore = new class {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {Object} messageTextBody
|
|
||||||
*/
|
|
||||||
initBlockquoteSwitcher(messageTextBody) {
|
|
||||||
messageTextBody && messageTextBody.querySelectorAll('blockquote:not(.rl-bq-switcher)').forEach(node => {
|
|
||||||
if (node.textContent.trim() && !node.parentNode.closest('blockquote')) {
|
|
||||||
let h = node.clientHeight || getRealHeight(node);
|
|
||||||
if (0 === h || 100 < h) {
|
|
||||||
const el = Element.fromHTML('<span class="rlBlockquoteSwitcher">•••</span>');
|
|
||||||
node.classList.add('rl-bq-switcher','hidden-bq');
|
|
||||||
node.before(el);
|
|
||||||
el.addEventListener('click', () => node.classList.toggle('hidden-bq'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {Object} messageTextBody
|
|
||||||
* @param {Object} message
|
|
||||||
*/
|
|
||||||
initOpenPgpControls(messageTextBody, message) {
|
|
||||||
messageTextBody && messageTextBody.querySelectorAll('.b-plain-openpgp:not(.inited)').forEach(node =>
|
|
||||||
PgpUserStore.initMessageBodyControls(node, message)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
setMessage(data, cached, oMessage) {
|
setMessage(data, cached, oMessage) {
|
||||||
let isNew = false,
|
let isNew = false,
|
||||||
json = data && data.Result,
|
json = data && data.Result,
|
||||||
|
|
@ -423,18 +396,14 @@ export const MessageUserStore = new class {
|
||||||
addRequestedMessage(message.folder, message.uid);
|
addRequestedMessage(message.folder, message.uid);
|
||||||
|
|
||||||
if (messagesDom) {
|
if (messagesDom) {
|
||||||
let body = null,
|
let id = 'rl-msg-' + message.hash.replace(/[^a-zA-Z0-9]/g, ''),
|
||||||
id = 'rl-msg-' + message.hash.replace(/[^a-zA-Z0-9]/g, '');
|
body = elementById(id);
|
||||||
|
if (body) {
|
||||||
const textBody = elementById(id);
|
message.body = body;
|
||||||
if (textBody) {
|
|
||||||
message.body = textBody;
|
|
||||||
message.fetchDataFromDom();
|
message.fetchDataFromDom();
|
||||||
messagesDom.append(textBody);
|
|
||||||
} else {
|
} else {
|
||||||
let isHtml = !!json.Html,
|
let isHtml = !!json.Html,
|
||||||
plain = '',
|
resultHtml = '';
|
||||||
resultHtml = '<pre></pre>';
|
|
||||||
if (isHtml) {
|
if (isHtml) {
|
||||||
resultHtml = json.Html.toString().replace(/font-size:\s*[0-9]px/g,'font-size:11px');
|
resultHtml = json.Html.toString().replace(/font-size:\s*[0-9]px/g,'font-size:11px');
|
||||||
if (SettingsUserStore.removeColors()) {
|
if (SettingsUserStore.removeColors()) {
|
||||||
|
|
@ -442,30 +411,16 @@ export const MessageUserStore = new class {
|
||||||
}
|
}
|
||||||
} else if (json.Plain) {
|
} else if (json.Plain) {
|
||||||
resultHtml = findEmailAndLinks(plainToHtml(json.Plain.toString()));
|
resultHtml = findEmailAndLinks(plainToHtml(json.Plain.toString()));
|
||||||
|
|
||||||
if ((message.isPgpSigned() || message.isPgpEncrypted()) && PgpUserStore.capaOpenPGP()) {
|
|
||||||
plain = pString(json.Plain);
|
|
||||||
const pre = createElement('pre');
|
|
||||||
if (message.isPgpSigned()) {
|
|
||||||
pre.className = 'b-plain-openpgp signed';
|
|
||||||
pre.textContent = plain;
|
|
||||||
} else if (message.isPgpEncrypted()) {
|
|
||||||
pre.className = 'b-plain-openpgp encrypted';
|
|
||||||
pre.textContent = plain;
|
|
||||||
} else {
|
|
||||||
pre.innerHTML = resultHtml;
|
|
||||||
}
|
|
||||||
resultHtml = pre.outerHTML;
|
|
||||||
} else {
|
|
||||||
resultHtml = '<pre>' + resultHtml + '</pre>';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Strip utm_* tracking
|
// Strip utm_* tracking
|
||||||
resultHtml = resultHtml.replace(/(\\?|&|&)utm_[a-z]+=[a-z0-9_-]*/si, '$1');
|
resultHtml = resultHtml.replace(/(\\?|&|&)utm_[a-z]+=[a-z0-9_-]*/si, '$1');
|
||||||
|
|
||||||
body = Element.fromHTML('<div id="' + id + '" hidden="" class="b-text-part '
|
body = Element.fromHTML('<div id="' + id + '" hidden="" class="b-text-part '
|
||||||
+ (isHtml ? 'html' : 'plain') + '">'
|
+ (isHtml ? 'html' : 'plain')
|
||||||
|
+ (message.isPgpSigned() ? ' openpgp-signed' : '')
|
||||||
|
+ (message.isPgpEncrypted() ? ' openpgp-encrypted' : '')
|
||||||
|
+ '">'
|
||||||
+ resultHtml
|
+ resultHtml
|
||||||
+ '</div>');
|
+ '</div>');
|
||||||
|
|
||||||
|
|
@ -482,11 +437,7 @@ export const MessageUserStore = new class {
|
||||||
body.rlHasImages = !!json.HasExternals;
|
body.rlHasImages = !!json.HasExternals;
|
||||||
|
|
||||||
message.body = body;
|
message.body = body;
|
||||||
|
message.fetchDataFromDom();
|
||||||
message.isHtml(isHtml);
|
|
||||||
message.hasImages(body.rlHasImages);
|
|
||||||
|
|
||||||
messagesDom.append(body);
|
|
||||||
|
|
||||||
if (json.HasInternals) {
|
if (json.HasInternals) {
|
||||||
message.showInternalImages();
|
message.showInternalImages();
|
||||||
|
|
@ -497,18 +448,29 @@ export const MessageUserStore = new class {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.purgeMessageBodyCache();
|
this.purgeMessageBodyCache();
|
||||||
|
|
||||||
|
PgpUserStore.initMessageBodyControls(body, message);
|
||||||
|
|
||||||
|
// init BlockquoteSwitcher
|
||||||
|
body.querySelectorAll('blockquote:not(.rl-bq-switcher)').forEach(node => {
|
||||||
|
if (node.textContent.trim() && !node.parentNode.closest('blockquote')) {
|
||||||
|
let h = node.clientHeight || getRealHeight(node);
|
||||||
|
if (0 === h || 100 < h) {
|
||||||
|
const el = Element.fromHTML('<span class="rlBlockquoteSwitcher">•••</span>');
|
||||||
|
node.classList.add('rl-bq-switcher','hidden-bq');
|
||||||
|
node.before(el);
|
||||||
|
el.addEventListener('click', () => node.classList.toggle('hidden-bq'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
messagesDom.append(body);
|
||||||
|
|
||||||
oMessage || this.messageActiveDom(message.body);
|
oMessage || this.messageActiveDom(message.body);
|
||||||
|
|
||||||
oMessage || this.hideMessageBodies();
|
oMessage || this.hideMessageBodies();
|
||||||
|
|
||||||
if (body) {
|
|
||||||
this.initOpenPgpControls(body, message);
|
|
||||||
|
|
||||||
this.initBlockquoteSwitcher(body);
|
|
||||||
}
|
|
||||||
|
|
||||||
oMessage || (message.body.hidden = false);
|
oMessage || (message.body.hidden = false);
|
||||||
oMessage && message.viewPopupMessage();
|
oMessage && message.viewPopupMessage();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ import ko from 'ko';
|
||||||
|
|
||||||
import { i18n } from 'Common/Translator';
|
import { i18n } from 'Common/Translator';
|
||||||
import { isArray, arrayLength, pString, addComputablesTo } from 'Common/Utils';
|
import { isArray, arrayLength, pString, addComputablesTo } from 'Common/Utils';
|
||||||
import { createElement } from 'Common/Globals';
|
|
||||||
|
|
||||||
import { AccountUserStore } from 'Stores/User/Account';
|
import { AccountUserStore } from 'Stores/User/Account';
|
||||||
|
|
||||||
|
|
@ -341,30 +340,24 @@ export const PgpUserStore = new class {
|
||||||
* @param {MessageModel} rainLoopMessage
|
* @param {MessageModel} rainLoopMessage
|
||||||
*/
|
*/
|
||||||
initMessageBodyControls(dom, rainLoopMessage) {
|
initMessageBodyControls(dom, rainLoopMessage) {
|
||||||
const cl = dom && dom.classList;
|
const cl = dom.classList,
|
||||||
if (!cl.contains('inited')) {
|
signed = cl.contains('openpgp-signed'),
|
||||||
cl.add('inited');
|
encrypted = cl.contains('openpgp-encrypted');
|
||||||
|
if ((encrypted || signed) && !dom.phpInited) {
|
||||||
const encrypted = cl.contains('encrypted'),
|
dom.phpInited = 1;
|
||||||
signed = cl.contains('signed'),
|
const
|
||||||
recipients = rainLoopMessage ? rainLoopMessage.getEmails(['from', 'to', 'cc']) : [];
|
domText = dom.textContent,
|
||||||
|
recipients = rainLoopMessage ? rainLoopMessage.getEmails(['from', 'to', 'cc']) : [],
|
||||||
let verControl = null;
|
|
||||||
|
|
||||||
if (encrypted || signed) {
|
|
||||||
const domText = dom.textContent;
|
|
||||||
|
|
||||||
verControl = Element.fromHTML('<div class="b-openpgp-control"><i class="fontastic">🔒</i></div>');
|
verControl = Element.fromHTML('<div class="b-openpgp-control"><i class="fontastic">🔒</i></div>');
|
||||||
if (encrypted) {
|
if (encrypted) {
|
||||||
verControl.title = i18n('MESSAGE/PGP_ENCRYPTED_MESSAGE_DESC');
|
verControl.title = i18n('MESSAGE/PGP_ENCRYPTED_MESSAGE_DESC');
|
||||||
verControl.addEventListener('click', domControlEncryptedClickHelper(this, dom, domText, recipients));
|
verControl.addEventListener('click', domControlEncryptedClickHelper(this, dom, domText, recipients));
|
||||||
} else {
|
} else {
|
||||||
verControl.title = i18n('MESSAGE/PGP_SIGNED_MESSAGE_DESC');
|
verControl.title = i18n('MESSAGE/PGP_SIGNED_MESSAGE_DESC');
|
||||||
verControl.addEventListener('click', domControlSignedClickHelper(this, dom, domText));
|
verControl.addEventListener('click', domControlSignedClickHelper(this, dom, domText));
|
||||||
}
|
|
||||||
|
|
||||||
dom.before(verControl, createElement('div'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dom.prepend(verControl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -387,7 +387,7 @@ html.rl-no-preview-pane {
|
||||||
&.plain {
|
&.plain {
|
||||||
|
|
||||||
padding: 15px;
|
padding: 15px;
|
||||||
/*white-space: pre-wrap;*/
|
white-space: pre-wrap;
|
||||||
font-family: var(--fontMono);
|
font-family: var(--fontMono);
|
||||||
|
|
||||||
pre {
|
pre {
|
||||||
|
|
@ -398,22 +398,6 @@ html.rl-no-preview-pane {
|
||||||
word-break: normal;
|
word-break: normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
pre.b-plain-openpgp {
|
|
||||||
display: inline-block;
|
|
||||||
padding: 6px 10px;
|
|
||||||
border: 1px dashed #666;
|
|
||||||
word-break: break-all;
|
|
||||||
|
|
||||||
&.success {
|
|
||||||
border-color: green;
|
|
||||||
background-color: rgba(0, 255, 0, 0.03);
|
|
||||||
}
|
|
||||||
&.error {
|
|
||||||
border-color: red;
|
|
||||||
background-color: rgba(255, 0, 0, 0.03);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
blockquote {
|
blockquote {
|
||||||
border-left: 2px solid blue;
|
border-left: 2px solid blue;
|
||||||
color: blue;
|
color: blue;
|
||||||
|
|
@ -430,11 +414,28 @@ html.rl-no-preview-pane {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
&.openpgp-signed,
|
||||||
|
&.openpgp-encrypted {
|
||||||
|
border: 1px dashed #FA0;
|
||||||
|
|
||||||
|
&.success {
|
||||||
|
border-color: green;
|
||||||
|
background-color: rgba(0, 255, 0, 0.03);
|
||||||
|
}
|
||||||
|
&.error {
|
||||||
|
border-color: red;
|
||||||
|
background-color: rgba(255, 0, 0, 0.03);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
.b-openpgp-control {
|
.b-openpgp-control {
|
||||||
|
|
||||||
display: inline-block;
|
color: #FA0;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
display: block;
|
||||||
opacity: 0.5;
|
opacity: 0.5;
|
||||||
|
margin: 15px;
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
|
|
@ -442,7 +443,6 @@ html.rl-no-preview-pane {
|
||||||
|
|
||||||
&.success {
|
&.success {
|
||||||
color: green;
|
color: green;
|
||||||
cursor: help;
|
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue