From bc9e635270ab40c33df1a8273ee0cd9777a94dc0 Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Thu, 29 Aug 2013 19:32:34 +0200 Subject: [PATCH] cleanup and integrate new imap-client --- src/js/dao/email-dao.js | 43 ++++++++++++++++++++------------- src/js/view/read-view.js | 2 +- test/new-unit/email-dao-test.js | 2 +- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/js/dao/email-dao.js b/src/js/dao/email-dao.js index 01295af..9334211 100644 --- a/src/js/dao/email-dao.js +++ b/src/js/dao/email-dao.js @@ -154,6 +154,7 @@ define(function(require) { // validate public key if (!receiverPubkey) { + // user hasn't registered a public key yet... invite callback({ errMsg: 'No public key found for: ' + email.from }); @@ -165,13 +166,6 @@ define(function(require) { }); }; - /** - * Encrypt an email symmetrically - */ - // EmailDAO.prototype.encryptForNewUser = function(email, callback) { - - // }; - /** * Encrypt an email asymmetrically for an exisiting user with their public key */ @@ -179,7 +173,7 @@ define(function(require) { var self = this, ptItems = [email], receiverPubkeys = [receiverPubkey], - to, greeting, ct, i; + i; // add attachment to encryption batch and remove from email object if (email.attachments) { @@ -197,14 +191,8 @@ define(function(require) { return; } - // get first name of recipient - to = (email.to[0].name || email.to[0].address).split('@')[0].split('.')[0].split(' ')[0]; - greeting = 'Hi ' + to + ',\n\n'; - - // build encrypted text body - ct = btoa(JSON.stringify(encryptedList[0])); - email.body = greeting + MESSAGE + PREFIX + ct + SUFFIX + SIGNATURE; - email.subject = SUBJECT; + // replace body and subject of the email with encrypted versions + email = self.frameEncryptedMessage(email, encryptedList[0]); // add encrypted attachments if (encryptedList.length > 1) { @@ -222,6 +210,27 @@ define(function(require) { }); }; + /** + * Frames an encrypted message in base64 Format + */ + EmailDAO.prototype.frameEncryptedMessage = function(email, ct) { + var to, greeting, ctBase64; + + // get first name of recipient + to = (email.to[0].name || email.to[0].address).split('@')[0].split('.')[0].split(' ')[0]; + greeting = 'Hi ' + to + ',\n\n'; + + // build encrypted text body + ctBase64 = btoa(JSON.stringify(ct)); + email.body = greeting + MESSAGE + PREFIX + ctBase64 + SUFFIX + SIGNATURE; + email.subject = SUBJECT; + + return email; + }; + + /** + * Send an actual message object via smtp + */ EmailDAO.prototype.send = function(email, callback) { var self = this; @@ -381,7 +390,7 @@ define(function(require) { self._imapClient.getMessage({ path: options.folder, uid: options.uid, - onMessageBody: messageReady, + onMessage: messageReady, /*onAttachment: attachmentReady*/ }); }; diff --git a/src/js/view/read-view.js b/src/js/view/read-view.js index 228141c..e7ae752 100644 --- a/src/js/view/read-view.js +++ b/src/js/view/read-view.js @@ -42,7 +42,7 @@ define(['jquery', 'underscore', 'backbone', 'js/app-config'], function($, _, Bac parseAttachments: function() { var attachments = this.model.attachments; - if (!attachments) { + if (!attachments || attachments.length < 1) { // remove link if no attachments are present $(this.el).find('#attachmentItem').remove(); return; diff --git a/test/new-unit/email-dao-test.js b/test/new-unit/email-dao-test.js index c163053..77199c8 100644 --- a/test/new-unit/email-dao-test.js +++ b/test/new-unit/email-dao-test.js @@ -272,7 +272,7 @@ define(function(require) { it('should parse message body without attachement', function(done) { var uid = 415; - imapClientStub.getMessage.yieldsTo('onMessageBody', null, { + imapClientStub.getMessage.yieldsTo('onMessage', null, { uid: uid, body: '' });