#89 Fix Mailvelope hasPrivateKey() detection

Proper rename OpenPGP Key viewer
This commit is contained in:
the-djmaze 2022-01-29 21:42:56 +01:00
parent b06b04a579
commit 76226f45ca
41 changed files with 252 additions and 200 deletions

View file

@ -2,9 +2,9 @@ import { Scope } from 'Common/Enums';
import { doc } from 'Common/Globals';
import { AbstractViewPopup } from 'Knoin/AbstractViews';
class ViewOpenPgpKeyPopupView extends AbstractViewPopup {
class OpenPgpKeyPopupView extends AbstractViewPopup {
constructor() {
super('ViewOpenPgpKey');
super('OpenPgpKey');
this.addObservables({
key: '',
@ -21,18 +21,25 @@ class ViewOpenPgpKeyPopupView extends AbstractViewPopup {
range.selectNodeContents(el);
sel.addRange(range);
}
if (navigator.clipboard) {
navigator.clipboard.writeText(this.key()).then(
() => console.log('Copied to clipboard'),
err => console.error(err)
);
}
}
onShow(openPgpKey) {
// TODO: show more info
this.key(openPgpKey ? openPgpKey.armor : '');
}
onBuild() {
shortcuts.add('a', 'meta', Scope.ViewOpenPgpKey, () => {
shortcuts.add('a', 'meta', Scope.OpenPgpKey, () => {
this.selectKey();
return false;
});
}
}
export { ViewOpenPgpKeyPopupView, ViewOpenPgpKeyPopupView as default };
export { OpenPgpKeyPopupView, OpenPgpKeyPopupView as default };

View file

@ -625,72 +625,71 @@ export class MailMessageView extends AbstractViewRight {
}
pgpDecrypt(self) {
const pgpInfo = self.pgpEncrypted();
const message = self.message(),
pgpInfo = message && message.pgpEncrypted();
if (pgpInfo) {
const message = self.message();
if (window.mailvelope) {
/**
* https://mailvelope.github.io/mailvelope/Mailvelope.html#createEncryptedFormContainer
* Creates an iframe to display an encrypted form
*/
// mailvelope.createEncryptedFormContainer('#mailvelope-form');
/**
* https://mailvelope.github.io/mailvelope/Mailvelope.html#createDisplayContainer
* Creates an iframe to display the decrypted content of the encrypted mail.
*/
let body = message.body;
body.textContent = '';
mailvelope.createDisplayContainer(
'#'+body.id,
message.plain(),
PgpUserStore.mailvelopeKeyring,
{
senderAddress: message.from[0].email
}
).then(status => {
if (status.error && status.error.message) {
alert(status.error.code + ': ' + status.error.message);
} else {
body.classList.add('mailvelope');
}
}, error => {
console.error(error);
});
}
/*
else {
// TODO: which key to decrypt, use pgpInfo.KeyIds
PgpUserStore.getKeyForDecrypting(message.email()).then(result => {
console.log({canPgpSign:result});
this.canPgpSign(!!result)
});
else if (window.openpgp) {
decryptMessage(message, recipients, fCallback)
}
else if (Settings.capa(Capa.GnuPG)) {
message.
let params = {
Folder: message.folder,
Uid: message.uid,
PartId: message.pgpEncrypted().PartId,
KeyId: '',
Passphrase: prompt("Passphrase", ''),
Data: '' // optional
// Also check message.from[0].email
PgpUserStore.getKeyForDecryption(pgpInfo.KeyIds, message.to[0].email).then(result => {
if (!result) {
// TODO: show error
alert('No decrypt key found for ids:\n\n' + pgpInfo.KeyIds.join('\n'));
return;
}
rl.app.Remote.post('GnupgDecrypt', null, params)
.then(data => {
// TODO
console.dir(data);
})
.catch(error => {
// TODO
console.dir(error);
if ('mailvelope' === result[0]) {
/**
* https://mailvelope.github.io/mailvelope/Mailvelope.html#createEncryptedFormContainer
* Creates an iframe to display an encrypted form
*/
// mailvelope.createEncryptedFormContainer('#mailvelope-form');
/**
* https://mailvelope.github.io/mailvelope/Mailvelope.html#createDisplayContainer
* Creates an iframe to display the decrypted content of the encrypted mail.
*/
let body = message.body;
body.textContent = '';
mailvelope.createDisplayContainer(
'#'+body.id,
message.plain(),
PgpUserStore.mailvelopeKeyring,
{
senderAddress: message.from[0].email
}
).then(status => {
if (status.error && status.error.message) {
alert(status.error.code + ': ' + status.error.message);
} else {
body.classList.add('mailvelope');
}
}, error => {
console.error(error);
});
}
*/
}
else if ('openpgp' === result[0]) {
// TODO
// PgpUserStore.decryptMessage(message, recipients, fCallback)
}
else if ('gnupg' === result[0]) {
let params = {
Folder: message.folder,
Uid: message.uid,
PartId: pgpInfo.PartId,
KeyId: result[1].id,
Passphrase: prompt('Passphrase for ' + result[1].id + ' ' + result[1].uids[0].uid),
Data: '' // optional
}
if (params.Passphrase) {
rl.app.Remote.post('GnupgDecrypt', null, params)
.then(data => {
// TODO
console.dir(data);
})
.catch(error => {
// TODO
console.dir(error);
});
}
}
});
}
}