2014-03-13 06:29:33 +08:00
|
|
|
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @constructor
|
|
|
|
* @extends KnoinAbstractViewModel
|
|
|
|
*/
|
|
|
|
function PopupsAddOpenPgpKeyViewModel()
|
|
|
|
{
|
|
|
|
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsAddOpenPgpKey');
|
|
|
|
|
|
|
|
this.key = ko.observable('');
|
|
|
|
this.key.error = ko.observable(false);
|
|
|
|
this.key.focus = ko.observable(false);
|
|
|
|
|
|
|
|
this.key.subscribe(function () {
|
|
|
|
this.key.error(false);
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
this.addOpenPgpKeyCommand = Utils.createCommand(this, function () {
|
|
|
|
|
|
|
|
var
|
2014-04-27 00:09:38 +08:00
|
|
|
iCount = 30,
|
|
|
|
aMatch = null,
|
2014-03-13 06:29:33 +08:00
|
|
|
sKey = Utils.trim(this.key()),
|
2014-04-27 00:09:38 +08:00
|
|
|
oReg = /[\-]{3,6}BEGIN PGP (PRIVATE|PUBLIC) KEY BLOCK[\-]{3,6}[\s\S]+[\-]{3,6}END PGP (PRIVATE|PUBLIC) KEY BLOCK[\-]{3,6}/gi,
|
2014-03-13 06:29:33 +08:00
|
|
|
oOpenpgpKeyring = RL.data().openpgpKeyring
|
|
|
|
;
|
|
|
|
|
|
|
|
this.key.error('' === sKey);
|
|
|
|
|
|
|
|
if (!oOpenpgpKeyring || this.key.error())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-04-27 00:09:38 +08:00
|
|
|
do
|
|
|
|
{
|
|
|
|
aMatch = oReg.exec(sKey);
|
|
|
|
if (!aMatch || 0 > iCount)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aMatch[0] && aMatch[1] && aMatch[2] && aMatch[1] === aMatch[2])
|
|
|
|
{
|
|
|
|
if ('PRIVATE' === aMatch[1])
|
|
|
|
{
|
|
|
|
oOpenpgpKeyring.privateKeys.importKey(aMatch[0]);
|
|
|
|
}
|
|
|
|
else if ('PUBLIC' === aMatch[1])
|
|
|
|
{
|
|
|
|
oOpenpgpKeyring.publicKeys.importKey(aMatch[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
iCount--;
|
|
|
|
}
|
|
|
|
while (true);
|
|
|
|
|
2014-03-13 06:29:33 +08:00
|
|
|
oOpenpgpKeyring.store();
|
|
|
|
|
|
|
|
RL.reloadOpenPgpKeys();
|
|
|
|
Utils.delegateRun(this, 'cancelCommand');
|
|
|
|
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
Knoin.constructorEnd(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
Utils.extendAsViewModel('PopupsAddOpenPgpKeyViewModel', PopupsAddOpenPgpKeyViewModel);
|
|
|
|
|
|
|
|
PopupsAddOpenPgpKeyViewModel.prototype.clearPopup = function ()
|
|
|
|
{
|
|
|
|
this.key('');
|
|
|
|
this.key.error(false);
|
|
|
|
};
|
|
|
|
|
|
|
|
PopupsAddOpenPgpKeyViewModel.prototype.onShow = function ()
|
|
|
|
{
|
|
|
|
this.clearPopup();
|
|
|
|
};
|
|
|
|
|
|
|
|
PopupsAddOpenPgpKeyViewModel.prototype.onFocus = function ()
|
|
|
|
{
|
|
|
|
this.key.focus(true);
|
|
|
|
};
|