mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Automaticaly add PGP key from Autocrypt #89
This commit is contained in:
parent
e28085fbba
commit
17cb093b32
3 changed files with 55 additions and 22 deletions
|
|
@ -9,6 +9,8 @@ import { SettingsCapa, SettingsGet } from 'Common/Globals';
|
||||||
import { GnuPGUserStore } from 'Stores/User/GnuPG';
|
import { GnuPGUserStore } from 'Stores/User/GnuPG';
|
||||||
import { OpenPGPUserStore } from 'Stores/User/OpenPGP';
|
import { OpenPGPUserStore } from 'Stores/User/OpenPGP';
|
||||||
|
|
||||||
|
import Remote from 'Remote/User/Fetch';
|
||||||
|
|
||||||
// https://mailvelope.github.io/mailvelope/Keyring.html
|
// https://mailvelope.github.io/mailvelope/Keyring.html
|
||||||
let mailvelopeKeyring = null;
|
let mailvelopeKeyring = null;
|
||||||
|
|
||||||
|
|
@ -75,6 +77,22 @@ export const
|
||||||
return 0 === text.trim().indexOf(BEGIN_PGP_MESSAGE);
|
return 0 === text.trim().indexOf(BEGIN_PGP_MESSAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
importKey(key, gnuPG, backup) {
|
||||||
|
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, gnuPG, backup
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
OpenPGPUserStore.isSupported() && OpenPGPUserStore.importKey(key);
|
||||||
|
}
|
||||||
|
|
||||||
async mailvelopeHasPublicKeyForEmails(recipients) {
|
async mailvelopeHasPublicKeyForEmails(recipients) {
|
||||||
const
|
const
|
||||||
mailvelope = mailvelopeKeyring && await mailvelopeKeyring.validKeyForAddress(recipients)
|
mailvelope = mailvelopeKeyring && await mailvelopeKeyring.validKeyForAddress(recipients)
|
||||||
|
|
|
||||||
|
|
@ -28,9 +28,12 @@ import { SettingsUserStore } from 'Stores/User/Settings';
|
||||||
import { IdentityUserStore } from 'Stores/User/Identity';
|
import { IdentityUserStore } from 'Stores/User/Identity';
|
||||||
import { AccountUserStore } from 'Stores/User/Account';
|
import { AccountUserStore } from 'Stores/User/Account';
|
||||||
import { FolderUserStore } from 'Stores/User/Folder';
|
import { FolderUserStore } from 'Stores/User/Folder';
|
||||||
|
|
||||||
import { PgpUserStore } from 'Stores/User/Pgp';
|
import { PgpUserStore } from 'Stores/User/Pgp';
|
||||||
import { OpenPGPUserStore } from 'Stores/User/OpenPGP';
|
import { OpenPGPUserStore } from 'Stores/User/OpenPGP';
|
||||||
import { GnuPGUserStore } from 'Stores/User/GnuPG';
|
import { GnuPGUserStore } from 'Stores/User/GnuPG';
|
||||||
|
//import { OpenPgpImportPopupView } from 'View/Popup/OpenPgpImport';
|
||||||
|
|
||||||
import { MessageUserStore } from 'Stores/User/Message';
|
import { MessageUserStore } from 'Stores/User/Message';
|
||||||
import { MessagelistUserStore } from 'Stores/User/Messagelist';
|
import { MessagelistUserStore } from 'Stores/User/Messagelist';
|
||||||
|
|
||||||
|
|
@ -46,6 +49,7 @@ import { AbstractViewPopup } from 'Knoin/AbstractViews';
|
||||||
import { FolderSystemPopupView } from 'View/Popup/FolderSystem';
|
import { FolderSystemPopupView } from 'View/Popup/FolderSystem';
|
||||||
import { AskPopupView } from 'View/Popup/Ask';
|
import { AskPopupView } from 'View/Popup/Ask';
|
||||||
import { ContactsPopupView } from 'View/Popup/Contacts';
|
import { ContactsPopupView } from 'View/Popup/Contacts';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
import { ThemeStore } from 'Stores/Theme';
|
import { ThemeStore } from 'Stores/Theme';
|
||||||
|
|
||||||
|
|
@ -350,10 +354,11 @@ export class ComposePopupView extends AbstractViewPopup {
|
||||||
value && PgpUserStore.getKeyForSigning(value).then(result => {
|
value && PgpUserStore.getKeyForSigning(value).then(result => {
|
||||||
console.log({
|
console.log({
|
||||||
email: value,
|
email: value,
|
||||||
canPgpSign:result
|
canPgpSign:!!result
|
||||||
});
|
});
|
||||||
this.canPgpSign(result)
|
this.canPgpSign(!!result)
|
||||||
});
|
});
|
||||||
|
this.initPgpEncrypt();
|
||||||
},
|
},
|
||||||
|
|
||||||
cc: value => {
|
cc: value => {
|
||||||
|
|
@ -858,7 +863,10 @@ export class ComposePopupView extends AbstractViewPopup {
|
||||||
|
|
||||||
switch (options.mode) {
|
switch (options.mode) {
|
||||||
case ComposeType.Reply:
|
case ComposeType.Reply:
|
||||||
case ComposeType.ReplyAll:
|
case ComposeType.ReplyAll: {
|
||||||
|
// if (1 == oLastMessage.to.length) {
|
||||||
|
// setTimeout(() => this.from(emailArrayToStringLineHelper(oLastMessage.to)), 1);
|
||||||
|
// }
|
||||||
if (ComposeType.Reply === options.mode) {
|
if (ComposeType.Reply === options.mode) {
|
||||||
this.to(emailArrayToStringLineHelper(oLastMessage.replyEmails(excludeEmail)));
|
this.to(emailArrayToStringLineHelper(oLastMessage.replyEmails(excludeEmail)));
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -872,8 +880,30 @@ export class ComposePopupView extends AbstractViewPopup {
|
||||||
this.sInReplyTo = oLastMessage.messageId;
|
this.sInReplyTo = oLastMessage.messageId;
|
||||||
this.sReferences = (oLastMessage.references + ' ' + oLastMessage.messageId).trim();
|
this.sReferences = (oLastMessage.references + ' ' + oLastMessage.messageId).trim();
|
||||||
// OpenPGP “Transferable Public Key”
|
// OpenPGP “Transferable Public Key”
|
||||||
// oLastMessage.autocrypt?.keydata
|
let autocrypt = {}, value = oLastMessage.headers().valueByName('autocrypt');
|
||||||
break;
|
if (value) {
|
||||||
|
value.split(';').forEach(entry => {
|
||||||
|
entry = entry.split('=', 2);
|
||||||
|
autocrypt[entry[0].trim()] = entry[1].trim();
|
||||||
|
});
|
||||||
|
if (autocrypt.addr && autocrypt.keydata) {
|
||||||
|
PgpUserStore.hasPublicKeyForEmails([autocrypt.addr]).then(result =>
|
||||||
|
result || PgpUserStore.importKey(
|
||||||
|
'-----BEGIN PGP PUBLIC KEY BLOCK-----\n\n'
|
||||||
|
+ autocrypt.keydata
|
||||||
|
+ '\n-----END PGP PUBLIC KEY BLOCK-----',
|
||||||
|
true, true)
|
||||||
|
/*
|
||||||
|
result || showScreenPopup(OpenPgpImportPopupView,
|
||||||
|
['-----BEGIN PGP PUBLIC KEY BLOCK-----\n\n'
|
||||||
|
+ autocrypt.keydata
|
||||||
|
+ '\n-----END PGP PUBLIC KEY BLOCK-----']
|
||||||
|
)
|
||||||
|
*/
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
|
||||||
case ComposeType.Forward:
|
case ComposeType.Forward:
|
||||||
case ComposeType.ForwardAsAttachment:
|
case ComposeType.ForwardAsAttachment:
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { addObservablesTo } from 'External/ko';
|
import { addObservablesTo } from 'External/ko';
|
||||||
import { GnuPGUserStore } from 'Stores/User/GnuPG';
|
import { GnuPGUserStore } from 'Stores/User/GnuPG';
|
||||||
import { OpenPGPUserStore } from 'Stores/User/OpenPGP';
|
import { PgpUserStore } from 'Stores/User/Pgp';
|
||||||
|
|
||||||
import { AbstractViewPopup } from 'Knoin/AbstractViews';
|
import { AbstractViewPopup } from 'Knoin/AbstractViews';
|
||||||
|
|
||||||
|
|
@ -94,23 +94,8 @@ export class OpenPgpImportPopupView extends AbstractViewPopup {
|
||||||
if (match[0] && match[1] && match[2] && match[1] === match[2]) {
|
if (match[0] && match[1] && match[2] && match[1] === match[2]) {
|
||||||
const GnuPG = this.saveGnuPG() && GnuPGUserStore.isSupported(),
|
const GnuPG = this.saveGnuPG() && GnuPGUserStore.isSupported(),
|
||||||
backup = this.saveServer();
|
backup = this.saveServer();
|
||||||
if (GnuPG || backup()) {
|
PgpUserStore.importKey(this.key(), 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());
|
|
||||||
}
|
|
||||||
|
|
||||||
--count;
|
--count;
|
||||||
done = false;
|
done = false;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue