From 16308232cea09ad8876e98430b96a8381a071f7f Mon Sep 17 00:00:00 2001 From: Felix Hammerl Date: Wed, 12 Nov 2014 16:41:40 +0100 Subject: [PATCH] Move ignoreUploadOnSent check to emailDao --- src/js/app-config.js | 1 + src/js/app-controller.js | 10 ++-------- src/js/dao/email-dao.js | 26 ++++++++++++++++++++++++++ test/unit/email-dao-test.js | 13 +++++++++++++ 4 files changed, 42 insertions(+), 8 deletions(-) diff --git a/src/js/app-config.js b/src/js/app-config.js index f7d1fc3..460b117 100644 --- a/src/js/app-config.js +++ b/src/js/app-config.js @@ -10,6 +10,7 @@ exports.config = { settingsUrl: 'https://settings.whiteout.io/autodiscovery/', wmailDomain: 'wmail.io', oauthDomains: [/\.gmail\.com$/, /\.googlemail\.com$/], + ignoreUploadOnSentDomains: [/\.gmail\.com$/, /\.googlemail\.com$/], serverPrivateKeyId: 'EE342F0DDBB0F3BE', symKeySize: 256, symIvSize: 96, diff --git a/src/js/app-controller.js b/src/js/app-controller.js index 5c69745..0c6059c 100644 --- a/src/js/app-controller.js +++ b/src/js/app-controller.js @@ -278,17 +278,11 @@ ctrl.onConnect = function(callback) { imapClient.onCert = ctrl._auth.handleCertificateUpdate.bind(ctrl._auth, 'imap', ctrl.onConnect, ctrl.onError); pgpMailer.onCert = ctrl._auth.handleCertificateUpdate.bind(ctrl._auth, 'smtp', ctrl.onConnect, ctrl.onError); - // TODO: remove provider here - - // after-setup configuration depending on the provider: - // gmail does not require you to upload to the sent items folder - // after successful sending, whereas most other providers do - ctrl._emailDao.ignoreUploadOnSent = !!(config[ctrl._auth.provider] && config[ctrl._auth.provider].ignoreUploadOnSent); - // connect to clients ctrl._emailDao.onConnect({ imapClient: imapClient, - pgpMailer: pgpMailer + pgpMailer: pgpMailer, + ignoreUploadOnSent: ctrl._emailDao.checkIgnoreUploadOnSent(credentials.imap.host) }, callback); } diff --git a/src/js/dao/email-dao.js b/src/js/dao/email-dao.js index 2b6278b..9c3fdbb 100644 --- a/src/js/dao/email-dao.js +++ b/src/js/dao/email-dao.js @@ -1132,6 +1132,9 @@ EmailDAO.prototype.onConnect = function(options, callback) { self._imapClient = options.imapClient; self._pgpMailer = options.pgpMailer; + // gmail does not require you to upload to the sent items folder after successful sending, whereas most other providers do + self.ignoreUploadOnSent = !!options.ignoreUploadOnSent; + self._imapClient.login(function(err) { self._account.loggingIn = false; @@ -1776,6 +1779,29 @@ EmailDAO.prototype._uploadToSent = function(options, callback) { +// +// +// External Heler Methods +// +// + +/** + * Checks whether we need to upload to the sent folder after sending an email. + * + * @param {String} hostname The hostname to check + * @return {Boolean} true if upload can be ignored, otherwise false + */ +EmailDAO.prototype.checkIgnoreUploadOnSent = function(hostname) { + for (var i = 0; i < config.ignoreUploadOnSentDomains.length; i++) { + if (config.ignoreUploadOnSentDomains[i].test(hostname)) { + return true; + } + } + + return false; +}; + + // // // Helper Functions diff --git a/test/unit/email-dao-test.js b/test/unit/email-dao-test.js index 01f02cf..a7bff81 100644 --- a/test/unit/email-dao-test.js +++ b/test/unit/email-dao-test.js @@ -1854,6 +1854,7 @@ describe('Email DAO unit tests', function() { }, function(err) { expect(err).to.not.exist; + expect(dao.ignoreUploadOnSent).to.be.false; expect(imapClientStub.login.calledOnce).to.be.true; expect(initFoldersStub.calledOnce).to.be.true; expect(imapClientStub.mailboxCache).to.deep.equal({ @@ -2478,5 +2479,17 @@ describe('Email DAO unit tests', function() { }); }); }); + + + describe('#checkIgnoreUploadOnSent', function() { + it('should ignore upload on gmail', function() { + expect(dao.checkIgnoreUploadOnSent('bla.gmail.com')).to.be.true; + expect(dao.checkIgnoreUploadOnSent('bla.googlemail.com')).to.be.true; + }); + + it('should not ignore upload on other domain', function() { + expect(dao.checkIgnoreUploadOnSent('imap.foo.com')).to.be.false; + }); + }); }); }); \ No newline at end of file