mirror of
https://github.com/the-djmaze/snappymail.git
synced 2024-11-10 09:02:45 +08: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() {
|
||||
if (this.body && this.body.rlHasImages) {
|
||||
if (this.body && this.hasImages()) {
|
||||
this.hasImages(false);
|
||||
this.body.rlHasImages = false;
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import { koComputable } from 'External/ko';
|
|||
|
||||
import { Scope, Notification } from 'Common/Enums';
|
||||
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 { 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) {
|
||||
let isNew = false,
|
||||
json = data && data.Result,
|
||||
|
@ -423,18 +396,14 @@ export const MessageUserStore = new class {
|
|||
addRequestedMessage(message.folder, message.uid);
|
||||
|
||||
if (messagesDom) {
|
||||
let body = null,
|
||||
id = 'rl-msg-' + message.hash.replace(/[^a-zA-Z0-9]/g, '');
|
||||
|
||||
const textBody = elementById(id);
|
||||
if (textBody) {
|
||||
message.body = textBody;
|
||||
let id = 'rl-msg-' + message.hash.replace(/[^a-zA-Z0-9]/g, ''),
|
||||
body = elementById(id);
|
||||
if (body) {
|
||||
message.body = body;
|
||||
message.fetchDataFromDom();
|
||||
messagesDom.append(textBody);
|
||||
} else {
|
||||
let isHtml = !!json.Html,
|
||||
plain = '',
|
||||
resultHtml = '<pre></pre>';
|
||||
resultHtml = '';
|
||||
if (isHtml) {
|
||||
resultHtml = json.Html.toString().replace(/font-size:\s*[0-9]px/g,'font-size:11px');
|
||||
if (SettingsUserStore.removeColors()) {
|
||||
|
@ -442,30 +411,16 @@ export const MessageUserStore = new class {
|
|||
}
|
||||
} else if (json.Plain) {
|
||||
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
|
||||
resultHtml = resultHtml.replace(/(\\?|&|&)utm_[a-z]+=[a-z0-9_-]*/si, '$1');
|
||||
|
||||
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
|
||||
+ '</div>');
|
||||
|
||||
|
@ -482,11 +437,7 @@ export const MessageUserStore = new class {
|
|||
body.rlHasImages = !!json.HasExternals;
|
||||
|
||||
message.body = body;
|
||||
|
||||
message.isHtml(isHtml);
|
||||
message.hasImages(body.rlHasImages);
|
||||
|
||||
messagesDom.append(body);
|
||||
message.fetchDataFromDom();
|
||||
|
||||
if (json.HasInternals) {
|
||||
message.showInternalImages();
|
||||
|
@ -497,18 +448,29 @@ export const MessageUserStore = new class {
|
|||
}
|
||||
|
||||
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.hideMessageBodies();
|
||||
|
||||
if (body) {
|
||||
this.initOpenPgpControls(body, message);
|
||||
|
||||
this.initBlockquoteSwitcher(body);
|
||||
}
|
||||
|
||||
oMessage || (message.body.hidden = false);
|
||||
oMessage && message.viewPopupMessage();
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ import ko from 'ko';
|
|||
|
||||
import { i18n } from 'Common/Translator';
|
||||
import { isArray, arrayLength, pString, addComputablesTo } from 'Common/Utils';
|
||||
import { createElement } from 'Common/Globals';
|
||||
|
||||
import { AccountUserStore } from 'Stores/User/Account';
|
||||
|
||||
|
@ -341,30 +340,24 @@ export const PgpUserStore = new class {
|
|||
* @param {MessageModel} rainLoopMessage
|
||||
*/
|
||||
initMessageBodyControls(dom, rainLoopMessage) {
|
||||
const cl = dom && dom.classList;
|
||||
if (!cl.contains('inited')) {
|
||||
cl.add('inited');
|
||||
|
||||
const encrypted = cl.contains('encrypted'),
|
||||
signed = cl.contains('signed'),
|
||||
recipients = rainLoopMessage ? rainLoopMessage.getEmails(['from', 'to', 'cc']) : [];
|
||||
|
||||
let verControl = null;
|
||||
|
||||
if (encrypted || signed) {
|
||||
const domText = dom.textContent;
|
||||
|
||||
const cl = dom.classList,
|
||||
signed = cl.contains('openpgp-signed'),
|
||||
encrypted = cl.contains('openpgp-encrypted');
|
||||
if ((encrypted || signed) && !dom.phpInited) {
|
||||
dom.phpInited = 1;
|
||||
const
|
||||
domText = dom.textContent,
|
||||
recipients = rainLoopMessage ? rainLoopMessage.getEmails(['from', 'to', 'cc']) : [],
|
||||
verControl = Element.fromHTML('<div class="b-openpgp-control"><i class="fontastic">🔒</i></div>');
|
||||
if (encrypted) {
|
||||
verControl.title = i18n('MESSAGE/PGP_ENCRYPTED_MESSAGE_DESC');
|
||||
verControl.addEventListener('click', domControlEncryptedClickHelper(this, dom, domText, recipients));
|
||||
} else {
|
||||
verControl.title = i18n('MESSAGE/PGP_SIGNED_MESSAGE_DESC');
|
||||
verControl.addEventListener('click', domControlSignedClickHelper(this, dom, domText));
|
||||
}
|
||||
|
||||
dom.before(verControl, createElement('div'));
|
||||
if (encrypted) {
|
||||
verControl.title = i18n('MESSAGE/PGP_ENCRYPTED_MESSAGE_DESC');
|
||||
verControl.addEventListener('click', domControlEncryptedClickHelper(this, dom, domText, recipients));
|
||||
} else {
|
||||
verControl.title = i18n('MESSAGE/PGP_SIGNED_MESSAGE_DESC');
|
||||
verControl.addEventListener('click', domControlSignedClickHelper(this, dom, domText));
|
||||
}
|
||||
|
||||
dom.prepend(verControl);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -387,7 +387,7 @@ html.rl-no-preview-pane {
|
|||
&.plain {
|
||||
|
||||
padding: 15px;
|
||||
/*white-space: pre-wrap;*/
|
||||
white-space: pre-wrap;
|
||||
font-family: var(--fontMono);
|
||||
|
||||
pre {
|
||||
|
@ -398,22 +398,6 @@ html.rl-no-preview-pane {
|
|||
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 {
|
||||
border-left: 2px solid 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 {
|
||||
|
||||
display: inline-block;
|
||||
color: #FA0;
|
||||
cursor: pointer;
|
||||
display: block;
|
||||
opacity: 0.5;
|
||||
margin: 15px;
|
||||
|
||||
&:hover {
|
||||
opacity: 1;
|
||||
|
@ -442,7 +443,6 @@ html.rl-no-preview-pane {
|
|||
|
||||
&.success {
|
||||
color: green;
|
||||
cursor: help;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue