mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-28 19:49:20 +03:00
OpenPGP (#53) UNSTABLE
This commit is contained in:
parent
9d26fe049e
commit
ee19a5cb41
17 changed files with 1010 additions and 582 deletions
|
|
@ -36,6 +36,8 @@ function MailBoxMessageViewViewModel()
|
|||
this.fullScreenMode = oData.messageFullScreenMode;
|
||||
|
||||
this.showFullInfo = ko.observable(false);
|
||||
this.openPGPInformation = ko.observable('');
|
||||
this.openPGPInformation.isError = ko.observable(false);
|
||||
|
||||
this.messageVisibility = ko.computed(function () {
|
||||
return !this.messageLoadingThrottle() && !!this.message();
|
||||
|
|
@ -105,6 +107,14 @@ function MailBoxMessageViewViewModel()
|
|||
this.viewUserPic = ko.observable(Consts.DataImages.UserDotPic);
|
||||
this.viewUserPicVisible = ko.observable(false);
|
||||
|
||||
this.viewPgpSignedVerifyStatus = ko.computed(function () {
|
||||
return this.message() ? this.message().pgpSignedVerifyStatus() : Enums.SignedVerifyStatus.None;
|
||||
}, this);
|
||||
|
||||
this.viewPgpSignedVerifyUser = ko.computed(function () {
|
||||
return this.message() ? this.message().pgpSignedVerifyUser() : '';
|
||||
}, this);
|
||||
|
||||
this.message.subscribe(function (oMessage) {
|
||||
|
||||
this.messageActiveDom(null);
|
||||
|
|
@ -176,6 +186,41 @@ function MailBoxMessageViewViewModel()
|
|||
|
||||
Utils.extendAsViewModel('MailBoxMessageViewViewModel', MailBoxMessageViewViewModel);
|
||||
|
||||
MailBoxMessageViewViewModel.prototype.isPgpActionVisible = function ()
|
||||
{
|
||||
return Enums.SignedVerifyStatus.Success !== this.viewPgpSignedVerifyStatus();
|
||||
};
|
||||
|
||||
MailBoxMessageViewViewModel.prototype.isPgpStatusVerifyVisible = function ()
|
||||
{
|
||||
return Enums.SignedVerifyStatus.None !== this.viewPgpSignedVerifyStatus();
|
||||
};
|
||||
|
||||
MailBoxMessageViewViewModel.prototype.isPgpStatusVerifySuccess = function ()
|
||||
{
|
||||
return Enums.SignedVerifyStatus.Success === this.viewPgpSignedVerifyStatus();
|
||||
};
|
||||
|
||||
MailBoxMessageViewViewModel.prototype.pgpStatusVerifyMessage = function ()
|
||||
{
|
||||
var sResult = '';
|
||||
switch (this.viewPgpSignedVerifyStatus())
|
||||
{
|
||||
// TODO i18n
|
||||
case Enums.SignedVerifyStatus.Unverified:
|
||||
sResult = 'Unverified signature';
|
||||
break;
|
||||
case Enums.SignedVerifyStatus.Error:
|
||||
sResult = 'OpenPGP decryption error';
|
||||
break;
|
||||
case Enums.SignedVerifyStatus.Success:
|
||||
sResult = 'Good signature from ' + this.viewPgpSignedVerifyUser();
|
||||
break;
|
||||
}
|
||||
|
||||
return sResult;
|
||||
};
|
||||
|
||||
MailBoxMessageViewViewModel.prototype.scrollToTop = function ()
|
||||
{
|
||||
var oCont = $('.messageItem.nano .content', this.viewModelDom);
|
||||
|
|
@ -354,6 +399,28 @@ MailBoxMessageViewViewModel.prototype.showImages = function (oMessage)
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {MessageModel} oMessage
|
||||
*/
|
||||
MailBoxMessageViewViewModel.prototype.verifyPgpSignedClearMessage = function (oMessage)
|
||||
{
|
||||
if (oMessage)
|
||||
{
|
||||
oMessage.verifyPgpSignedClearMessage();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {MessageModel} oMessage
|
||||
*/
|
||||
MailBoxMessageViewViewModel.prototype.decryptPgpEncryptedMessage = function (oMessage)
|
||||
{
|
||||
if (oMessage)
|
||||
{
|
||||
oMessage.decryptPgpEncryptedMessage();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {MessageModel} oMessage
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -30,80 +30,26 @@ function PopupsComposeOpenPgpViewModel()
|
|||
var
|
||||
self = this,
|
||||
bResult = true,
|
||||
aOpenpgpkeysPublic = RL.data().openpgpkeysPublic(),
|
||||
oKey = null,
|
||||
oData = RL.data(),
|
||||
oPrivateKey = null,
|
||||
aPublicKeys = [],
|
||||
fFindPublicKey = function (sEmail) {
|
||||
|
||||
var
|
||||
oResult = null,
|
||||
oKey = _.find(aOpenpgpkeysPublic, function (oItem) {
|
||||
return oItem && sEmail === oItem.email;
|
||||
})
|
||||
;
|
||||
|
||||
if (oKey)
|
||||
{
|
||||
try
|
||||
{
|
||||
oResult = window.openpgp.key.readArmored(oKey.armor);
|
||||
if (oResult && !oResult.err && oResult.keys && oResult.keys[0])
|
||||
{
|
||||
oResult = oResult.keys[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
oResult = null;
|
||||
}
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
oResult = null;
|
||||
}
|
||||
}
|
||||
|
||||
return oResult;
|
||||
}
|
||||
aPublicKeys = []
|
||||
;
|
||||
|
||||
this.submitRequest(true);
|
||||
|
||||
if (bResult && this.sign() && '' === this.from())
|
||||
{
|
||||
this.notification('Please specify From email address');
|
||||
// TODO i18n
|
||||
this.notification('Please specify FROM email address');
|
||||
bResult = false;
|
||||
}
|
||||
|
||||
if (bResult && this.sign())
|
||||
{
|
||||
oKey = _.find(RL.data().openpgpkeysPrivate(), function (oItem) {
|
||||
return oItem && self.from() === oItem.email;
|
||||
});
|
||||
|
||||
if (oKey)
|
||||
{
|
||||
try
|
||||
{
|
||||
oPrivateKey = window.openpgp.key.readArmored(oKey.armor);
|
||||
if (oPrivateKey && !oPrivateKey.err && oPrivateKey.keys && oPrivateKey.keys[0])
|
||||
{
|
||||
oPrivateKey = oPrivateKey.keys[0];
|
||||
oPrivateKey.decrypt(this.password());
|
||||
}
|
||||
else
|
||||
{
|
||||
oPrivateKey = null;
|
||||
}
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
oPrivateKey = null;
|
||||
}
|
||||
}
|
||||
|
||||
oPrivateKey = oData.findPrivateKeyByEmail(this.from(), this.password());
|
||||
if (!oPrivateKey)
|
||||
{
|
||||
// TODO i18n
|
||||
this.notification('No private key found for "' + this.from() + '" email');
|
||||
bResult = false;
|
||||
}
|
||||
|
|
@ -111,25 +57,27 @@ function PopupsComposeOpenPgpViewModel()
|
|||
|
||||
if (bResult && this.encrypt() && 0 === this.to().length)
|
||||
{
|
||||
// TODO i18n
|
||||
this.notification('Please specify at least one recipient');
|
||||
bResult = false;
|
||||
}
|
||||
|
||||
if (bResult && this.encrypt())
|
||||
{
|
||||
aPublicKeys = _.compact(_.map(this.to(), function (sEmail) {
|
||||
var oKey = fFindPublicKey(sEmail);
|
||||
if (!oKey && bResult)
|
||||
aPublicKeys = _.compact(_.union(this.to(), function (sEmail) {
|
||||
var aKeys = oData.findPublicKeysByEmail(sEmail);
|
||||
if (0 === aKeys.length && bResult)
|
||||
{
|
||||
// TODO i18n
|
||||
self.notification('No public key found for "' + sEmail + '" email');
|
||||
bResult = false;
|
||||
}
|
||||
|
||||
return oKey;
|
||||
return aKeys;
|
||||
|
||||
}));
|
||||
|
||||
if (0 === aPublicKeys.length || this.to().length !== aPublicKeys.length)
|
||||
if (bResult && (0 === aPublicKeys.length || this.to().length !== aPublicKeys.length))
|
||||
{
|
||||
bResult = false;
|
||||
}
|
||||
|
|
@ -162,6 +110,7 @@ function PopupsComposeOpenPgpViewModel()
|
|||
}
|
||||
catch (e)
|
||||
{
|
||||
// TODO i18n
|
||||
self.notification('OpenPGP error: ' + e);
|
||||
bResult = false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue