OpenPGP (Compose) (#53) UNSTABLE

This commit is contained in:
RainLoop Team 2014-03-20 02:39:36 +04:00
parent 2bf7c2e033
commit 67b5a72a71
22 changed files with 496 additions and 247 deletions

View file

@ -324,7 +324,7 @@ RainLoopApp.prototype.folders = function (fCallback)
RainLoopApp.prototype.reloadOpenPgpKeys = function ()
{
if (Globals.bAllowOpenPGP)
if (RL.data().allowOpenPGP())
{
var
aKeys = [],
@ -963,8 +963,8 @@ RainLoopApp.prototype.bootstart = function ()
if (window.openpgp)
{
RL.data().openpgpKeyring = new window.openpgp.Keyring(new OpenPgpLocalStorageDriver());
Globals.bAllowOpenPGP = true;
RL.data().allowOpenPGP(true);
RL.pub('openpgp.init');
RL.reloadOpenPgpKeys();
@ -974,7 +974,7 @@ RainLoopApp.prototype.bootstart = function ()
}
else
{
Globals.bAllowOpenPGP = false;
RL.data().allowOpenPGP(false);
}
kn.startScreens([MailBoxScreen, SettingsScreen]);

View file

@ -65,11 +65,6 @@ Globals.bDisableNanoScroll = Globals.bMobileDevice;
*/
Globals.bAllowPdfPreview = !Globals.bMobileDevice;
/**
* @type {boolean}
*/
Globals.bAllowOpenPGP = false;
/**
* @type {boolean}
*/

View file

@ -456,7 +456,11 @@ ko.bindingHandlers.emailsTags = {
'parseHook': function (aInput) {
return _.map(aInput, function (sInputValue) {
var sValue = Utils.trim(sInputValue), oEmail = null;
var
sValue = Utils.trim(sInputValue),
oEmail = null
;
if ('' !== sValue)
{
oEmail = new EmailModel();

View file

@ -4,14 +4,16 @@
* @param {Object} oElement
* @param {Function=} fOnBlur
* @param {Function=} fOnReady
* @param {Function=} fOnModeChange
*/
function NewHtmlEditorWrapper(oElement, fOnBlur, fOnReady)
function NewHtmlEditorWrapper(oElement, fOnBlur, fOnReady, fOnModeChange)
{
var self = this;
self.editor = null;
self.iBlurTimer = 0;
self.fOnBlur = fOnBlur || null;
self.fOnReady = fOnReady || null;
self.fOnModeChange = fOnModeChange || null;
self.$element = $(oElement);
@ -162,6 +164,11 @@ NewHtmlEditorWrapper.prototype.init = function ()
self.editor.on('mode', function() {
self.blurTrigger();
if (self.fOnModeChange)
{
self.fOnModeChange('plain' !== self.editor.mode);
}
});
self.editor.on('focus', function() {

View file

@ -359,7 +359,7 @@ MessageModel.prototype.initUpdateByMessageJson = function (oJsonMessage)
this.sInReplyTo = oJsonMessage.InReplyTo;
this.sReferences = oJsonMessage.References;
if (Globals.bAllowOpenPGP)
if (RL.data().allowOpenPGP())
{
this.isPgpSigned(!!oJsonMessage.PgpSigned);
this.isPgpEncrypted(!!oJsonMessage.PgpEncrypted);

View file

@ -344,6 +344,7 @@ function WebMailDataStorage()
// other
this.useKeyboardShortcuts = ko.observable(true);
this.allowOpenPGP = ko.observable(false);
this.openpgpkeys = ko.observableArray([]);
this.openpgpKeyring = null;
@ -868,7 +869,8 @@ WebMailDataStorage.prototype.setMessage = function (oData, bCached)
bIsHtml = false;
sPlain = oData.Result.Plain.toString();
if (Globals.bAllowOpenPGP && (oMessage.isPgpSigned() || oMessage.isPgpEncrypted()) &&
if ((oMessage.isPgpSigned() || oMessage.isPgpEncrypted()) &&
RL.data().allowOpenPGP() &&
Utils.isNormal(oData.Result.PlainRaw))
{
bPgpEncrypted = /---BEGIN PGP MESSAGE---/.test(oData.Result.PlainRaw);
@ -968,7 +970,7 @@ WebMailDataStorage.prototype.setMessage = function (oData, bCached)
}
}
if (Globals.bAllowOpenPGP && oMessage.body)
if (oMessage.body && RL.data().allowOpenPGP())
{
oMessage.isPgpSigned(!!oMessage.body.data('rl-plain-pgp-signed'));
oMessage.isPgpEncrypted(!!oMessage.body.data('rl-plain-pgp-encrypted'));

View file

@ -1,5 +1,5 @@
.popups {
.b-open-pgp-key-view-content, .b-open-pgp-key-generate-content, .b-open-pgp-key-add-content {
.b-open-pgp-key-view-content, .b-open-pgp-key-generate-content, .b-open-pgp-key-add-content, .b-compose-open-pgp-content {
.modal-header {
background-color: #fff;

View file

@ -55,6 +55,10 @@ select {
padding-right: 12px;
}
.btn-group.btn-group-custom-margin > .btn + .btn {
margin-left: 0px;
}
.dropdown-menu {
.border-radius(@btnBorderRadius);
}

View file

@ -0,0 +1,64 @@
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
/**
* @constructor
* @extends KnoinAbstractViewModel
*/
function PopupsComposeOpenPgpViewModel()
{
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsComposeOpenPgp');
this.notification = ko.observable('');
this.sign = ko.observable(true);
this.encrypt = ko.observable(true);
this.password = ko.observable('');
this.password.focus = ko.observable(true);
// commands
this.doCommand = Utils.createCommand(this, function () {
this.cancelCommand();
}, function () {
return '' === this.notification();
});
Knoin.constructorEnd(this);
}
Utils.extendAsViewModel('PopupsComposeOpenPgpViewModel', PopupsComposeOpenPgpViewModel);
PopupsComposeOpenPgpViewModel.prototype.clearPopup = function ()
{
this.notification('');
this.password('');
this.password.focus(false);
};
PopupsComposeOpenPgpViewModel.prototype.onHide = function ()
{
this.clearPopup();
};
PopupsComposeOpenPgpViewModel.prototype.onShow = function (fCallback, sText, sFromEmail, sTo, sCc, sBcc)
{
this.clearPopup();
if ('' === sTo + sCc + sBcc)
{
this.notification('Please specify at least one recipient');
}
// TODO
};
PopupsComposeOpenPgpViewModel.prototype.onFocus = function ()
{
if (this.sign())
{
this.password.focus(true);
}
};

View file

@ -28,6 +28,8 @@ function PopupsComposeViewModel()
}
;
this.allowOpenPGP = oRainLoopData.allowOpenPGP;
this.resizer = ko.observable(false).extend({'throttle': 50});
this.to = ko.observable('');
@ -37,6 +39,7 @@ function PopupsComposeViewModel()
this.replyTo = ko.observable('');
this.subject = ko.observable('');
this.isHtml = ko.observable(false);
this.requestReadReceipt = ko.observable(false);
@ -355,6 +358,23 @@ function PopupsComposeViewModel()
Utils.extendAsViewModel('PopupsComposeViewModel', PopupsComposeViewModel);
PopupsComposeViewModel.prototype.openOpenPgpPopup = function ()
{
if (this.allowOpenPGP() && this.oEditor && !this.oEditor.isHtml())
{
kn.showScreenPopup(PopupsComposeOpenPgpViewModel, [
function () {
},
this.oEditor.getData(),
this.currentIdentityResultEmail(),
this.to(),
this.cc(),
this.bcc()
]);
}
};
PopupsComposeViewModel.prototype.reloadDraftFolder = function ()
{
var sDraftFolder = RL.data().draftFolder();
@ -597,6 +617,8 @@ PopupsComposeViewModel.prototype.editor = function (fOnInit)
_.delay(function () {
self.oEditor = new NewHtmlEditorWrapper(self.composeEditorArea(), null, function () {
fOnInit(self.oEditor);
}, function (bHtml) {
self.isHtml(!!bHtml);
});
}, 300);
}