mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
#89 Use OpenPGP.js v5.1.0 (still in progress)
This commit is contained in:
parent
dfd255545a
commit
ff7e41ad08
130 changed files with 1871 additions and 44411 deletions
98
dev/View/Popup/OpenPgpImport.js
Normal file
98
dev/View/Popup/OpenPgpImport.js
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
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';
|
||||
|
||||
export class OpenPgpImportPopupView extends AbstractViewPopup {
|
||||
constructor() {
|
||||
super('OpenPgpImport');
|
||||
|
||||
this.addObservables({
|
||||
key: '',
|
||||
keyError: false,
|
||||
keyErrorMessage: '',
|
||||
|
||||
saveGnuPG: true,
|
||||
saveServer: true
|
||||
});
|
||||
|
||||
this.canGnuPG = Settings.capa(Capa.GnuPG);
|
||||
|
||||
this.key.subscribe(() => {
|
||||
this.keyError(false);
|
||||
this.keyErrorMessage('');
|
||||
});
|
||||
|
||||
decorateKoCommands(this, {
|
||||
addOpenPgpKeyCommand: 1
|
||||
});
|
||||
}
|
||||
|
||||
addOpenPgpKeyCommand() {
|
||||
let keyTrimmed = this.key().trim();
|
||||
|
||||
if (/\n/.test(keyTrimmed)) {
|
||||
keyTrimmed = keyTrimmed.replace(/\r+/g, '').replace(/\n{2,}/g, '\n\n');
|
||||
}
|
||||
|
||||
this.keyError(!keyTrimmed);
|
||||
this.keyErrorMessage('');
|
||||
|
||||
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;
|
||||
|
||||
do {
|
||||
match = reg.exec(keyTrimmed);
|
||||
if (match && 0 < count) {
|
||||
if (match[0] && match[1] && match[2] && match[1] === match[2]) {
|
||||
let err = null;
|
||||
if (this.saveGnuPG()) {
|
||||
PgpUserStore.gnupgImportKey(this.key());
|
||||
}
|
||||
/*
|
||||
if (this.canOpenPGP && this.saveOpenPGP()) {
|
||||
if ('PRIVATE' === match[1]) {
|
||||
err = PgpUserStore.openpgpKeyring.privateKeys.importKey(match[0]);
|
||||
} else if ('PUBLIC' === match[1]) {
|
||||
err = PgpUserStore.openpgpKeyring.publicKeys.importKey(match[0]);
|
||||
}
|
||||
}
|
||||
*/
|
||||
if (err) {
|
||||
this.keyError(true);
|
||||
this.keyErrorMessage(err && err[0] ? '' + err[0] : '');
|
||||
console.log(err);
|
||||
}
|
||||
}
|
||||
|
||||
--count;
|
||||
done = false;
|
||||
} else {
|
||||
done = true;
|
||||
}
|
||||
} while (!done);
|
||||
|
||||
if (this.keyError()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.cancelCommand();
|
||||
return true;
|
||||
}
|
||||
|
||||
onShow() {
|
||||
this.key('');
|
||||
this.keyError(false);
|
||||
this.keyErrorMessage('');
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue