From aa5b476de0a910064a3c330aabb8a5d603d57799 Mon Sep 17 00:00:00 2001 From: Felix Hammerl Date: Tue, 14 Jan 2014 16:32:36 +0100 Subject: [PATCH] dev/imap-redesign --- package.json | 2 +- src/js/dao/email-dao.js | 28 +++-------------- test/new-unit/email-dao-test.js | 53 ++++----------------------------- 3 files changed, 11 insertions(+), 72 deletions(-) diff --git a/package.json b/package.json index 7ff1e93..6a1e3cd 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ }, "dependencies": { "crypto-lib": "https://github.com/whiteout-io/crypto-lib/tarball/master", - "imap-client": "git+ssh://git@github.com:whiteout-io/imap-client.git#master", + "imap-client": "git+ssh://git@github.com:whiteout-io/imap-client.git#dev/imap-redesign", "smtp-client": "git+ssh://git@github.com:whiteout-io/smtp-client.git#master", "requirejs": "2.1.8" }, diff --git a/src/js/dao/email-dao.js b/src/js/dao/email-dao.js index 8352354..13efb71 100644 --- a/src/js/dao/email-dao.js +++ b/src/js/dao/email-dao.js @@ -1111,36 +1111,16 @@ define(function(require) { return; } - self._imapClient.listMessagesByUid({ + self._imapClient.getMessage({ path: options.folder, - firstUid: options.uid, - lastUid: options.uid - }, function(err, imapHeaders) { + uid: options.uid + }, function(err, message) { if (err) { callback(err); return; } - var imapHeader = imapHeaders[0]; - self._imapClient.getMessagePreview({ - path: options.folder, - uid: options.uid - }, function(err, message) { - if (err) { - callback(err); - return; - } - - // create a bastard child of smtp and imap. before thinking this is stupid, talk to the guys who wrote this. - // p.s. it's a parsing issue. - - imapHeader.id = message.id; - imapHeader.body = message.body; - imapHeader.html = message.html; - imapHeader.attachments = message.attachments; - - callback(null, imapHeader); - }); + callback(null, message); }); }; diff --git a/test/new-unit/email-dao-test.js b/test/new-unit/email-dao-test.js index f596085..99adaae 100644 --- a/test/new-unit/email-dao-test.js +++ b/test/new-unit/email-dao-test.js @@ -724,24 +724,10 @@ define(function(require) { var path = 'FOLDAAAA', uid = 1337; - imapClientStub.listMessagesByUid.withArgs({ - path: path, - firstUid: uid, - lastUid: uid - }).yields(null, [{ - uid: uid, - subject: 'asdasd', - unread: true, - answered: false - }]); - - imapClientStub.getMessagePreview.withArgs({ + imapClientStub.getMessage.withArgs({ path: path, uid: uid - }).yields(null, { - id: 'idididididid', - body: 'yes.' - }); + }).yields(null, {}); dao._imapGetMessage({ folder: path, @@ -750,17 +736,16 @@ define(function(require) { expect(err).to.not.exist; expect(msg).to.exist; - expect(imapClientStub.listMessagesByUid.calledOnce).to.be.true; - expect(imapClientStub.getMessagePreview.calledOnce).to.be.true; + expect(imapClientStub.getMessage.calledOnce).to.be.true; done(); }); }); - it('should not work when listMessages fails', function(done) { + it('should not work when getMessage fails', function(done) { var path = 'FOLDAAAA', uid = 1337; - imapClientStub.listMessagesByUid.yields({}); + imapClientStub.getMessage.yields({}); dao._imapGetMessage({ folder: path, @@ -769,33 +754,7 @@ define(function(require) { expect(err).to.exist; expect(msg).to.not.exist; - expect(imapClientStub.listMessagesByUid.calledOnce).to.be.true; - expect(imapClientStub.getMessagePreview.called).to.be.false; - - done(); - }); - }); - it('should not work when getMessagePreview fails', function(done) { - var path = 'FOLDAAAA', - uid = 1337; - - imapClientStub.listMessagesByUid.yields(null, [{ - uid: uid, - subject: 'asdasd', - unread: true, - answered: false - }]); - imapClientStub.getMessagePreview.yields({}); - - dao._imapGetMessage({ - folder: path, - uid: uid - }, function(err, msg) { - expect(err).to.exist; - expect(msg).to.not.exist; - - expect(imapClientStub.listMessagesByUid.calledOnce).to.be.true; - expect(imapClientStub.getMessagePreview.calledOnce).to.be.true; + expect(imapClientStub.getMessage.calledOnce).to.be.true; done(); });