mirror of
https://github.com/moparisthebest/mail
synced 2024-11-29 12:22:22 -05:00
inject pgpbuilder
This commit is contained in:
parent
debb06c943
commit
3d2fdc7f8c
@ -141,9 +141,8 @@ module.exports = function(grunt) {
|
||||
'imap-client/node_modules/mime/src/mime.js',
|
||||
'pgpmailer/src/*.js',
|
||||
'pgpmailer/node_modules/simplesmtp/src/*',
|
||||
'pgpmailer/node_modules/pgpbuilder/src/*.js',
|
||||
'pgpmailer/node_modules/pgpbuilder/node_modules/mailbuilder/src/*.js',
|
||||
'pgpmailer/node_modules/mailbuilder/src/*.js'
|
||||
'pgpbuilder/src/*.js',
|
||||
'pgpbuilder/node_modules/mailbuilder/src/*.js'
|
||||
],
|
||||
dest: 'src/lib/'
|
||||
},
|
||||
|
@ -13,6 +13,7 @@
|
||||
"crypto-lib": "https://github.com/whiteout-io/crypto-lib/tarball/master",
|
||||
"imap-client": "https://github.com/whiteout-io/imap-client/tarball/master",
|
||||
"pgpmailer": "https://github.com/whiteout-io/pgpmailer/tarball/dev/pgpbuilder",
|
||||
"pgpbuilder": "https://github.com/whiteout-io/pgpbuilder/tarball/master",
|
||||
"requirejs": "2.1.10"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@ -16,6 +16,7 @@ define(function(require) {
|
||||
InvitationDAO = require('js/dao/invitation-dao'),
|
||||
OutboxBO = require('js/bo/outbox'),
|
||||
PGP = require('js/crypto/pgp'),
|
||||
PgpBuilder = require('pgpbuilder'),
|
||||
config = require('js/app-config').config;
|
||||
|
||||
var self = {};
|
||||
@ -117,7 +118,7 @@ define(function(require) {
|
||||
};
|
||||
|
||||
imapClient = new ImapClient(imapOptions);
|
||||
pgpMailer = new PgpMailer(smtpOptions);
|
||||
pgpMailer = new PgpMailer(smtpOptions, self._pgpbuilder);
|
||||
|
||||
imapClient.onError = function(err) {
|
||||
console.log('IMAP error.', err);
|
||||
@ -341,7 +342,7 @@ define(function(require) {
|
||||
|
||||
self.buildModules = function() {
|
||||
var lawnchairDao, restDao, pubkeyDao, invitationDao,
|
||||
emailDao, keychain, pgp, userStorage;
|
||||
emailDao, keychain, pgp, userStorage, pgpbuilder;
|
||||
|
||||
// init objects and inject dependencies
|
||||
restDao = new RestDAO();
|
||||
@ -354,7 +355,8 @@ define(function(require) {
|
||||
self._keychain = keychain;
|
||||
pgp = new PGP();
|
||||
self._crypto = pgp;
|
||||
self._emailDao = emailDao = new EmailDAO(keychain, pgp, userStorage);
|
||||
self._pgpbuilder = pgpbuilder = new PgpBuilder({}); // set the worker path?!
|
||||
self._emailDao = emailDao = new EmailDAO(keychain, pgp, userStorage, pgpbuilder);
|
||||
self._outboxBo = new OutboxBO(emailDao, keychain, userStorage, invitationDao);
|
||||
};
|
||||
|
||||
|
@ -6,12 +6,11 @@ define(function(require) {
|
||||
str = require('js/app-config').string,
|
||||
config = require('js/app-config').config;
|
||||
|
||||
var EmailDAO = function(keychain, crypto, devicestorage) {
|
||||
var self = this;
|
||||
|
||||
self._keychain = keychain;
|
||||
self._crypto = crypto;
|
||||
self._devicestorage = devicestorage;
|
||||
var EmailDAO = function(keychain, crypto, devicestorage, pgpbuilder) {
|
||||
this._keychain = keychain;
|
||||
this._crypto = crypto;
|
||||
this._devicestorage = devicestorage;
|
||||
this._pgpbuilder = pgpbuilder;
|
||||
};
|
||||
|
||||
//
|
||||
@ -76,7 +75,7 @@ define(function(require) {
|
||||
self._pgpMailer = options.pgpMailer;
|
||||
// set private key
|
||||
if (self._crypto && self._crypto._privateKey) {
|
||||
self._pgpMailer._pgpbuilder._privateKey = self._crypto._privateKey;
|
||||
self._pgpbuilder._privateKey = self._crypto._privateKey;
|
||||
}
|
||||
|
||||
// delegation-esque pattern to mitigate between node-style events and plain js
|
||||
@ -143,9 +142,8 @@ define(function(require) {
|
||||
return;
|
||||
}
|
||||
|
||||
// HANDLE THIS PROPERLY!!!
|
||||
// set decrypted privateKey to pgpMailer
|
||||
self._pgpMailer._pgpbuilder._privateKey = self._crypto._privateKey;
|
||||
self._pgpbuilder._privateKey = self._crypto._privateKey;
|
||||
callback();
|
||||
});
|
||||
return;
|
||||
@ -196,9 +194,8 @@ define(function(require) {
|
||||
return;
|
||||
}
|
||||
|
||||
// HANDLE THIS PROPERLY!!!
|
||||
// set decrypted privateKey to pgpMailer
|
||||
self._pgpMailer._pgpbuilder._privateKey = self._crypto._privateKey;
|
||||
self._pgpbuilder._privateKey = self._crypto._privateKey;
|
||||
callback();
|
||||
});
|
||||
});
|
||||
@ -1060,11 +1057,11 @@ define(function(require) {
|
||||
};
|
||||
|
||||
EmailDAO.prototype.encrypt = function(options, callback) {
|
||||
this._pgpMailer.encrypt(options, callback);
|
||||
this._pgpbuilder.encrypt(options, callback);
|
||||
};
|
||||
|
||||
EmailDAO.prototype.reEncrypt = function(options, callback) {
|
||||
this._pgpMailer.reEncrypt(options, callback);
|
||||
this._pgpbuilder.reEncrypt(options, callback);
|
||||
};
|
||||
|
||||
//
|
||||
|
@ -5,6 +5,7 @@ define(function(require) {
|
||||
KeychainDAO = require('js/dao/keychain-dao'),
|
||||
ImapClient = require('imap-client'),
|
||||
PgpMailer = require('pgpmailer'),
|
||||
PgpBuilder = require('pgpbuilder'),
|
||||
PGP = require('js/crypto/pgp'),
|
||||
DeviceStorageDAO = require('js/dao/devicestorage-dao'),
|
||||
str = require('js/app-config').string,
|
||||
@ -13,7 +14,7 @@ define(function(require) {
|
||||
chai.Assertion.includeStack = true;
|
||||
|
||||
describe('Email DAO unit tests', function() {
|
||||
var dao, keychainStub, imapClientStub, pgpMailerStub, pgpStub, devicestorageStub;
|
||||
var dao, keychainStub, imapClientStub, pgpMailerStub, pgpBuilderStub, pgpStub, devicestorageStub;
|
||||
|
||||
var emailAddress, passphrase, asymKeySize, mockkeyId, dummyEncryptedMail,
|
||||
dummyDecryptedMail, mockKeyPair, account, verificationMail, verificationUuid,
|
||||
@ -111,10 +112,11 @@ define(function(require) {
|
||||
keychainStub = sinon.createStubInstance(KeychainDAO);
|
||||
imapClientStub = sinon.createStubInstance(ImapClient);
|
||||
pgpMailerStub = sinon.createStubInstance(PgpMailer);
|
||||
pgpBuilderStub = sinon.createStubInstance(PgpBuilder);
|
||||
pgpStub = sinon.createStubInstance(PGP);
|
||||
devicestorageStub = sinon.createStubInstance(DeviceStorageDAO);
|
||||
|
||||
dao = new EmailDAO(keychainStub, pgpStub, devicestorageStub);
|
||||
dao = new EmailDAO(keychainStub, pgpStub, devicestorageStub, pgpBuilderStub);
|
||||
dao._account = account;
|
||||
|
||||
expect(dao._keychain).to.equal(keychainStub);
|
||||
@ -2613,6 +2615,29 @@ define(function(require) {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('encrypt', function() {
|
||||
it('should encrypt', function(done) {
|
||||
pgpBuilderStub.encrypt.yields();
|
||||
|
||||
dao.encrypt({}, function() {
|
||||
expect(pgpBuilderStub.encrypt.calledOnce).to.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('reEncrypt', function() {
|
||||
it('should re-encrypt', function(done) {
|
||||
pgpBuilderStub.reEncrypt.yields();
|
||||
|
||||
dao.reEncrypt({}, function() {
|
||||
expect(pgpBuilderStub.reEncrypt.calledOnce).to.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('syncOutbox', function() {
|
||||
it('should sync the outbox', function(done) {
|
||||
var folder = 'FOLDAAAA';
|
||||
|
Loading…
Reference in New Issue
Block a user