1
0
mirror of https://github.com/moparisthebest/mail synced 2024-12-23 07:48:48 -05:00

wire emailDao.smtpSend to write view

This commit is contained in:
Tankred Hase 2013-09-15 17:05:37 +02:00
parent 836456f0d0
commit 1e5be28bf7
4 changed files with 93 additions and 21 deletions

View File

@ -15,6 +15,11 @@
outline: 0px;
}
button {
font-size: 1em;
border: 0!important;
}
.address-input {
width: 90%;
}

View File

@ -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) {

View File

@ -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('<div>')) {
body = body.replace('<div>', '\n');
}
while (has('<br>')) {
body = body.replace('<br>', '\n');
}
while (has('</div>')) {
body = body.replace('</div>', '');
}
// 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('<div>')) {
body = body.replace('<div>', '\n');
}
while (has('<br>')) {
body = body.replace('<br>', '\n');
}
while (has('</div>')) {
body = body.replace('</div>', '');
}
return body;
}
//
// Directives
//

View File

@ -4,7 +4,7 @@
<div class="address-headers">
<p>
<span>To:</span>
<input ng-model="to" class="address-input" tabindex="1">
<input ng-model="to" class="address-input" tabindex="1" focus-me >
</p>
<p>
<span>CC:</span>
@ -22,13 +22,14 @@
</div><!--/.subject-box-->
<div class="mail-text-body">
<p ng-model="body" contentEditable="true" ng-change="updatePreview()" focus-me tabindex="4"></p>
<p ng-model="body" contentEditable="true" ng-change="updatePreview()" tabindex="4"></p>
<div class="encrypt-preview">
<p>-----BEGIN ENCRYPTED PREVIEW-----<br>{{ciphertextPreview}}<br>-----END ENCRYPTED PREVIEW-----</p>
<p><br>--<br>{{signature}}</p>
<br>
<p>{{signature}}</p>
</div><!--/.encrypt-preview-->
</div><!--/.mail-text-body-->
<div class="send-btn btn-shadow" tabindex="5">Send securely</div>
<button ng-click="sendEmail()" class="send-btn btn-shadow" tabindex="5">Send securely</button>
</div>