From 1e5be28bf7de9007f2a7080e7faccdde7199e4c8 Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Sun, 15 Sep 2013 17:05:37 +0200 Subject: [PATCH] wire emailDao.smtpSend to write view --- src/css/write.scss | 5 ++ src/js/controller/message-list.js | 8 ++- src/js/controller/write.js | 92 ++++++++++++++++++++++++++----- src/tpl/write.html | 9 +-- 4 files changed, 93 insertions(+), 21 deletions(-) diff --git a/src/css/write.scss b/src/css/write.scss index a799398..705c691 100644 --- a/src/css/write.scss +++ b/src/css/write.scss @@ -15,6 +15,11 @@ outline: 0px; } + button { + font-size: 1em; + border: 0!important; + } + .address-input { width: 90%; } diff --git a/src/js/controller/message-list.js b/src/js/controller/message-list.js index 16d6b9b..b5aed42 100644 --- a/src/js/controller/message-list.js +++ b/src/js/controller/message-list.js @@ -3,11 +3,13 @@ define(function(require) { var _ = require('underscore'), appController = require('js/app-controller'), - moment = require('moment'); + moment = require('moment'), + emailDao; var MessageListCtrl = function($scope, $routeParams) { $scope.folder = $routeParams.folder; $scope.messageId = $routeParams.messageId; + emailDao = appController._emailDao; $scope.select = function(email) { email.bodyDisplayParts = email.body.split('\n'); @@ -48,7 +50,7 @@ define(function(require) { function fetchList(folder, callback) { // fetch imap folder's message list - appController._emailDao.imapListMessages({ + emailDao.imapListMessages({ folder: folder, offset: -6, num: 0 @@ -74,7 +76,7 @@ define(function(require) { }); _.each(messageList, function(messageItem) { - appController._emailDao.imapGetMessage({ + emailDao.imapGetMessage({ folder: folder, uid: messageItem.uid }, function(err, message) { diff --git a/src/js/controller/write.js b/src/js/controller/write.js index eeb3218..ce1b5ba 100644 --- a/src/js/controller/write.js +++ b/src/js/controller/write.js @@ -2,9 +2,11 @@ define(function(require) { 'use strict'; var angular = require('angular'), + appController = require('js/app-controller'), aes = require('cryptoLib/aes-cbc'), util = require('cryptoLib/util'), - str = require('js/app-config').string; + str = require('js/app-config').string, + emailDao; // // Controller @@ -13,32 +15,94 @@ define(function(require) { var WriteCtrl = function($scope) { $scope.signature = str.signature; + if (window.chrome && chrome.identity) { + // start the main app controller + appController.fetchOAuthToken('passphrase', function(err) { + if (err) { + console.log(err); + return; + } + + emailDao = appController._emailDao; + }); + } + // generate key,iv for encryption preview var key = util.random(128), iv = util.random(128); $scope.updatePreview = function() { - // remove generated html from body var body = $scope.body; + // remove generated html from body + body = parseBody(body); - function has(substr) { - return (body.indexOf(substr) !== -1); - } - while (has('
')) { - body = body.replace('
', '\n'); - } - while (has('
')) { - body = body.replace('
', '\n'); - } - while (has('
')) { - body = body.replace('
', ''); - } // Although this does encrypt live using AES, this is just for show. The plaintext is encrypted seperately using before sending the email. var plaintext = ($scope.subject) ? $scope.subject + body : body; $scope.ciphertextPreview = aes.encrypt(plaintext, key, iv); }; + + $scope.sendEmail = function() { + var to, body, email; + + // validate recipients + to = $scope.to.replace(/\s/g, '').split(/[,;]/); + if (!to || to.length < 1) { + console.log('Seperate recipients with a comma!'); + return; + } + + body = $scope.body; + // remove generated html from body + body = parseBody(body); + + email = { + to: [], // list of receivers + subject: $scope.subject, // Subject line + body: body // plaintext body + }; + email.from = [{ + name: '', + address: emailDao._account.emailAddress + }]; + to.forEach(function(address) { + email.to.push({ + name: '', + address: address + }); + }); + + emailDao.smtpSend(email, function(err) { + if (err) { + console.log(err); + return; + } + + if (window.chrome && chrome.app.window) { + // close the chrome window + chrome.app.window.current().close(); + return; + } + }); + }; }; + function parseBody(body) { + function has(substr) { + return (body.indexOf(substr) !== -1); + } + while (has('
')) { + body = body.replace('
', '\n'); + } + while (has('
')) { + body = body.replace('
', '\n'); + } + while (has('
')) { + body = body.replace('
', ''); + } + + return body; + } + // // Directives // diff --git a/src/tpl/write.html b/src/tpl/write.html index 28c4a0e..7b3c395 100644 --- a/src/tpl/write.html +++ b/src/tpl/write.html @@ -4,7 +4,7 @@

To: - +

CC: @@ -22,13 +22,14 @@

-

+

-----BEGIN ENCRYPTED PREVIEW-----
{{ciphertextPreview}}
-----END ENCRYPTED PREVIEW-----

-


--
{{signature}}

+
+

{{signature}}

-
Send securely
+ \ No newline at end of file