mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-30 04:29:21 +03:00
Many more changes for #89
This commit is contained in:
parent
3cc3a76b23
commit
a7eeeb4f55
18 changed files with 310 additions and 236 deletions
|
|
@ -3,6 +3,9 @@ import { PgpUserStore } from 'Stores/User/Pgp';
|
|||
import { decorateKoCommands } from 'Knoin/Knoin';
|
||||
import { AbstractViewPopup } from 'Knoin/AbstractViews';
|
||||
|
||||
import { Capa } from 'Common/Enums';
|
||||
import { Settings } from 'Common/Globals';
|
||||
|
||||
class AddOpenPgpKeyPopupView extends AbstractViewPopup {
|
||||
constructor() {
|
||||
super('AddOpenPgpKey');
|
||||
|
|
@ -10,9 +13,15 @@ class AddOpenPgpKeyPopupView extends AbstractViewPopup {
|
|||
this.addObservables({
|
||||
key: '',
|
||||
keyError: false,
|
||||
keyErrorMessage: ''
|
||||
keyErrorMessage: '',
|
||||
|
||||
saveGnuPG: true,
|
||||
saveOpenPGP: true
|
||||
});
|
||||
|
||||
this.canGnuPG = Settings.capa(Capa.GnuPG);
|
||||
this.canOpenPGP = Settings.capa(Capa.OpenPGP);
|
||||
|
||||
this.key.subscribe(() => {
|
||||
this.keyError(false);
|
||||
this.keyErrorMessage('');
|
||||
|
|
@ -24,36 +33,40 @@ class AddOpenPgpKeyPopupView extends AbstractViewPopup {
|
|||
}
|
||||
|
||||
addOpenPgpKeyCommand() {
|
||||
// eslint-disable-next-line max-len
|
||||
const reg = /[-]{3,6}BEGIN[\s]PGP[\s](PRIVATE|PUBLIC)[\s]KEY[\s]BLOCK[-]{3,6}[\s\S]+?[-]{3,6}END[\s]PGP[\s](PRIVATE|PUBLIC)[\s]KEY[\s]BLOCK[-]{3,6}/gi,
|
||||
openpgpKeyring = PgpUserStore.openpgpKeyring;
|
||||
|
||||
let keyTrimmed = this.key().trim();
|
||||
|
||||
if (/[\n]/.test(keyTrimmed)) {
|
||||
keyTrimmed = keyTrimmed.replace(/[\r]+/g, '').replace(/[\n]{2,}/g, '\n\n');
|
||||
if (/\n/.test(keyTrimmed)) {
|
||||
keyTrimmed = keyTrimmed.replace(/\r+/g, '').replace(/\n{2,}/g, '\n\n');
|
||||
}
|
||||
|
||||
this.keyError(!keyTrimmed);
|
||||
this.keyErrorMessage('');
|
||||
|
||||
if (!openpgpKeyring || this.keyError()) {
|
||||
if (!keyTrimmed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let match = null,
|
||||
count = 30,
|
||||
done = false;
|
||||
// eslint-disable-next-line max-len
|
||||
const reg = /[-]{3,6}BEGIN[\s]PGP[\s](PRIVATE|PUBLIC)[\s]KEY[\s]BLOCK[-]{3,6}[\s\S]+?[-]{3,6}END[\s]PGP[\s](PRIVATE|PUBLIC)[\s]KEY[\s]BLOCK[-]{3,6}/gi,
|
||||
keyring = PgpUserStore.openpgpKeyring;
|
||||
|
||||
do {
|
||||
match = reg.exec(keyTrimmed);
|
||||
if (match && 0 < count) {
|
||||
if (match[0] && match[1] && match[2] && match[1] === match[2]) {
|
||||
let err = null;
|
||||
if ('PRIVATE' === match[1]) {
|
||||
err = openpgpKeyring.privateKeys.importKey(match[0]);
|
||||
} else if ('PUBLIC' === match[1]) {
|
||||
err = openpgpKeyring.publicKeys.importKey(match[0]);
|
||||
if (this.saveGnuPG()) {
|
||||
PgpUserStore.gnupgImportKey(this.key());
|
||||
}
|
||||
if (this.canOpenPGP && this.saveOpenPGP()) {
|
||||
if ('PRIVATE' === match[1]) {
|
||||
err = keyring.privateKeys.importKey(match[0]);
|
||||
} else if ('PUBLIC' === match[1]) {
|
||||
err = keyring.publicKeys.importKey(match[0]);
|
||||
}
|
||||
}
|
||||
|
||||
if (err) {
|
||||
|
|
@ -70,9 +83,11 @@ class AddOpenPgpKeyPopupView extends AbstractViewPopup {
|
|||
}
|
||||
} while (!done);
|
||||
|
||||
openpgpKeyring.store();
|
||||
if (this.canOpenPGP && this.saveOpenPGP()) {
|
||||
keyring.store();
|
||||
}
|
||||
|
||||
PgpUserStore.reloadOpenPgpKeys();
|
||||
// PgpUserStore.reloadOpenPgpKeys();
|
||||
|
||||
if (this.keyError()) {
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -133,8 +133,6 @@ class ComposePopupView extends AbstractViewPopup {
|
|||
|
||||
this.capaOpenPGP = PgpUserStore.isSupported();
|
||||
|
||||
this.identities = IdentityUserStore;
|
||||
|
||||
this.addObservables({
|
||||
identitiesDropdownTrigger: false,
|
||||
|
||||
|
|
@ -189,7 +187,7 @@ class ComposePopupView extends AbstractViewPopup {
|
|||
// div.textAreaParent
|
||||
composeEditorArea: null,
|
||||
|
||||
currentIdentity: this.identities()[0] ? this.identities()[0] : null
|
||||
currentIdentity: IdentityUserStore()[0] || null
|
||||
});
|
||||
|
||||
// this.to.subscribe((v) => console.log(v));
|
||||
|
|
@ -281,7 +279,7 @@ class ComposePopupView extends AbstractViewPopup {
|
|||
|
||||
currentIdentity: value => {
|
||||
this.canPgpSign(false);
|
||||
value && PgpUserStore.hasPrivateKeyForEmail(value.email()).then(result => {
|
||||
value && PgpUserStore.hasKeyForSigning(value.email()).then(result => {
|
||||
console.log({canPgpSign:result});
|
||||
this.canPgpSign(result)
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { pInt } from 'Common/Utils';
|
||||
|
||||
import { PgpUserStore } from 'Stores/User/Pgp';
|
||||
import { IdentityUserStore } from 'Stores/User/Identity';
|
||||
|
||||
import { decorateKoCommands } from 'Knoin/Knoin';
|
||||
import { AbstractViewPopup } from 'Knoin/AbstractViews';
|
||||
|
|
@ -9,6 +10,8 @@ class NewOpenPgpKeyPopupView extends AbstractViewPopup {
|
|||
constructor() {
|
||||
super('NewOpenPgpKey');
|
||||
|
||||
this.identities = IdentityUserStore;
|
||||
|
||||
this.addObservables({
|
||||
email: '',
|
||||
emailError: false,
|
||||
|
|
@ -63,6 +66,9 @@ class NewOpenPgpKeyPopupView extends AbstractViewPopup {
|
|||
openpgpKeyring.store();
|
||||
|
||||
PgpUserStore.reloadOpenPgpKeys();
|
||||
|
||||
PgpUserStore.gnupgImportKey(keyPair.privateKeyArmored);
|
||||
|
||||
this.cancelCommand();
|
||||
}
|
||||
})
|
||||
|
|
@ -87,13 +93,11 @@ class NewOpenPgpKeyPopupView extends AbstractViewPopup {
|
|||
}
|
||||
|
||||
onShow() {
|
||||
this.name('');
|
||||
this.name(IdentityUserStore()[0].name());
|
||||
this.password('');
|
||||
|
||||
this.email('');
|
||||
this.email(IdentityUserStore()[0].email());
|
||||
this.emailError(false);
|
||||
this.keyBitLength(4096);
|
||||
|
||||
this.submitError('');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -180,8 +180,7 @@ export class MailMessageView extends AbstractViewRight {
|
|||
|
||||
pgpSigned: () => MessageUserStore.message() && !!MessageUserStore.message().pgpSigned(),
|
||||
|
||||
pgpEncrypted: () => PgpUserStore.isSupported()
|
||||
&& MessageUserStore.message() && MessageUserStore.message().isPgpEncrypted(),
|
||||
pgpEncrypted: () => MessageUserStore.message() && MessageUserStore.message().isPgpEncrypted(),
|
||||
|
||||
messageListOrViewLoading:
|
||||
() => MessageUserStore.listIsLoading() | MessageUserStore.messageLoading()
|
||||
|
|
@ -624,11 +623,65 @@ export class MailMessageView extends AbstractViewRight {
|
|||
|
||||
pgpDecrypt(self) {
|
||||
const message = self.message();
|
||||
message && message.pgpDecrypt();
|
||||
if (message && PgpUserStore.isSupported()) {
|
||||
// pgpClickHelper(message.body, message.plain(), message.getEmails(['from', 'to', 'cc']));
|
||||
/*
|
||||
pgpEncrypted: () => PgpUserStore.isSupported()
|
||||
&& MessageUserStore.message() && MessageUserStore.message().isPgpEncrypted(),
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
pgpVerify(self) {
|
||||
const message = self.message();
|
||||
message && message.pgpVerify();
|
||||
if (message && PgpUserStore.isSupported()) {
|
||||
const mode = PgpUserStore.hasPublicKeyForEmails([message.from[0].email()]);
|
||||
if ('gnupg' === mode) {
|
||||
let params = message.pgpSigned(); // { BodyPartId: "1", SigPartId: "2", MicAlg: "pgp-sha256" }
|
||||
if (params) {
|
||||
params.Folder = message.folder;
|
||||
params.Uid = message.uid;
|
||||
rl.app.Remote.post('MessagePgpVerify', null, params)
|
||||
.then(data => {
|
||||
// TODO
|
||||
console.dir(data);
|
||||
})
|
||||
.catch(error => {
|
||||
// TODO
|
||||
console.dir(error);
|
||||
});
|
||||
}
|
||||
} else if ('openpgp' === mode) {
|
||||
let text = null;
|
||||
try {
|
||||
text = PgpUserStore.openpgp.cleartext.readArmored(message.plain);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
if (text && text.getText && text.verify) {
|
||||
PgpUserStore.verifyMessage(text, (validKey, signingKeyIds) => {
|
||||
console.dir([validKey, signingKeyIds]);
|
||||
/*
|
||||
if (validKey) {
|
||||
i18n('PGP_NOTIFICATIONS/GOOD_SIGNATURE', {
|
||||
USER: validKey.user + ' (' + validKey.id + ')'
|
||||
});
|
||||
message.getText()
|
||||
} else {
|
||||
const keyIds = arrayLength(signingKeyIds) ? signingKeyIds : null,
|
||||
additional = keyIds
|
||||
? keyIds.map(item => (item && item.toHex ? item.toHex() : null)).filter(v => v).join(', ')
|
||||
: '';
|
||||
|
||||
i18n('PGP_NOTIFICATIONS/UNVERIFIRED_SIGNATURE') + (additional ? ' (' + additional + ')' : '');
|
||||
}
|
||||
*/
|
||||
});
|
||||
} else {
|
||||
// controlsHelper(dom, this, false, i18n('PGP_NOTIFICATIONS/DECRYPTION_ERROR'));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue