diff --git a/dev/Stores/User/GnuPG.js b/dev/Stores/User/GnuPG.js index 88af3f74d..605067b1c 100644 --- a/dev/Stores/User/GnuPG.js +++ b/dev/Stores/User/GnuPG.js @@ -117,19 +117,6 @@ export const GnuPGUserStore = new class { return SettingsCapa('GnuPG'); } - importKey(key, callback) { - Remote.request('GnupgImportKey', - (iError, oData) => { - if (oData?.Result/* && (oData.Result.imported || oData.Result.secretimported)*/) { - this.loadKeyrings(); - } - callback?.(iError, oData); - }, { - key: key - } - ); - } - /** keyPair.privateKey keyPair.publicKey diff --git a/dev/View/Popup/OpenPgpImport.js b/dev/View/Popup/OpenPgpImport.js index f13fb7d10..a26291178 100644 --- a/dev/View/Popup/OpenPgpImport.js +++ b/dev/View/Popup/OpenPgpImport.js @@ -19,7 +19,7 @@ export class OpenPgpImportPopupView extends AbstractViewPopup { keyErrorMessage: '', saveGnuPG: true, - saveServer: false + saveServer: true }); this.canGnuPG = GnuPGUserStore.isSupported(); @@ -69,9 +69,22 @@ export class OpenPgpImportPopupView extends AbstractViewPopup { match = reg.exec(keyTrimmed); if (match && 0 < count) { if (match[0] && match[1] && match[2] && match[1] === match[2]) { - this.saveGnuPG() && GnuPGUserStore.isSupported() && GnuPGUserStore.importKey(this.key(), (iError, oData) => { - iError && alert(oData.ErrorMessage); - }); + const GnuPG = this.saveGnuPG() && GnuPGUserStore.isSupported(), + backup = this.saveServer(); + if (GnuPG || backup()) { + Remote.request('PgpImportKey', + (iError, oData) => { + if (GnuPG && oData?.Result/* && (oData.Result.imported || oData.Result.secretimported)*/) { + GnuPGUserStore.loadKeyrings(); + } + iError && alert(oData.ErrorMessage); + }, { + key: this.key(), + gnuPG: GnuPG, + backup: backup + } + ); + } OpenPGPUserStore.isSupported() && OpenPGPUserStore.importKey(this.key()); } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Pgp.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Pgp.php index 5fec23b18..d4d391e69 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Pgp.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Pgp.php @@ -190,7 +190,7 @@ trait Pgp return $this->DefaultResponse($GPG ? $GPG->deleteKey($sKeyId, $bPrivate) : false); } - public function DoGnupgImportKey() : array + public function DoPgpImportKey() : array { $sKey = $this->GetActionParam('key', ''); $sKeyId = $this->GetActionParam('keyId', ''); @@ -217,8 +217,17 @@ trait Pgp } } - $GPG = $sKey ? $this->GnuPG() : null; - return $this->DefaultResponse($GPG ? $GPG->import($sKey) : false); + $result = false; + if ($sKey) { + if ($this->GetActionParam('backup', '')) { + $result = $result || Backup::PGPKey($sKey); + } + if ($this->GetActionParam('gnuPG', '') && ($GPG = $this->GnuPG())) { + $result = $result || $GPG->import($sKey); + } + } + + return $this->DefaultResponse($result); } /** diff --git a/snappymail/v/0.0.0/app/templates/Views/User/PopupsOpenPgpImport.html b/snappymail/v/0.0.0/app/templates/Views/User/PopupsOpenPgpImport.html index d4948f069..46ca374e0 100644 --- a/snappymail/v/0.0.0/app/templates/Views/User/PopupsOpenPgpImport.html +++ b/snappymail/v/0.0.0/app/templates/Views/User/PopupsOpenPgpImport.html @@ -13,7 +13,6 @@
-