mirror of
https://github.com/moparisthebest/mail
synced 2024-11-22 08:52:15 -05:00
added preliminary functionality for outbox
This commit is contained in:
parent
99a6cda40d
commit
7542cf8589
@ -809,5 +809,64 @@ define(function(require) {
|
||||
}
|
||||
};
|
||||
|
||||
// to be removed and solved with IMAP!
|
||||
EmailDAO.prototype.store = function(email, callback) {
|
||||
var self = this,
|
||||
dbType = 'email_OUTBOX';
|
||||
|
||||
email.id = util.UUID();
|
||||
|
||||
// encrypt
|
||||
self._encrypt({
|
||||
email: email
|
||||
}, function(err, email) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
// store to local storage
|
||||
self._devicestorage.storeList([email], dbType, callback);
|
||||
});
|
||||
};
|
||||
|
||||
// to be removed and solved with IMAP!
|
||||
EmailDAO.prototype.list = function(callback) {
|
||||
var self = this,
|
||||
dbType = 'email_OUTBOX';
|
||||
|
||||
self._devicestorage.listItems(dbType, 0, null, function(err, mails) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
if (mails.length === 0) {
|
||||
callback(null, []);
|
||||
return;
|
||||
}
|
||||
|
||||
self._crypto.exportKeys(function(err, ownKeys) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
var after = _.after(mails.length, function() {
|
||||
callback(null, mails);
|
||||
});
|
||||
|
||||
mails.forEach(function(mail) {
|
||||
mail.body = str.cryptPrefix + mail.body.split(str.cryptPrefix)[1].split(str.cryptSuffix)[0] + str.cryptSuffix;
|
||||
self._crypto.decrypt(mail.body, ownKeys.publicKeyArmored, function(err, decrypted) {
|
||||
mail.body = err ? err.errMsg : decrypted;
|
||||
after();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
return EmailDAO;
|
||||
});
|
@ -1636,5 +1636,48 @@ define(function(require) {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('store', function() {
|
||||
it('should work', function(done) {
|
||||
pgpStub.exportKeys.yields(null, {
|
||||
publicKeyArmored: 'omgsocrypto'
|
||||
});
|
||||
pgpStub.encrypt.yields(null, 'asdfasfd');
|
||||
devicestorageStub.storeList.yields();
|
||||
|
||||
dao.store(dummyDecryptedMail, function(err) {
|
||||
expect(err).to.not.exist;
|
||||
expect(pgpStub.exportKeys.calledOnce).to.be.true;
|
||||
expect(pgpStub.encrypt.calledOnce).to.be.true;
|
||||
expect(devicestorageStub.storeList.calledOnce).to.be.true;
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('list', function() {
|
||||
it('should work', function(done) {
|
||||
devicestorageStub.listItems.yields(null, [dummyEncryptedMail]);
|
||||
pgpStub.exportKeys.yields(null, {
|
||||
publicKeyArmored: 'omgsocrypto'
|
||||
});
|
||||
pgpStub.decrypt.yields(null, dummyDecryptedMail.body);
|
||||
|
||||
dao.list(function(err, mails) {
|
||||
expect(err).to.not.exist;
|
||||
|
||||
expect(devicestorageStub.listItems.calledOnce).to.be.true;
|
||||
expect(pgpStub.exportKeys.calledOnce).to.be.true;
|
||||
expect(pgpStub.decrypt.calledOnce).to.be.true;
|
||||
expect(mails.length).to.equal(1);
|
||||
expect(mails[0].body).to.equal(dummyDecryptedMail.body);
|
||||
expect(mails[0].subject).to.equal(dummyDecryptedMail.subject);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user