mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-08 08:57:03 +03:00
Improved mailvelope handling
This commit is contained in:
parent
4a9bc53558
commit
d484392518
2 changed files with 54 additions and 52 deletions
|
|
@ -9,17 +9,15 @@ 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';
|
||||||
|
|
||||||
|
// https://mailvelope.github.io/mailvelope/Keyring.html
|
||||||
|
let mailvelopeKeyring = null;
|
||||||
|
|
||||||
export const
|
export const
|
||||||
BEGIN_PGP_MESSAGE = '-----BEGIN PGP MESSAGE-----',
|
BEGIN_PGP_MESSAGE = '-----BEGIN PGP MESSAGE-----',
|
||||||
// BEGIN_PGP_SIGNATURE = '-----BEGIN PGP SIGNATURE-----',
|
// BEGIN_PGP_SIGNATURE = '-----BEGIN PGP SIGNATURE-----',
|
||||||
// BEGIN_PGP_SIGNED = '-----BEGIN PGP SIGNED MESSAGE-----',
|
// BEGIN_PGP_SIGNED = '-----BEGIN PGP SIGNED MESSAGE-----',
|
||||||
|
|
||||||
PgpUserStore = new class {
|
PgpUserStore = new class {
|
||||||
constructor() {
|
|
||||||
// https://mailvelope.github.io/mailvelope/Keyring.html
|
|
||||||
this.mailvelopeKeyring = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
if (SettingsCapa('OpenPGP') && window.crypto && crypto.getRandomValues) {
|
if (SettingsCapa('OpenPGP') && window.crypto && crypto.getRandomValues) {
|
||||||
rl.loadScript(SettingsGet('StaticLibsJs').replace('/libs.', '/openpgp.'))
|
rl.loadScript(SettingsGet('StaticLibsJs').replace('/libs.', '/openpgp.'))
|
||||||
|
|
@ -38,7 +36,7 @@ export const
|
||||||
identifier = identifier || SettingsGet('Email');
|
identifier = identifier || SettingsGet('Email');
|
||||||
if (window.mailvelope) {
|
if (window.mailvelope) {
|
||||||
const fn = keyring => {
|
const fn = keyring => {
|
||||||
this.mailvelopeKeyring = keyring;
|
mailvelopeKeyring = keyring;
|
||||||
console.log('mailvelope ready');
|
console.log('mailvelope ready');
|
||||||
};
|
};
|
||||||
mailvelope.getKeyring().then(fn, err => {
|
mailvelope.getKeyring().then(fn, err => {
|
||||||
|
|
@ -79,8 +77,7 @@ export const
|
||||||
|
|
||||||
async mailvelopeHasPublicKeyForEmails(recipients) {
|
async mailvelopeHasPublicKeyForEmails(recipients) {
|
||||||
const
|
const
|
||||||
keyring = this.mailvelopeKeyring,
|
mailvelope = mailvelopeKeyring && await mailvelopeKeyring.validKeyForAddress(recipients)
|
||||||
mailvelope = keyring && await keyring.validKeyForAddress(recipients)
|
|
||||||
/*.then(LookupResult => Object.entries(LookupResult))*/,
|
/*.then(LookupResult => Object.entries(LookupResult))*/,
|
||||||
entries = mailvelope && Object.entries(mailvelope);
|
entries = mailvelope && Object.entries(mailvelope);
|
||||||
return entries && entries.filter(value => value[1]).length === recipients.length;
|
return entries && entries.filter(value => value[1]).length === recipients.length;
|
||||||
|
|
@ -104,8 +101,7 @@ export const
|
||||||
}
|
}
|
||||||
|
|
||||||
async getMailvelopePrivateKeyFor(email/*, sign*/) {
|
async getMailvelopePrivateKeyFor(email/*, sign*/) {
|
||||||
let keyring = this.mailvelopeKeyring;
|
if (mailvelopeKeyring && await mailvelopeKeyring.hasPrivateKey({email:email})) {
|
||||||
if (keyring && await keyring.hasPrivateKey({email:email})) {
|
|
||||||
return ['mailvelope', email];
|
return ['mailvelope', email];
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -145,6 +141,7 @@ export const
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try Mailvelope (does not support inline images)
|
// Try Mailvelope (does not support inline images)
|
||||||
|
if (mailvelopeKeyring) {
|
||||||
try {
|
try {
|
||||||
let emails = [...message.from,...message.to,...message.cc].validUnique(),
|
let emails = [...message.from,...message.to,...message.cc].validUnique(),
|
||||||
i = emails.length;
|
i = emails.length;
|
||||||
|
|
@ -164,7 +161,7 @@ export const
|
||||||
let result = await mailvelope.createDisplayContainer(
|
let result = await mailvelope.createDisplayContainer(
|
||||||
'#'+body.id,
|
'#'+body.id,
|
||||||
armoredText,
|
armoredText,
|
||||||
this.mailvelopeKeyring,
|
mailvelopeKeyring,
|
||||||
{
|
{
|
||||||
senderAddress: sender
|
senderAddress: sender
|
||||||
// emails[i].email
|
// emails[i].email
|
||||||
|
|
@ -186,6 +183,7 @@ export const
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Now try GnuPG
|
// Now try GnuPG
|
||||||
return GnuPGUserStore.decrypt(message);
|
return GnuPGUserStore.decrypt(message);
|
||||||
|
|
@ -217,19 +215,19 @@ export const
|
||||||
* So far this is only the autocrypt header.
|
* So far this is only the autocrypt header.
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
this.mailvelopeKeyring.additionalHeadersForOutgoingEmail(headers)
|
mailvelopeKeyring.additionalHeadersForOutgoingEmail(headers)
|
||||||
this.mailvelopeKeyring.addSyncHandler(syncHandlerObj)
|
mailvelopeKeyring.addSyncHandler(syncHandlerObj)
|
||||||
this.mailvelopeKeyring.createKeyBackupContainer(selector, options)
|
mailvelopeKeyring.createKeyBackupContainer(selector, options)
|
||||||
this.mailvelopeKeyring.createKeyGenContainer(selector, {
|
mailvelopeKeyring.createKeyGenContainer(selector, {
|
||||||
// userIds: [],
|
// userIds: [],
|
||||||
keySize: 4096
|
keySize: 4096
|
||||||
})
|
})
|
||||||
|
|
||||||
this.mailvelopeKeyring.exportOwnPublicKey(emailAddr).then(<AsciiArmored, Error>)
|
mailvelopeKeyring.exportOwnPublicKey(emailAddr).then(<AsciiArmored, Error>)
|
||||||
this.mailvelopeKeyring.importPublicKey(armored)
|
mailvelopeKeyring.importPublicKey(armored)
|
||||||
|
|
||||||
// https://mailvelope.github.io/mailvelope/global.html#SyncHandlerObject
|
// https://mailvelope.github.io/mailvelope/global.html#SyncHandlerObject
|
||||||
this.mailvelopeKeyring.addSyncHandler({
|
mailvelopeKeyring.addSyncHandler({
|
||||||
uploadSync
|
uploadSync
|
||||||
downloadSync
|
downloadSync
|
||||||
backup
|
backup
|
||||||
|
|
|
||||||
|
|
@ -455,6 +455,10 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.mailvelope iframe {
|
||||||
|
min-height: 400px;
|
||||||
|
}
|
||||||
|
|
||||||
html:not(.sm-msgView-bottom):not(.sm-msgView-side) {
|
html:not(.sm-msgView-bottom):not(.sm-msgView-side) {
|
||||||
#rl-right:not(.message-selected) #V-MailMessageView {
|
#rl-right:not(.message-selected) #V-MailMessageView {
|
||||||
display: none;
|
display: none;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue