mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-04 06:57:03 +03:00
Code refactoring
This commit is contained in:
parent
bf56821c2d
commit
31860420cb
32 changed files with 1342 additions and 1282 deletions
|
|
@ -3,7 +3,10 @@
|
|||
'use strict';
|
||||
|
||||
var
|
||||
ko = require('ko')
|
||||
_ = require('_'),
|
||||
ko = require('ko'),
|
||||
|
||||
Utils = require('Common/Utils')
|
||||
;
|
||||
|
||||
/**
|
||||
|
|
@ -35,6 +38,84 @@
|
|||
return !!this.openpgp;
|
||||
};
|
||||
|
||||
PgpUserStore.prototype.findPublicKeyByHex = function (sHash)
|
||||
{
|
||||
return _.find(this.openpgpkeysPublic(), function (oItem) {
|
||||
return oItem && sHash === oItem.id;
|
||||
});
|
||||
};
|
||||
|
||||
PgpUserStore.prototype.findPublicKeysByEmail = function (sEmail)
|
||||
{
|
||||
var self = this;
|
||||
return _.compact(_.map(this.openpgpkeysPublic(), function (oItem) {
|
||||
|
||||
var oKey = null;
|
||||
if (oItem && sEmail === oItem.email)
|
||||
{
|
||||
try
|
||||
{
|
||||
oKey = self.openpgp.key.readArmored(oItem.armor);
|
||||
if (oKey && !oKey.err && oKey.keys && oKey.keys[0])
|
||||
{
|
||||
return oKey.keys[0];
|
||||
}
|
||||
}
|
||||
catch (e) {}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}));
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} sEmail
|
||||
* @param {string=} sPassword
|
||||
* @returns {?}
|
||||
*/
|
||||
PgpUserStore.prototype.findPrivateKeyByEmail = function (sEmail, sPassword)
|
||||
{
|
||||
var
|
||||
oPrivateKey = null,
|
||||
oKey = _.find(this.openpgpkeysPrivate(), function (oItem) {
|
||||
return oItem && sEmail === oItem.email;
|
||||
})
|
||||
;
|
||||
|
||||
if (oKey)
|
||||
{
|
||||
try
|
||||
{
|
||||
oPrivateKey = this.openpgp.key.readArmored(oKey.armor);
|
||||
if (oPrivateKey && !oPrivateKey.err && oPrivateKey.keys && oPrivateKey.keys[0])
|
||||
{
|
||||
oPrivateKey = oPrivateKey.keys[0];
|
||||
oPrivateKey.decrypt(Utils.pString(sPassword));
|
||||
}
|
||||
else
|
||||
{
|
||||
oPrivateKey = null;
|
||||
}
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
oPrivateKey = null;
|
||||
}
|
||||
}
|
||||
|
||||
return oPrivateKey;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string=} sPassword
|
||||
* @returns {?}
|
||||
*/
|
||||
PgpUserStore.prototype.findSelfPrivateKey = function (sPassword)
|
||||
{
|
||||
return this.findPrivateKeyByEmail(require('Stores/User/Account').email(), sPassword);
|
||||
};
|
||||
|
||||
module.exports = new PgpUserStore();
|
||||
|
||||
}());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue