Skip to content

Commit

Permalink
OpenPGP - part 2 - unstable (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
RainLoop committed Jan 28, 2014
1 parent d181974 commit 0bb69d4
Show file tree
Hide file tree
Showing 23 changed files with 599 additions and 338 deletions.
7 changes: 7 additions & 0 deletions dev/Admin/Security.js
Expand Up @@ -6,6 +6,7 @@
function AdminSecurity()
{
this.csrfProtection = ko.observable(!!RL.settingsGet('UseTokenProtection'));
this.openPGP = ko.observable(!!RL.settingsGet('OpenPGP'));

this.adminLogin = ko.observable(RL.settingsGet('AdminLogin'));
this.adminPassword = ko.observable('');
Expand Down Expand Up @@ -65,6 +66,12 @@ AdminSecurity.prototype.onBuild = function ()
'TokenProtection': bValue ? '1' : '0'
});
});

this.openPGP.subscribe(function (bValue) {
RL.remote().saveAdminConfig(Utils.emptyFunction, {
'OpenPGP': bValue ? '1' : '0'
});
});
};

AdminSecurity.prototype.onHide = function ()
Expand Down
1 change: 1 addition & 0 deletions dev/Boots/AbstractApp.js
Expand Up @@ -238,6 +238,7 @@ AbstractApp.prototype.sub = function (sName, fFunc, oContext)
*/
AbstractApp.prototype.pub = function (sName, aArgs)
{
Plugins.runHook('rl-pub', [sName, aArgs]);
if (!Utils.isUnd(this.oSubs[sName]))
{
_.each(this.oSubs[sName], function (aItem) {
Expand Down
38 changes: 26 additions & 12 deletions dev/Boots/RainLoopApp.js
Expand Up @@ -703,6 +703,7 @@ RainLoopApp.prototype.mailToHelper = function (sMailToUrl)

RainLoopApp.prototype.bootstart = function ()
{
RL.pub('rl.bootstart');
AbstractApp.prototype.bootstart.call(this);

RL.data().populateDataOnStart();
Expand Down Expand Up @@ -785,17 +786,26 @@ RainLoopApp.prototype.bootstart = function ()

if (bValue)
{
// if (window.crypto && window.crypto.getRandomValues)
// {
// $.ajax({
// 'url': RL.link().openPgpJs(),
// 'dataType': 'script',
// 'cache': true,
// 'success': function () {
// window.console.log('openPgpJs');
// }
// });
// }
if (window.crypto && window.crypto.getRandomValues && RL.settingsGet('OpenPGP'))
{
$.ajax({
'url': RL.link().openPgpJs(),
'dataType': 'script',
'cache': true,
'success': function () {
if (window.openpgp)
{
// window.console.log(window.openpgp);
Globals.bAllowOpenPGP = true;
RL.pub('openpgp.init');
}
}
});
}
else
{
Globals.bAllowOpenPGP = false;
}

kn.startScreens([MailBoxScreen, SettingsScreen]);

Expand Down Expand Up @@ -846,13 +856,15 @@ RainLoopApp.prototype.bootstart = function ()

}, 2000);


Plugins.runHook('rl-start-user-screens');
RL.pub('rl.bootstart-user-screens');
}
else
{
kn.startScreens([LoginScreen]);

Plugins.runHook('rl-start-login-screens');
RL.pub('rl.bootstart-login-screens');
}

if (window.SimplePace)
Expand All @@ -878,6 +890,7 @@ RainLoopApp.prototype.bootstart = function ()
kn.startScreens([LoginScreen]);

Plugins.runHook('rl-start-login-screens');
RL.pub('rl.bootstart-login-screens');

if (window.SimplePace)
{
Expand Down Expand Up @@ -925,6 +938,7 @@ RainLoopApp.prototype.bootstart = function ()
});

Plugins.runHook('rl-start-screens');
RL.pub('rl.bootstart-end');
};

/**
Expand Down
5 changes: 5 additions & 0 deletions dev/Common/Globals.js
Expand Up @@ -65,6 +65,11 @@ Globals.bDisableNanoScroll = Globals.bMobileDevice;
*/
Globals.bAllowPdfPreview = !Globals.bMobileDevice;

/**
* @type {boolean}
*/
Globals.bAllowOpenPGP = false;

/**
* @type {boolean}
*/
Expand Down
20 changes: 20 additions & 0 deletions dev/Models/MessageModel.js
Expand Up @@ -82,11 +82,16 @@ function MessageModel()
}, this);

this.body = null;
this.plainRaw = '';
this.isRtl = ko.observable(false);
this.isHtml = ko.observable(false);
this.hasImages = ko.observable(false);
this.attachments = ko.observableArray([]);

this.isPgpSigned = ko.observable(false);
this.isPgpEncrypted = ko.observable(false);
this.pgpSignature = ko.observable('');

this.priority = ko.observable(Enums.MessagePriority.Normal);
this.readReceipt = ko.observable('');

Expand Down Expand Up @@ -253,6 +258,10 @@ MessageModel.prototype.clear = function ()
this.isHtml(false);
this.hasImages(false);
this.attachments([]);

this.isPgpSigned(false);
this.isPgpEncrypted(false);
this.pgpSignature('');

this.priority(Enums.MessagePriority.Normal);
this.readReceipt('');
Expand Down Expand Up @@ -347,6 +356,13 @@ MessageModel.prototype.initUpdateByMessageJson = function (oJsonMessage)
this.sInReplyTo = oJsonMessage.InReplyTo;
this.sReferences = oJsonMessage.References;

if (Globals.bAllowOpenPGP)
{
this.isPgpSigned(!!oJsonMessage.PgpSigned);
this.isPgpEncrypted(!!oJsonMessage.PgpEncrypted);
this.pgpSignature(oJsonMessage.PgpSignature);
}

this.hasAttachments(!!oJsonMessage.HasAttachments);
this.attachmentsMainType(oJsonMessage.AttachmentsMainType);

Expand Down Expand Up @@ -808,6 +824,10 @@ MessageModel.prototype.populateByMessageListItem = function (oMessage)
// this.hasImages(false);
// this.attachments([]);

// this.isPgpSigned(false);
// this.isPgpEncrypted(false);
// this.pgpSignature('');

this.priority(Enums.MessagePriority.Normal);
this.aDraftInfo = [];
this.sMessageId = '';
Expand Down
100 changes: 86 additions & 14 deletions dev/Storages/WebMailData.js
Expand Up @@ -709,6 +709,10 @@ WebMailDataStorage.prototype.setMessage = function (oData, bCached)
oBody = null,
oTextBody = null,
sId = '',
sPlain = '',
bPgpSigned = false,
bPgpEncrypted = false,
mPgpMessage = null,
oMessagesBodiesDom = this.messagesBodiesDom(),
oMessage = this.message()
;
Expand Down Expand Up @@ -747,7 +751,57 @@ WebMailDataStorage.prototype.setMessage = function (oData, bCached)
else if (Utils.isNormal(oData.Result.Plain) && '' !== oData.Result.Plain)
{
bIsHtml = false;
oBody.html(oData.Result.Plain.toString()).addClass('b-text-part plain');
sPlain = oData.Result.Plain.toString();

if (Globals.bAllowOpenPGP && (oMessage.isPgpSigned() || oMessage.isPgpEncrypted()) &&
Utils.isNormal(oData.Result.PlainRaw))
{
bPgpEncrypted = /---BEGIN PGP MESSAGE---/.test(oData.Result.PlainRaw);
if (!bPgpEncrypted)
{
bPgpSigned = /-----BEGIN PGP SIGNED MESSAGE-----/.test(oData.Result.PlainRaw) &&
/-----BEGIN PGP SIGNATURE-----/.test(oData.Result.PlainRaw);
}

if (bPgpSigned && oMessage.isPgpSigned() && oMessage.pgpSignature())
{
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;
}
}
else if (bPgpEncrypted && oMessage.isPgpEncrypted())
{
try
{
mPgpMessage = window.openpgp.message.readArmored(oData.Result.PlainRaw);
}
catch (oExc) {}

sPlain = '<pre class="b-plain-openpgp encrypted">' + oData.Result.PlainRaw + '</pre>';
}

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

oBody.html(sPlain).addClass('b-text-part plain');
}
else
{
Expand All @@ -760,15 +814,19 @@ WebMailDataStorage.prototype.setMessage = function (oData, bCached)
oBody.addClass('rtl-text-part');
}

oMessagesBodiesDom.append(oBody);

oBody.data('rl-is-html', bIsHtml);
oBody.data('rl-has-images', bHasExternals);

oMessage.isRtl(!!oBody.data('rl-is-rtl'));
oMessage.isHtml(!!oBody.data('rl-is-html'));
oMessage.hasImages(!!oBody.data('rl-has-images'));
oMessage.body = oBody;
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)
{
Expand All @@ -784,12 +842,26 @@ WebMailDataStorage.prototype.setMessage = function (oData, bCached)
}
else
{
oTextBody.data('rl-cache-count', ++Globals.iMessageBodyCacheCount);

oMessage.isRtl(!!oTextBody.data('rl-is-rtl'));
oMessage.isHtml(!!oTextBody.data('rl-is-html'));
oMessage.hasImages(!!oTextBody.data('rl-has-images'));
oMessage.body = oTextBody;
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'));
}
}

if (Globals.bAllowOpenPGP && oMessage.body)
{
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);
Expand Down
20 changes: 0 additions & 20 deletions dev/Styles/Compose.less
Expand Up @@ -145,24 +145,4 @@
color: #fff;
}
}

.editorTextArea, .editorHtmlArea {

background: #fff;
color: #000;
font-family: Arial, Verdana, Geneva, sans-serif;
font-size: 14px;

table {
border-collapse: separate;
}

blockquote {
border: 0;
border-left: solid 2px #444;
margin-left: 5px;
margin: 5px 0;
padding-left: 5px;
}
}
}
22 changes: 15 additions & 7 deletions dev/Styles/Editor.less
Expand Up @@ -76,12 +76,15 @@

.box-sizing(border-box);

background: #fff;
color: #000;

border: 0px !important;
overflow: auto;
overflow-y: scroll;
font-family: arial, sans-serif;
font-size: 14px;
line-height: 16px;
font-family: Arial, Verdana, Geneva, sans-serif;
font-size: 13px;
line-height: 15px;
margin: 0px;
padding: 8px;

Expand All @@ -102,9 +105,11 @@
}

blockquote {
border: 0;
border-left: solid 2px #444;
margin-left: 5px;
padding-left: 5px
margin: 5px 0;
padding-left: 5px;
}

img {
Expand All @@ -119,14 +124,17 @@
.editorTextArea {
.box-sizing(border-box);

background: #fff;
color: #000;

display: block;
border: 0px !important;
width: 100%;
line-height: 16px;
margin: 0px;
padding: 8px;
font-family: arial, sans-serif;
font-size: 14px;
font-family: Monaco, Menlo, Consolas, 'Courier New', monospace;
font-size: 13px;
line-height: 15px;

overflow: auto;
overflow-y: scroll;
Expand Down

0 comments on commit 0bb69d4

Please sign in to comment.