OpenPGP (#53) UNSTABLE

This commit is contained in:
RainLoop Team 2014-04-01 22:03:37 +04:00
parent 9d26fe049e
commit ee19a5cb41
17 changed files with 1010 additions and 582 deletions

View file

@ -306,10 +306,10 @@ module.exports = function (grunt) {
"dev/Settings/Identity.js",
"dev/Settings/Identities.js",
"dev/Settings/Social.js",
"dev/Settings/OpenPGP.js",
"dev/Settings/ChangePassword.js",
"dev/Settings/Folders.js",
"dev/Settings/Themes.js",
"dev/Settings/OpenPGP.js",
"dev/Storages/AbstractData.js",
"dev/Storages/WebMailData.js",

View file

@ -250,6 +250,16 @@ Enums.ContactScopeType = {
'ShareAll': 2
};
/**
* @enum {number}
*/
Enums.SignedVerifyStatus = {
'Unverified': -2,
'Error': -1,
'None': 0,
'Success': 1
};
/**
* @enum {number}
*/

View file

@ -4,5 +4,9 @@
/**
* @type {?RainLoopApp}
*/
var RL = null;
var
RL = null,
$proxyDiv = $('<div></div>')
;
/*jshint onevar: true*/

View file

@ -91,7 +91,8 @@ function MessageModel()
this.isPgpSigned = ko.observable(false);
this.isPgpEncrypted = ko.observable(false);
this.pgpSignature = ko.observable('');
this.pgpSignedVerifyStatus = ko.observable(Enums.SignedVerifyStatus.None);
this.pgpSignedVerifyUser = ko.observable('');
this.priority = ko.observable(Enums.MessagePriority.Normal);
this.readReceipt = ko.observable('');
@ -263,7 +264,8 @@ MessageModel.prototype.clear = function ()
this.isPgpSigned(false);
this.isPgpEncrypted(false);
this.pgpSignature('');
this.pgpSignedVerifyStatus(Enums.SignedVerifyStatus.None);
this.pgpSignedVerifyUser('');
this.priority(Enums.MessagePriority.Normal);
this.readReceipt('');
@ -363,7 +365,6 @@ MessageModel.prototype.initUpdateByMessageJson = function (oJsonMessage)
{
this.isPgpSigned(!!oJsonMessage.PgpSigned);
this.isPgpEncrypted(!!oJsonMessage.PgpEncrypted);
this.pgpSignature(oJsonMessage.PgpSignature);
}
this.hasAttachments(!!oJsonMessage.HasAttachments);
@ -830,7 +831,6 @@ MessageModel.prototype.populateByMessageListItem = function (oMessage)
// this.isPgpSigned(false);
// this.isPgpEncrypted(false);
// this.pgpSignature('');
this.priority(Enums.MessagePriority.Normal);
this.aDraftInfo = [];
@ -897,12 +897,12 @@ MessageModel.prototype.showInternalImages = function (bLazy)
{
if (this.body && !this.body.data('rl-init-internal-images'))
{
this.body.data('rl-init-internal-images', true);
bLazy = Utils.isUnd(bLazy) ? false : bLazy;
var self = this;
this.body.data('rl-init-internal-images', true);
$('[data-x-src-cid]', this.body).each(function () {
var oAttachment = self.findAttachmentByCid($(this).attr('data-x-src-cid'));
@ -981,3 +981,128 @@ MessageModel.prototype.showInternalImages = function (bLazy)
Utils.windowResize(500);
}
};
MessageModel.prototype.storeDataToDom = function ()
{
if (this.body)
{
this.body.data('rl-is-rtl', !!this.isRtl());
this.body.data('rl-is-html', !!this.isHtml());
this.body.data('rl-has-images', !!this.hasImages());
this.body.data('rl-plain-raw', this.plainRaw);
if (RL.data().allowOpenPGP())
{
this.body.data('rl-plain-pgp-signed', !!this.isPgpSigned());
this.body.data('rl-plain-pgp-encrypted', !!this.isPgpEncrypted());
this.body.data('rl-pgp-verify-status', this.pgpSignedVerifyStatus());
this.body.data('rl-pgp-verify-user', this.pgpSignedVerifyUser());
}
}
};
MessageModel.prototype.storePgpVerifyDataToDom = function ()
{
if (this.body && RL.data().allowOpenPGP())
{
this.body.data('rl-pgp-verify-status', this.pgpSignedVerifyStatus());
this.body.data('rl-pgp-verify-user', this.pgpSignedVerifyUser());
}
};
MessageModel.prototype.fetchDataToDom = function ()
{
if (this.body)
{
this.isRtl(!!this.body.data('rl-is-rtl'));
this.isHtml(!!this.body.data('rl-is-html'));
this.hasImages(!!this.body.data('rl-has-images'));
this.plainRaw = Utils.pString(this.body.data('rl-plain-raw'));
if (RL.data().allowOpenPGP())
{
this.isPgpSigned(!!this.body.data('rl-plain-pgp-signed'));
this.isPgpEncrypted(!!this.body.data('rl-plain-pgp-encrypted'));
this.pgpSignedVerifyStatus(this.body.data('rl-pgp-verify-status'));
this.pgpSignedVerifyUser(this.body.data('rl-pgp-verify-user'));
}
else
{
this.isPgpSigned(false);
this.isPgpEncrypted(false);
this.pgpSignedVerifyStatus(Enums.SignedVerifyStatus.None);
this.pgpSignedVerifyUser('');
}
}
};
MessageModel.prototype.verifyPgpSignedClearMessage = function ()
{
if (this.isPgpSigned())
{
var
aRes = [],
mPgpMessage = null,
sFrom = this.from && this.from[0] && this.from[0].email ? this.from[0].email : '',
aPublicKey = RL.data().findPublicKeysByEmail(sFrom),
oValidKey = null,
oValidSysKey = null,
sPlain = ''
;
this.pgpSignedVerifyStatus(Enums.SignedVerifyStatus.Error);
this.pgpSignedVerifyUser('');
try
{
mPgpMessage = window.openpgp.cleartext.readArmored(this.plainRaw);
if (mPgpMessage && mPgpMessage.getText)
{
this.pgpSignedVerifyStatus(Enums.SignedVerifyStatus.Unverified);
aRes = mPgpMessage.verify(aPublicKey);
if (aRes && 0 < aRes.length)
{
oValidKey = _.find(aRes, function (oItem) {
return oItem && oItem.keyid && oItem.valid;
});
if (oValidKey)
{
oValidSysKey = RL.data().findPublicKeyByHex(oValidKey.keyid.toHex());
if (oValidSysKey)
{
sPlain = mPgpMessage.getText();
this.pgpSignedVerifyStatus(Enums.SignedVerifyStatus.Success);
this.pgpSignedVerifyUser(oValidSysKey.user);
sPlain =
$proxyDiv.empty().append(
$('<pre class="b-plain-openpgp signed verified"></pre>').text(sPlain)
).html()
;
$proxyDiv.empty();
this.replacePlaneTextBody(sPlain);
}
}
}
}
}
catch (oExc) {}
this.storePgpVerifyDataToDom();
}
};
MessageModel.prototype.replacePlaneTextBody = function (sPlain)
{
if (this.body)
{
this.body.html(sPlain).addClass('b-text-part plain');
}
};

View file

@ -883,49 +883,43 @@ WebMailDataStorage.prototype.setMessage = function (oData, bCached)
RL.data().allowOpenPGP() &&
Utils.isNormal(oData.Result.PlainRaw))
{
bPgpEncrypted = /---BEGIN PGP MESSAGE---/.test(oData.Result.PlainRaw);
oMessage.plainRaw = Utils.pString(oData.Result.PlainRaw);
bPgpEncrypted = /---BEGIN PGP MESSAGE---/.test(oMessage.plainRaw);
if (!bPgpEncrypted)
{
bPgpSigned = /-----BEGIN PGP SIGNED MESSAGE-----/.test(oData.Result.PlainRaw) &&
/-----BEGIN PGP SIGNATURE-----/.test(oData.Result.PlainRaw);
bPgpSigned = /-----BEGIN PGP SIGNED MESSAGE-----/.test(oMessage.plainRaw) &&
/-----BEGIN PGP SIGNATURE-----/.test(oMessage.plainRaw);
}
if (bPgpSigned && oMessage.isPgpSigned() && oMessage.pgpSignature())
$proxyDiv.empty();
if (bPgpSigned && oMessage.isPgpSigned())
{
sPlain = '<pre class="b-plain-openpgp signed">' + oData.Result.PlainRaw + '</pre>';
try
{
mPgpMessage = window.openpgp.cleartext.readArmored(oData.Result.PlainRaw);
}
catch (oExc) {}
if (mPgpMessage && mPgpMessage.getText)
{
sPlain = mPgpMessage.getText();
}
else
{
bPgpSigned = false;
}
sPlain =
$proxyDiv.append(
$('<pre class="b-plain-openpgp signed"></pre>').text(oMessage.plainRaw)
).html()
;
}
else if (bPgpEncrypted && oMessage.isPgpEncrypted())
{
try
{
mPgpMessage = window.openpgp.message.readArmored(oData.Result.PlainRaw);
}
catch (oExc) {}
// try
// {
// mPgpMessage = window.openpgp.message.readArmored(oMessage.plainRaw);
// }
// catch (oExc) {}
sPlain = '<pre class="b-plain-openpgp encrypted">' + oData.Result.PlainRaw + '</pre>';
sPlain =
$proxyDiv.append(
$('<pre class="b-plain-openpgp encrypted"></pre>').text(oMessage.plainRaw)
).html()
;
}
if (bPgpSigned || bPgpEncrypted)
{
oBody.data('rl-plain-raw', oData.Result.PlainRaw);
oBody.data('rl-plain-pgp-encrypted', bPgpEncrypted);
oBody.data('rl-plain-pgp-signed', bPgpSigned);
}
$proxyDiv.empty();
oMessage.isPgpSigned(bPgpSigned);
oMessage.isPgpEncrypted(bPgpEncrypted);
}
oBody.html(sPlain).addClass('b-text-part plain');
@ -935,9 +929,14 @@ WebMailDataStorage.prototype.setMessage = function (oData, bCached)
bIsHtml = false;
}
oMessage.isHtml(!!bIsHtml);
oMessage.hasImages(!!bHasExternals);
oMessage.pgpSignedVerifyStatus(Enums.SignedVerifyStatus.None);
oMessage.pgpSignedVerifyUser('');
if (oData.Result.Rtl)
{
oBody.data('rl-is-rtl', true);
this.isRtl(true);
oBody.addClass('rtl-text-part');
}
@ -945,14 +944,6 @@ WebMailDataStorage.prototype.setMessage = function (oData, bCached)
if (oMessage.body)
{
oMessagesBodiesDom.append(oMessage.body);
oMessage.body.data('rl-is-html', bIsHtml);
oMessage.body.data('rl-has-images', bHasExternals);
oMessage.isRtl(!!oMessage.body.data('rl-is-rtl'));
oMessage.isHtml(!!oMessage.body.data('rl-is-html'));
oMessage.hasImages(!!oMessage.body.data('rl-has-images'));
oMessage.plainRaw = Utils.pString(oMessage.body.data('rl-plain-raw'));
}
if (bHasInternals)
@ -965,6 +956,7 @@ WebMailDataStorage.prototype.setMessage = function (oData, bCached)
oMessage.showExternalImages(true);
}
oMessage.storeDataToDom();
this.purgeMessageBodyCacheThrottle();
}
else
@ -973,24 +965,10 @@ WebMailDataStorage.prototype.setMessage = function (oData, bCached)
if (oMessage.body)
{
oMessage.body.data('rl-cache-count', ++Globals.iMessageBodyCacheCount);
oMessage.isRtl(!!oMessage.body.data('rl-is-rtl'));
oMessage.isHtml(!!oMessage.body.data('rl-is-html'));
oMessage.hasImages(!!oMessage.body.data('rl-has-images'));
oMessage.plainRaw = Utils.pString(oMessage.body.data('rl-plain-raw'));
oMessage.fetchDataToDom();
}
}
if (oMessage.body && RL.data().allowOpenPGP())
{
oMessage.isPgpSigned(!!oMessage.body.data('rl-plain-pgp-signed'));
oMessage.isPgpEncrypted(!!oMessage.body.data('rl-plain-pgp-encrypted'));
}
else
{
oMessage.isPgpSigned(false);
oMessage.isPgpEncrypted(false);
}
this.messageActiveDom(oMessage.body);
this.hideMessageBodies();
@ -1148,3 +1126,66 @@ WebMailDataStorage.prototype.setMessageList = function (oData, bCached)
));
}
};
WebMailDataStorage.prototype.findPublicKeyByHex = function (sHash)
{
return _.find(this.openpgpkeysPublic(), function (oItem) {
return oItem && sHash === oItem.id;
});
};
WebMailDataStorage.prototype.findPublicKeysByEmail = function (sEmail)
{
return _.compact(_.map(this.openpgpkeysPublic(), function (oItem) {
var oKey = null;
if (oItem && sEmail === oItem.email)
{
try
{
oKey = window.openpgp.key.readArmored(oItem.armor);
if (oKey && !oKey.err && oKey.keys && oKey.keys[0])
{
return oKey.keys[0];
}
}
catch (e) {}
}
return null;
}));
};
WebMailDataStorage.prototype.findPrivateKeyByEmail = function (sEmail, sPass)
{
var
oPrivateKey = null,
oKey = _.find(this.openpgpkeysPrivate(), function (oItem) {
return oItem && sEmail === 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(sPass);
}
else
{
oPrivateKey = null;
}
}
catch (e)
{
oPrivateKey = null;
}
}
return oPrivateKey;
};

View file

@ -187,6 +187,16 @@ html.rl-no-preview-pane {
background-color: #eee;
}
.pgpInfo {
padding: 5px 15px;
border-bottom: 1px solid #ddd;
background-color: #fcf8e3;
&.success {
background-color: #e9f4ff;
}
}
.readReceipt {
background-color: #ffffd9;
}

View file

@ -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
*/

View file

@ -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;
}

View file

@ -22,8 +22,8 @@
</div>
<div class="btn-group">&nbsp;</div>
<div class="btn-group btn-group-custom-margin">
<a class="btn btn-danger buttonDelete" data-placement="bottom" data-bind="command: deleteCommand, tooltip: 'MESSAGE_LIST/BUTTON_DELETE'">
<i class="icon-trash icon-white"></i>
<a class="btn buttonDelete" data-placement="bottom" data-bind="command: deleteCommand, tooltip: 'MESSAGE_LIST/BUTTON_DELETE'">
<i class="icon-trash"></i>
<span data-bind="text: 1 < messageListCheckedOrSelectedUidsWithSubMails().length ? ' (' + messageListCheckedOrSelectedUidsWithSubMails().length + ')' : ''"></span>
</a>
<a class="btn buttonSpam" data-placement="bottom" data-bind="visible: !isSpamFolder() && !isSpamDisabled(), command: spamCommand, tooltip: 'MESSAGE_LIST/BUTTON_SPAM'">

View file

@ -2,58 +2,58 @@
<div class="messageView" data-bind="css: {'message-selected': isMessageSelected}">
<div class="toolbar g-ui-user-select-none">
<div class="messageButtons btn-toolbar">
<div class="btn-group" data-placement="bottom" data-bind="visible: !$root.usePreviewPane(), tooltip: 'MESSAGE/BUTTON_CLOSE'">
<a class="btn buttonClose" data-bind="command: $root.closeMessage">
<div class="btn-group" data-placement="bottom" data-bind="visible: !usePreviewPane(), tooltip: 'MESSAGE/BUTTON_CLOSE'">
<a class="btn buttonClose" data-bind="command: closeMessage">
<i class="icon-remove"></i>
</a>
</div>
<div class="btn-group">&nbsp;</div>
<div class="btn-group" data-placement="bottom" data-bind="visible: $root.isDraftFolder(), tooltip: 'MESSAGE/BUTTON_EDIT'">
<a class="btn btn-success buttonEdit" data-bind="command: $root.messageEditCommand">
<div class="btn-group" data-placement="bottom" data-bind="visible: isDraftFolder(), tooltip: 'MESSAGE/BUTTON_EDIT'">
<a class="btn btn-success buttonEdit" data-bind="command: messageEditCommand">
<i class="icon-pencil icon-white"></i>
</a>
</div>
<div class="btn-group" data-bind="visible: !$root.isDraftFolder()">
<a class="btn buttonReply" data-placement="bottom" data-bind="command: $root.replyCommand, tooltip: 'MESSAGE/BUTTON_REPLY'">
<div class="btn-group" data-bind="visible: !isDraftFolder()">
<a class="btn buttonReply" data-placement="bottom" data-bind="command: replyCommand, tooltip: 'MESSAGE/BUTTON_REPLY'">
<i class="icon-reply"></i>
</a>
<a class="btn buttonReplyAll" data-placement="bottom" data-bind="command: $root.replyAllCommand, tooltip: 'MESSAGE/BUTTON_REPLY_ALL'">
<a class="btn buttonReplyAll" data-placement="bottom" data-bind="command: replyAllCommand, tooltip: 'MESSAGE/BUTTON_REPLY_ALL'">
<i class="icon-reply-all"></i>
</a>
<a class="btn buttonForward" data-placement="bottom" data-bind=" command: $root.forwardCommand, tooltip: 'MESSAGE/BUTTON_FORWARD'">
<a class="btn buttonForward" data-placement="bottom" data-bind=" command: forwardCommand, tooltip: 'MESSAGE/BUTTON_FORWARD'">
<i class="icon-forward"></i>
</a>
</div>
<div class="btn-group">&nbsp;</div>
<div class="btn-group btn-group-custom-margin">
<a class="btn btn-danger buttonDelete" data-placement="bottom" data-bind="command: $root.deleteCommand, tooltip: 'MESSAGE/BUTTON_DELETE'">
<a class="btn btn-danger buttonDelete" data-placement="bottom" data-bind="command: deleteCommand, tooltip: 'MESSAGE/BUTTON_DELETE'">
<i class="icon-trash icon-white"></i>
</a>
<a class="btn buttonSpam" data-placement="bottom" data-bind="visible: !$root.isDraftFolder(), command: $root.spamCommand, tooltip: 'MESSAGE/BUTTON_SPAM'">
<a class="btn buttonSpam" data-placement="bottom" data-bind="visible: !isDraftFolder(), command: spamCommand, tooltip: 'MESSAGE/BUTTON_SPAM'">
<i class="icon-bug"></i>
</a>
</div>
<div class="btn-group">&nbsp;</div>
<div class="btn-group">
<a class="btn dropdown-toggle buttonMore" data-placement="bottom" data-toggle="dropdown" data-bind="command: $root.messageVisibilityCommand, tooltip: 'MESSAGE/BUTTON_MORE'">
<a class="btn dropdown-toggle buttonMore" data-placement="bottom" data-toggle="dropdown" data-bind="command: messageVisibilityCommand, tooltip: 'MESSAGE/BUTTON_MORE'">
<i class="icon-list"></i>
</a>
<ul class="dropdown-menu g-ui-menu">
<li class="e-item" data-bind="visible: !$root.isDraftFolder()">
<a class="e-link" data-bind="command: $root.forwardAsAttachmentCommand">
<li class="e-item" data-bind="visible: !isDraftFolder()">
<a class="e-link" data-bind="command: forwardAsAttachmentCommand">
<i class="icon-reply"></i>
&nbsp;&nbsp;
<span class="i18n" data-i18n-text="MESSAGE/BUTTON_FORWARD_AS_ATTACHMENT"></span>
</a>
</li>
<li class="e-item" data-bind="visible: !$root.isDraftFolder()">
<a class="e-link" data-bind="command: $root.editAsNewCommand">
<li class="e-item" data-bind="visible: !isDraftFolder()">
<a class="e-link" data-bind="command: editAsNewCommand">
<i class="icon-pencil"></i>
&nbsp;&nbsp;
<span class="i18n" data-i18n-text="MESSAGE/BUTTON_EDIT_AS_NEW"></span>
</a>
</li>
<li class="divider" data-bind="visible: !$root.isDraftFolder()"></li>
<li class="divider" data-bind="visible: !isDraftFolder()"></li>
<li class="e-item">
<a target="_blank" class="e-link" data-bind="click: function () { if (message()) { message().viewPopupMessage(); }}">
<i class="icon-popup"></i>
@ -86,11 +86,11 @@
</ul>
</div>
<div class="btn-group">&nbsp;</div>
<div class="btn-group" data-bind="visible: !$root.usePreviewPane()">
<a class="btn buttonUp" data-bind="command: $root.goUpCommand">
<div class="btn-group" data-bind="visible: !usePreviewPane()">
<a class="btn buttonUp" data-bind="command: goUpCommand">
<i class="icon-left-middle"></i>
</a>
<a class="btn buttonDown" data-bind="command: $root.goDownCommand">
<a class="btn buttonDown" data-bind="command: goDownCommand">
<i class="icon-right-middle"></i>
</a>
</div>
@ -98,11 +98,11 @@
</div>
<div class="b-content thm-message-view-background-color">
<div>
<div class="b-message-view-desc" data-bind="visible: !message() && '' === $root.messageError()">
<div class="b-message-view-desc" data-bind="visible: !message() && '' === messageError()">
<span class="i18n" data-i18n-text="MESSAGE/MESSAGE_VIEW_DESC"></span>
</div>
<div class="b-message-view-desc error" data-bind="visible: !message() && '' !== $root.messageError()">
<span class="text" data-bind="text: $root.messageError()"></span>
<div class="b-message-view-desc error" data-bind="visible: !message() && '' !== messageError()">
<span class="text" data-bind="text: messageError()"></span>
</div>
<div data-bind="visible: message">
<div class="messageItem" data-bind="css: viewLineAsCcc(), nano: true">
@ -127,14 +127,14 @@
<span class="i18n emptySubjectText" data-i18n-text="MESSAGE/EMPTY_SUBJECT_TEXT"></span>
</div>
<div class="senderParent">
<div class="g-ui-user-select-none" style="float: left; cursor: pointer;" data-bind="click: function() { $root.showFullInfo(!$root.showFullInfo()); }">
<i class="icon-right-dir" data-bind="css: $root.showFullInfo() ? 'icon-down-dir' : 'icon-right-dir'"></i>
<div class="g-ui-user-select-none" style="float: left; cursor: pointer;" data-bind="click: function() { showFullInfo(!showFullInfo()); }">
<i class="icon-right-dir" data-bind="css: showFullInfo() ? 'icon-down-dir' : 'icon-right-dir'"></i>
</div>
<div class="informationShort" data-bind="event: { 'dblclick': toggleFullScreen }">
<span data-bind="visible: !$root.isDraftOrSentFolder()">
<span data-bind="visible: !isDraftOrSentFolder()">
<span class="from" data-bind="html: viewFromShort, title: viewFrom"></span>
</span>
<span data-bind="visible: $root.isDraftOrSentFolder()">
<span data-bind="visible: isDraftOrSentFolder()">
<span class="i18n uiLabel labelTo" data-i18n-text="MESSAGE/LABEL_TO"></span>:
<span class="to" data-bind="html: viewToShort, title: viewTo"></span>
</span>
@ -143,7 +143,7 @@
<div class="clearfix"></div>
</div>
</div>
<div class="informationFull" data-bind="visible: $root.showFullInfo()">
<div class="informationFull" data-bind="visible: showFullInfo()">
<div data-bind="visible: '' !== viewFrom()">
<span class="i18n uiLabel labelFrom" data-i18n-text="MESSAGE/LABEL_FROM"></span>:
&nbsp;
@ -175,33 +175,41 @@
</div>
</div>
<div class="line-loading e-strip-animation" data-bind="visible: $root.messageLoadingThrottle()"></div>
<div class="line-loading e-strip-animation" data-bind="visible: messageLoadingThrottle()"></div>
<div class="loading g-ui-min-height-300" data-bind="visible: $root.messageLoadingThrottle()">
<div class="loading g-ui-min-height-300" data-bind="visible: messageLoadingThrottle()">
<span class="i18n text" data-i18n-text="MESSAGE/MESSAGE_LOADING"></span><span class="textLoadingAnimationD1">.</span><span class="textLoadingAnimationD2">.</span><span class="textLoadingAnimationD3">.</span>
</div>
</div>
<div class="g-ui-min-height-300" data-bind="visible: !$root.messageLoadingThrottle()">
<div class="showImages" data-bind="visible: message() && message().hasImages(), click: function() { $root.showImages(message()); }">
<div class="g-ui-min-height-300" data-bind="visible: !messageLoadingThrottle()">
<div class="showImages" data-bind="visible: message() && message().hasImages(), click: function() { showImages(message()); }">
<i class="icon-image"></i>
&nbsp;&nbsp;
<span class="i18n text" data-i18n-text="MESSAGE/BUTTON_SHOW_IMAGES"></span>
</div>
<div class="readReceipt" data-bind="visible: message() && '' !== message().readReceipt() && !message().isReadReceipt(), click: function() { $root.readReceipt(message()); }">
<div class="readReceipt" data-bind="visible: message() && '' !== message().readReceipt() && !message().isReadReceipt(), click: function() { readReceipt(message()); }">
<i class="icon-mail"></i>
&nbsp;&nbsp;
<span class="i18n text" data-i18n-text="MESSAGE/BUTTON_NOTIFY_READ_RECEIPT"></span>
</div>
<div class="pgpSigned" data-bind="visible: message() && message().isPgpSigned()">
<div class="pgpInfo" data-bind="visible: isPgpStatusVerifyVisible(), css: {'success': isPgpStatusVerifySuccess()}">
<i class="icon-key"></i>
&nbsp;&nbsp;
<span data-bind="text: pgpStatusVerifyMessage()"></span>
</div>
<div class="pgpSigned" data-bind="visible: message() && message().isPgpSigned() && isPgpActionVisible(), click: function() { verifyPgpSignedClearMessage(message()); }">
<i class="icon-lock"></i>
&nbsp;&nbsp;
PGP signed
OpenPGP signed message (click to verify)
</div>
<div class="pgpEncrypted" data-bind="visible: message() && message().isPgpEncrypted()">
<i class="icon-lock"></i>
&nbsp;&nbsp;
PGP encrypted
<span data-bind="click: function() { decryptPgpEncryptedMessage(message()); }">
OpenPGP encrypted message (click to decrypt)
</span>
<input type="password" />
</div>
<div class="attachmentsPlace" data-bind="visible: message() && message().hasVisibleAttachments()">
<ul class="attachmentList" data-bind="foreach: message() ? message().attachments() : []">

View file

@ -7226,6 +7226,14 @@ html.rl-no-preview-pane .messageView.message-selected {
border-bottom: 1px solid #ddd;
background-color: #eee;
}
.messageView .b-content .messageItem .pgpInfo {
padding: 5px 15px;
border-bottom: 1px solid #ddd;
background-color: #fcf8e3;
}
.messageView .b-content .messageItem .pgpInfo.success {
background-color: #e9f4ff;
}
.messageView .b-content .messageItem .readReceipt {
background-color: #ffffd9;
}

File diff suppressed because one or more lines are too long

View file

@ -590,6 +590,16 @@ Enums.ContactScopeType = {
'ShareAll': 2
};
/**
* @enum {number}
*/
Enums.SignedVerifyStatus = {
'Unverified': -2,
'Error': -1,
'None': 0,
'Success': 1
};
/**
* @enum {number}
*/

File diff suppressed because one or more lines are too long

View file

@ -75,7 +75,11 @@ var
/**
* @type {?RainLoopApp}
*/
var RL = null;
var
RL = null,
$proxyDiv = $('<div></div>')
;
/*jshint onevar: true*/
/**
@ -590,6 +594,16 @@ Enums.ContactScopeType = {
'ShareAll': 2
};
/**
* @enum {number}
*/
Enums.SignedVerifyStatus = {
'Unverified': -2,
'Error': -1,
'None': 0,
'Success': 1
};
/**
* @enum {number}
*/
@ -6097,7 +6111,8 @@ function MessageModel()
this.isPgpSigned = ko.observable(false);
this.isPgpEncrypted = ko.observable(false);
this.pgpSignature = ko.observable('');
this.pgpSignedVerifyStatus = ko.observable(Enums.SignedVerifyStatus.None);
this.pgpSignedVerifyUser = ko.observable('');
this.priority = ko.observable(Enums.MessagePriority.Normal);
this.readReceipt = ko.observable('');
@ -6269,7 +6284,8 @@ MessageModel.prototype.clear = function ()
this.isPgpSigned(false);
this.isPgpEncrypted(false);
this.pgpSignature('');
this.pgpSignedVerifyStatus(Enums.SignedVerifyStatus.None);
this.pgpSignedVerifyUser('');
this.priority(Enums.MessagePriority.Normal);
this.readReceipt('');
@ -6369,7 +6385,6 @@ MessageModel.prototype.initUpdateByMessageJson = function (oJsonMessage)
{
this.isPgpSigned(!!oJsonMessage.PgpSigned);
this.isPgpEncrypted(!!oJsonMessage.PgpEncrypted);
this.pgpSignature(oJsonMessage.PgpSignature);
}
this.hasAttachments(!!oJsonMessage.HasAttachments);
@ -6836,7 +6851,6 @@ MessageModel.prototype.populateByMessageListItem = function (oMessage)
// this.isPgpSigned(false);
// this.isPgpEncrypted(false);
// this.pgpSignature('');
this.priority(Enums.MessagePriority.Normal);
this.aDraftInfo = [];
@ -6903,12 +6917,12 @@ MessageModel.prototype.showInternalImages = function (bLazy)
{
if (this.body && !this.body.data('rl-init-internal-images'))
{
this.body.data('rl-init-internal-images', true);
bLazy = Utils.isUnd(bLazy) ? false : bLazy;
var self = this;
this.body.data('rl-init-internal-images', true);
$('[data-x-src-cid]', this.body).each(function () {
var oAttachment = self.findAttachmentByCid($(this).attr('data-x-src-cid'));
@ -6988,6 +7002,131 @@ MessageModel.prototype.showInternalImages = function (bLazy)
}
};
MessageModel.prototype.storeDataToDom = function ()
{
if (this.body)
{
this.body.data('rl-is-rtl', !!this.isRtl());
this.body.data('rl-is-html', !!this.isHtml());
this.body.data('rl-has-images', !!this.hasImages());
this.body.data('rl-plain-raw', this.plainRaw);
if (RL.data().allowOpenPGP())
{
this.body.data('rl-plain-pgp-signed', !!this.isPgpSigned());
this.body.data('rl-plain-pgp-encrypted', !!this.isPgpEncrypted());
this.body.data('rl-pgp-verify-status', this.pgpSignedVerifyStatus());
this.body.data('rl-pgp-verify-user', this.pgpSignedVerifyUser());
}
}
};
MessageModel.prototype.storePgpVerifyDataToDom = function ()
{
if (this.body && RL.data().allowOpenPGP())
{
this.body.data('rl-pgp-verify-status', this.pgpSignedVerifyStatus());
this.body.data('rl-pgp-verify-user', this.pgpSignedVerifyUser());
}
};
MessageModel.prototype.fetchDataToDom = function ()
{
if (this.body)
{
this.isRtl(!!this.body.data('rl-is-rtl'));
this.isHtml(!!this.body.data('rl-is-html'));
this.hasImages(!!this.body.data('rl-has-images'));
this.plainRaw = Utils.pString(this.body.data('rl-plain-raw'));
if (RL.data().allowOpenPGP())
{
this.isPgpSigned(!!this.body.data('rl-plain-pgp-signed'));
this.isPgpEncrypted(!!this.body.data('rl-plain-pgp-encrypted'));
this.pgpSignedVerifyStatus(this.body.data('rl-pgp-verify-status'));
this.pgpSignedVerifyUser(this.body.data('rl-pgp-verify-user'));
}
else
{
this.isPgpSigned(false);
this.isPgpEncrypted(false);
this.pgpSignedVerifyStatus(Enums.SignedVerifyStatus.None);
this.pgpSignedVerifyUser('');
}
}
};
MessageModel.prototype.verifyPgpSignedClearMessage = function ()
{
if (this.isPgpSigned())
{
var
aRes = [],
mPgpMessage = null,
sFrom = this.from && this.from[0] && this.from[0].email ? this.from[0].email : '',
aPublicKey = RL.data().findPublicKeysByEmail(sFrom),
oValidKey = null,
oValidSysKey = null,
sPlain = ''
;
this.pgpSignedVerifyStatus(Enums.SignedVerifyStatus.Error);
this.pgpSignedVerifyUser('');
try
{
mPgpMessage = window.openpgp.cleartext.readArmored(this.plainRaw);
if (mPgpMessage && mPgpMessage.getText)
{
this.pgpSignedVerifyStatus(Enums.SignedVerifyStatus.Unverified);
aRes = mPgpMessage.verify(aPublicKey);
if (aRes && 0 < aRes.length)
{
oValidKey = _.find(aRes, function (oItem) {
return oItem && oItem.keyid && oItem.valid;
});
if (oValidKey)
{
oValidSysKey = RL.data().findPublicKeyByHex(oValidKey.keyid.toHex());
if (oValidSysKey)
{
sPlain = mPgpMessage.getText();
this.pgpSignedVerifyStatus(Enums.SignedVerifyStatus.Success);
this.pgpSignedVerifyUser(oValidSysKey.user);
sPlain =
$proxyDiv.empty().append(
$('<pre class="b-plain-openpgp signed verified"></pre>').text(sPlain)
).html()
;
$proxyDiv.empty();
this.replacePlaneTextBody(sPlain);
}
}
}
}
}
catch (oExc) {}
this.storePgpVerifyDataToDom();
}
};
MessageModel.prototype.replacePlaneTextBody = function (sPlain)
{
if (this.body)
{
this.body.html(sPlain).addClass('b-text-part plain');
}
};
/**
* @constructor
*/
@ -10295,80 +10434,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;
}
@ -10376,25 +10461,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;
}
@ -10427,6 +10514,7 @@ function PopupsComposeOpenPgpViewModel()
}
catch (e)
{
// TODO i18n
self.notification('OpenPGP error: ' + e);
bResult = false;
}
@ -12079,6 +12167,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();
@ -12148,6 +12238,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);
@ -12219,6 +12317,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);
@ -12397,6 +12530,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
*/
@ -13058,91 +13213,6 @@ function SettingsSocialScreen()
Utils.addSettingsViewModel(SettingsSocialScreen, 'SettingsSocial', 'SETTINGS_LABELS/LABEL_SOCIAL_NAME', 'social');
/**
* @constructor
*/
function SettingsOpenPGP()
{
this.openpgpkeys = RL.data().openpgpkeys;
this.openpgpkeysPublic = RL.data().openpgpkeysPublic;
this.openpgpkeysPrivate = RL.data().openpgpkeysPrivate;
this.openPgpKeyForDeletion = ko.observable(null).extend({'falseTimeout': 3000}).extend({'toggleSubscribe': [this,
function (oPrev) {
if (oPrev)
{
oPrev.deleteAccess(false);
}
}, function (oNext) {
if (oNext)
{
oNext.deleteAccess(true);
}
}
]});
}
Utils.addSettingsViewModel(SettingsOpenPGP, 'SettingsOpenPGP', 'SETTINGS_LABELS/LABEL_OPEN_PGP_NAME', 'openpgp');
SettingsOpenPGP.prototype.addOpenPgpKey = function ()
{
kn.showScreenPopup(PopupsAddOpenPgpKeyViewModel);
};
SettingsOpenPGP.prototype.generateOpenPgpKey = function ()
{
kn.showScreenPopup(PopupsGenerateNewOpenPgpKeyViewModel);
};
SettingsOpenPGP.prototype.viewOpenPgpKey = function (oOpenPgpKey)
{
if (oOpenPgpKey)
{
kn.showScreenPopup(PopupsViewOpenPgpKeyViewModel, [oOpenPgpKey]);
}
};
/**
* @param {OpenPgpKeyModel} oOpenPgpKeyToRemove
*/
SettingsOpenPGP.prototype.deleteOpenPgpKey = function (oOpenPgpKeyToRemove)
{
if (oOpenPgpKeyToRemove && oOpenPgpKeyToRemove.deleteAccess())
{
this.openPgpKeyForDeletion(null);
var
iFindIndex = -1,
oOpenpgpKeyring = RL.data().openpgpKeyring,
fRemoveAccount = function (oOpenPgpKey) {
return oOpenPgpKeyToRemove === oOpenPgpKey;
}
;
if (oOpenPgpKeyToRemove && oOpenpgpKeyring)
{
this.openpgpkeys.remove(fRemoveAccount);
_.each(oOpenpgpKeyring.keys, function (oKey, iIndex) {
if (-1 === iFindIndex && oKey && oKey.primaryKey &&
oOpenPgpKeyToRemove.guid === oKey.primaryKey.getFingerprint() &&
oOpenPgpKeyToRemove.isPrivate === oKey.isPrivate())
{
iFindIndex = iIndex;
}
});
if (0 <= iFindIndex)
{
oOpenpgpKeyring.removeKey(iFindIndex);
}
oOpenpgpKeyring.store();
RL.reloadOpenPgpKeys();
}
}
};
/**
* @constructor
*/
@ -13627,6 +13697,91 @@ SettingsThemes.prototype.initCustomThemeUploader = function ()
};
/**
* @constructor
*/
function SettingsOpenPGP()
{
this.openpgpkeys = RL.data().openpgpkeys;
this.openpgpkeysPublic = RL.data().openpgpkeysPublic;
this.openpgpkeysPrivate = RL.data().openpgpkeysPrivate;
this.openPgpKeyForDeletion = ko.observable(null).extend({'falseTimeout': 3000}).extend({'toggleSubscribe': [this,
function (oPrev) {
if (oPrev)
{
oPrev.deleteAccess(false);
}
}, function (oNext) {
if (oNext)
{
oNext.deleteAccess(true);
}
}
]});
}
Utils.addSettingsViewModel(SettingsOpenPGP, 'SettingsOpenPGP', 'SETTINGS_LABELS/LABEL_OPEN_PGP_NAME', 'openpgp');
SettingsOpenPGP.prototype.addOpenPgpKey = function ()
{
kn.showScreenPopup(PopupsAddOpenPgpKeyViewModel);
};
SettingsOpenPGP.prototype.generateOpenPgpKey = function ()
{
kn.showScreenPopup(PopupsGenerateNewOpenPgpKeyViewModel);
};
SettingsOpenPGP.prototype.viewOpenPgpKey = function (oOpenPgpKey)
{
if (oOpenPgpKey)
{
kn.showScreenPopup(PopupsViewOpenPgpKeyViewModel, [oOpenPgpKey]);
}
};
/**
* @param {OpenPgpKeyModel} oOpenPgpKeyToRemove
*/
SettingsOpenPGP.prototype.deleteOpenPgpKey = function (oOpenPgpKeyToRemove)
{
if (oOpenPgpKeyToRemove && oOpenPgpKeyToRemove.deleteAccess())
{
this.openPgpKeyForDeletion(null);
var
iFindIndex = -1,
oOpenpgpKeyring = RL.data().openpgpKeyring,
fRemoveAccount = function (oOpenPgpKey) {
return oOpenPgpKeyToRemove === oOpenPgpKey;
}
;
if (oOpenPgpKeyToRemove && oOpenpgpKeyring)
{
this.openpgpkeys.remove(fRemoveAccount);
_.each(oOpenpgpKeyring.keys, function (oKey, iIndex) {
if (-1 === iFindIndex && oKey && oKey.primaryKey &&
oOpenPgpKeyToRemove.guid === oKey.primaryKey.getFingerprint() &&
oOpenPgpKeyToRemove.isPrivate === oKey.isPrivate())
{
iFindIndex = iIndex;
}
});
if (0 <= iFindIndex)
{
oOpenpgpKeyring.removeKey(iFindIndex);
}
oOpenpgpKeyring.store();
RL.reloadOpenPgpKeys();
}
}
};
/**
* @constructor
*/
@ -14585,49 +14740,43 @@ WebMailDataStorage.prototype.setMessage = function (oData, bCached)
RL.data().allowOpenPGP() &&
Utils.isNormal(oData.Result.PlainRaw))
{
bPgpEncrypted = /---BEGIN PGP MESSAGE---/.test(oData.Result.PlainRaw);
oMessage.plainRaw = Utils.pString(oData.Result.PlainRaw);
bPgpEncrypted = /---BEGIN PGP MESSAGE---/.test(oMessage.plainRaw);
if (!bPgpEncrypted)
{
bPgpSigned = /-----BEGIN PGP SIGNED MESSAGE-----/.test(oData.Result.PlainRaw) &&
/-----BEGIN PGP SIGNATURE-----/.test(oData.Result.PlainRaw);
bPgpSigned = /-----BEGIN PGP SIGNED MESSAGE-----/.test(oMessage.plainRaw) &&
/-----BEGIN PGP SIGNATURE-----/.test(oMessage.plainRaw);
}
if (bPgpSigned && oMessage.isPgpSigned() && oMessage.pgpSignature())
$proxyDiv.empty();
if (bPgpSigned && oMessage.isPgpSigned())
{
sPlain = '<pre class="b-plain-openpgp signed">' + oData.Result.PlainRaw + '</pre>';
try
{
mPgpMessage = window.openpgp.cleartext.readArmored(oData.Result.PlainRaw);
}
catch (oExc) {}
if (mPgpMessage && mPgpMessage.getText)
{
sPlain = mPgpMessage.getText();
}
else
{
bPgpSigned = false;
}
sPlain =
$proxyDiv.append(
$('<pre class="b-plain-openpgp signed"></pre>').text(oMessage.plainRaw)
).html()
;
}
else if (bPgpEncrypted && oMessage.isPgpEncrypted())
{
try
{
mPgpMessage = window.openpgp.message.readArmored(oData.Result.PlainRaw);
}
catch (oExc) {}
// try
// {
// mPgpMessage = window.openpgp.message.readArmored(oMessage.plainRaw);
// }
// catch (oExc) {}
sPlain = '<pre class="b-plain-openpgp encrypted">' + oData.Result.PlainRaw + '</pre>';
sPlain =
$proxyDiv.append(
$('<pre class="b-plain-openpgp encrypted"></pre>').text(oMessage.plainRaw)
).html()
;
}
if (bPgpSigned || bPgpEncrypted)
{
oBody.data('rl-plain-raw', oData.Result.PlainRaw);
oBody.data('rl-plain-pgp-encrypted', bPgpEncrypted);
oBody.data('rl-plain-pgp-signed', bPgpSigned);
}
$proxyDiv.empty();
oMessage.isPgpSigned(bPgpSigned);
oMessage.isPgpEncrypted(bPgpEncrypted);
}
oBody.html(sPlain).addClass('b-text-part plain');
@ -14637,9 +14786,14 @@ WebMailDataStorage.prototype.setMessage = function (oData, bCached)
bIsHtml = false;
}
oMessage.isHtml(!!bIsHtml);
oMessage.hasImages(!!bHasExternals);
oMessage.pgpSignedVerifyStatus(Enums.SignedVerifyStatus.None);
oMessage.pgpSignedVerifyUser('');
if (oData.Result.Rtl)
{
oBody.data('rl-is-rtl', true);
this.isRtl(true);
oBody.addClass('rtl-text-part');
}
@ -14647,14 +14801,6 @@ WebMailDataStorage.prototype.setMessage = function (oData, bCached)
if (oMessage.body)
{
oMessagesBodiesDom.append(oMessage.body);
oMessage.body.data('rl-is-html', bIsHtml);
oMessage.body.data('rl-has-images', bHasExternals);
oMessage.isRtl(!!oMessage.body.data('rl-is-rtl'));
oMessage.isHtml(!!oMessage.body.data('rl-is-html'));
oMessage.hasImages(!!oMessage.body.data('rl-has-images'));
oMessage.plainRaw = Utils.pString(oMessage.body.data('rl-plain-raw'));
}
if (bHasInternals)
@ -14667,6 +14813,7 @@ WebMailDataStorage.prototype.setMessage = function (oData, bCached)
oMessage.showExternalImages(true);
}
oMessage.storeDataToDom();
this.purgeMessageBodyCacheThrottle();
}
else
@ -14675,24 +14822,10 @@ WebMailDataStorage.prototype.setMessage = function (oData, bCached)
if (oMessage.body)
{
oMessage.body.data('rl-cache-count', ++Globals.iMessageBodyCacheCount);
oMessage.isRtl(!!oMessage.body.data('rl-is-rtl'));
oMessage.isHtml(!!oMessage.body.data('rl-is-html'));
oMessage.hasImages(!!oMessage.body.data('rl-has-images'));
oMessage.plainRaw = Utils.pString(oMessage.body.data('rl-plain-raw'));
oMessage.fetchDataToDom();
}
}
if (oMessage.body && RL.data().allowOpenPGP())
{
oMessage.isPgpSigned(!!oMessage.body.data('rl-plain-pgp-signed'));
oMessage.isPgpEncrypted(!!oMessage.body.data('rl-plain-pgp-encrypted'));
}
else
{
oMessage.isPgpSigned(false);
oMessage.isPgpEncrypted(false);
}
this.messageActiveDom(oMessage.body);
this.hideMessageBodies();
@ -14851,6 +14984,69 @@ WebMailDataStorage.prototype.setMessageList = function (oData, bCached)
}
};
WebMailDataStorage.prototype.findPublicKeyByHex = function (sHash)
{
return _.find(this.openpgpkeysPublic(), function (oItem) {
return oItem && sHash === oItem.id;
});
};
WebMailDataStorage.prototype.findPublicKeysByEmail = function (sEmail)
{
return _.compact(_.map(this.openpgpkeysPublic(), function (oItem) {
var oKey = null;
if (oItem && sEmail === oItem.email)
{
try
{
oKey = window.openpgp.key.readArmored(oItem.armor);
if (oKey && !oKey.err && oKey.keys && oKey.keys[0])
{
return oKey.keys[0];
}
}
catch (e) {}
}
return null;
}));
};
WebMailDataStorage.prototype.findPrivateKeyByEmail = function (sEmail, sPass)
{
var
oPrivateKey = null,
oKey = _.find(this.openpgpkeysPrivate(), function (oItem) {
return oItem && sEmail === 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(sPass);
}
else
{
oPrivateKey = null;
}
}
catch (e)
{
oPrivateKey = null;
}
}
return oPrivateKey;
};
/**
* @constructor
*/

File diff suppressed because one or more lines are too long