Cleanup pgp decrypt code and show green when decrypted

This commit is contained in:
the-djmaze 2022-02-17 10:18:47 +01:00
parent b2a492bdab
commit f4bed88e39
8 changed files with 280 additions and 302 deletions

View file

@ -75,10 +75,11 @@ export class MessageModel extends AbstractModel {
hasExternals: false, hasExternals: false,
pgpSigned: null, pgpSigned: null,
pgpEncrypted: null,
isPgpEncrypted: false,
pgpVerified: null, pgpVerified: null,
pgpEncrypted: null,
pgpDecrypted: false,
readReceipt: '', readReceipt: '',
hasUnseenSubMessage: false, hasUnseenSubMessage: false,
@ -153,10 +154,11 @@ export class MessageModel extends AbstractModel {
this.attachments(new AttachmentCollectionModel); this.attachments(new AttachmentCollectionModel);
this.pgpSigned(null); this.pgpSigned(null);
this.pgpEncrypted(null);
this.isPgpEncrypted(false);
this.pgpVerified(null); this.pgpVerified(null);
this.pgpEncrypted(null);
this.pgpDecrypted(false);
this.priority(MessagePriority.Normal); this.priority(MessagePriority.Normal);
this.readReceipt(''); this.readReceipt('');
@ -472,6 +474,7 @@ export class MessageModel extends AbstractModel {
initView() { initView() {
// init BlockquoteSwitcher // init BlockquoteSwitcher
this.body.querySelectorAll('blockquote:not(.rl-bq-switcher)').forEach(node => { this.body.querySelectorAll('blockquote:not(.rl-bq-switcher)').forEach(node => {
node.removeAttribute('style')
if (node.textContent.trim() && !node.parentNode.closest('blockquote')) { if (node.textContent.trim() && !node.parentNode.closest('blockquote')) {
let h = node.clientHeight || getRealHeight(node); let h = node.clientHeight || getRealHeight(node);
if (0 === h || 100 < h) { if (0 === h || 100 < h) {

View file

@ -372,7 +372,7 @@ export const MessageUserStore = new class {
} else { } else {
body = Element.fromHTML('<div id="' + id + '" hidden="" class="b-text-part ' body = Element.fromHTML('<div id="' + id + '" hidden="" class="b-text-part '
+ (message.pgpSigned() ? ' openpgp-signed' : '') + (message.pgpSigned() ? ' openpgp-signed' : '')
+ (message.isPgpEncrypted() ? ' openpgp-encrypted' : '') + (message.pgpEncrypted() ? ' openpgp-encrypted' : '')
+ '">' + '">'
+ '</div>'); + '</div>');
message.body = body; message.body = body;

View file

@ -176,7 +176,7 @@ export const
} }
} else { } else {
body.classList.add('mailvelope'); body.classList.add('mailvelope');
return; return true;
} }
} }
} }

View file

@ -174,6 +174,56 @@ html.rl-no-preview-pane {
} }
} }
.openpgp-control {
margin: 0.5em;
padding: 0.5em;
span {
margin-right: 1em;
}
button {
cursor: pointer;
}
&.encrypted {
border: 1px dashed #18F;
color: #18F;
}
&.signed {
border: 1px dashed #FA0;
color: #FA0;
}
&.success {
border-color: #090;
color: #090;
}
&.error {
border-color: #F00;
color: #F00;
}
&.error button,
&.success button {
display: none;
}
}
.b-text-part > iframe {
min-height: 50vh;
}
.thread-controls {
.dropdown-toggle {
padding-left: 10px;
padding-right: 10px;
}
&.open .dropdown-toggle {
padding-left: 10px;
padding-right: 10px;
}
}
}
#messageItem { #messageItem {
color: #000; color: #000;
@ -284,7 +334,6 @@ html.rl-no-preview-pane {
text-align: center; text-align: center;
cursor: pointer; cursor: pointer;
margin: 2em 0 10px; margin: 2em 0 10px;
opacity: 0.5; opacity: 0.5;
&:hover { &:hover {
opacity: 1; opacity: 1;
@ -294,6 +343,7 @@ html.rl-no-preview-pane {
.b-text-part { .b-text-part {
height: 100%; height: 100%;
padding: 10px;
div[data-x-div-type=html] { div[data-x-div-type=html] {
height: 100%; height: 100%;
@ -316,6 +366,7 @@ html.rl-no-preview-pane {
blockquote { blockquote {
border-left: 2px solid #000; border-left: 2px solid #000;
opacity: 0.8;
padding: 0 10px; padding: 0 10px;
margin: 0; margin: 0;
} }
@ -386,7 +437,6 @@ html.rl-no-preview-pane {
&.plain { &.plain {
padding: 15px;
white-space: pre-wrap; white-space: pre-wrap;
font-family: var(--fontMono); font-family: var(--fontMono);
@ -397,21 +447,6 @@ html.rl-no-preview-pane {
display: block; display: block;
word-break: normal; word-break: normal;
} }
blockquote {
border-left: 2px solid blue;
color: blue;
}
blockquote blockquote {
border-left: 2px solid green;
color: green;
}
blockquote blockquote blockquote {
border-left: 2px solid red;
color: red;
}
} }
/* /*
@ -432,56 +467,6 @@ html.rl-no-preview-pane {
} }
} }
.openpgp-control {
margin: 0.5em;
padding: 0.5em;
span {
margin-right: 1em;
}
button {
cursor: pointer;
}
&.encrypted {
border: 1px dashed #18F;
color: #18F;
}
&.signed {
border: 1px dashed #FA0;
color: #FA0;
}
&.success {
border-color: #090;
color: #090;
}
&.error {
border-color: #F00;
color: #F00;
}
&.error button,
&.success button {
display: none;
}
}
.b-text-part > iframe {
min-height: 50vh;
}
.thread-controls {
.dropdown-toggle {
padding-left: 10px;
padding-right: 10px;
}
&.open .dropdown-toggle {
padding-left: 10px;
padding-right: 10px;
}
}
}
html.rl-no-preview-pane .messageView { html.rl-no-preview-pane .messageView {
.toolbar { .toolbar {

View file

@ -583,7 +583,9 @@ export class MailMessageView extends AbstractViewRight {
pgpDecrypt() { pgpDecrypt() {
const oMessage = currentMessage(); const oMessage = currentMessage();
PgpUserStore.decrypt(oMessage).then(result => { PgpUserStore.decrypt(oMessage).then(result => {
if (result && result.data) { if (result) {
oMessage.pgpDecrypted(true);
if (result.data) {
MimeToMessage(result.data, oMessage); MimeToMessage(result.data, oMessage);
oMessage.html() ? oMessage.viewHtml() : oMessage.viewPlain(); oMessage.html() ? oMessage.viewHtml() : oMessage.viewPlain();
if (result.signatures && result.signatures.length) { if (result.signatures && result.signatures.length) {
@ -594,6 +596,7 @@ export class MailMessageView extends AbstractViewRight {
}); });
} }
} }
}
}); });
} }

View file

@ -78,8 +78,7 @@ class Message implements \JsonSerializable
$aThreads = array(), $aThreads = array(),
$aPgpSigned = null, $aPgpSigned = null,
$aPgpEncrypted = null, $aPgpEncrypted = null;
$bPgpEncrypted = false;
function __construct() function __construct()
{ {
@ -106,11 +105,6 @@ class Message implements \JsonSerializable
return $this->aPgpEncrypted; return $this->aPgpEncrypted;
} }
public function isPgpEncrypted() : bool
{
return $this->bPgpEncrypted || $this->aPgpEncrypted;
}
public function Folder() : string public function Folder() : string
{ {
return $this->sFolder; return $this->sFolder;
@ -491,10 +485,6 @@ class Message implements \JsonSerializable
$oMessage->sInReplyTo = $oFetchResponse->GetFetchEnvelopeValue(8, ''); $oMessage->sInReplyTo = $oFetchResponse->GetFetchEnvelopeValue(8, '');
} }
// Content-Type: multipart/encrypted; protocol="application/pgp-encrypted"
$oMessage->bPgpEncrypted = ('multipart/encrypted' === \strtolower($oMessage->sContentType)
&& 'application/pgp-encrypted' === \strtolower($oHeaders->ParameterValue(\MailSo\Mime\Enumerations\Header::CONTENT_TYPE, \MailSo\Mime\Enumerations\Parameter::PROTOCOL)));
if ($oBodyStructure) if ($oBodyStructure)
{ {
$gEncryptedParts = $oBodyStructure->SearchByContentType('multipart/encrypted'); $gEncryptedParts = $oBodyStructure->SearchByContentType('multipart/encrypted');
@ -573,12 +563,6 @@ class Message implements \JsonSerializable
]; ];
} }
if ('text/html' === $oPart->ContentType())
{
$aHtmlParts[] = $sText;
}
else
{
if (\str_contains($sText, '-----BEGIN PGP MESSAGE-----')) if (\str_contains($sText, '-----BEGIN PGP MESSAGE-----'))
{ {
$keyIds = []; $keyIds = [];
@ -592,6 +576,12 @@ class Message implements \JsonSerializable
]; ];
} }
if ('text/html' === $oPart->ContentType())
{
$aHtmlParts[] = $sText;
}
else
{
if ($oPart->IsFlowedFormat()) if ($oPart->IsFlowedFormat())
{ {
$sText = Utils::DecodeFlowedFormat($sText); $sText = Utils::DecodeFlowedFormat($sText);
@ -605,9 +595,7 @@ class Message implements \JsonSerializable
$oMessage->sHtml = \implode('<br>', $aHtmlParts); $oMessage->sHtml = \implode('<br>', $aHtmlParts);
$oMessage->sPlain = \trim(\implode("\n", $aPlainParts)); $oMessage->sPlain = \trim(\implode("\n", $aPlainParts));
$oMessage->bPgpEncrypted = !$oMessage->bPgpEncrypted && false !== \stripos($oMessage->sPlain, '-----BEGIN PGP MESSAGE-----'); unset($aHtmlParts, $aPlainParts);
unset($aHtmlParts, $aPlainParts, $aMatch);
} }
$gAttachmentsParts = $oBodyStructure->SearchAttachmentsParts(); $gAttachmentsParts = $oBodyStructure->SearchAttachmentsParts();

View file

@ -211,7 +211,6 @@ trait Response
$mResult['Plain'] = $mResponse->Plain(); $mResult['Plain'] = $mResponse->Plain();
// $this->GetCapa(Capa::OPEN_PGP) || $this->GetCapa(Capa::GNUPG) // $this->GetCapa(Capa::OPEN_PGP) || $this->GetCapa(Capa::GNUPG)
$mResult['isPgpEncrypted'] = $mResponse->isPgpEncrypted();
$mResult['PgpSigned'] = $mResponse->PgpSigned(); $mResult['PgpSigned'] = $mResponse->PgpSigned();
$mResult['PgpEncrypted'] = $mResponse->PgpEncrypted(); $mResult['PgpEncrypted'] = $mResponse->PgpEncrypted();

View file

@ -264,7 +264,7 @@
</div> </div>
</div> </div>
<div class="openpgp-control encrypted" data-bind="visible: message().pgpEncrypted() || message().isPgpEncrypted()"> <div class="openpgp-control encrypted" data-bind="visible: message().pgpEncrypted(), css: {'success': message().pgpDecrypted()}">
<span data-icon="🔒" data-i18n="OPENPGP/ENCRYPTED_MESSAGE"></span> <span data-icon="🔒" data-i18n="OPENPGP/ENCRYPTED_MESSAGE"></span>
<button class="btn" data-bind="visible: pgpSupported, click: pgpDecrypt" data-i18n="OPENPGP/BUTTON_DECRYPT"></button> <button class="btn" data-bind="visible: pgpSupported, click: pgpDecrypt" data-i18n="OPENPGP/BUTTON_DECRYPT"></button>
</div> </div>