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:
parent
836456f0d0
commit
1e5be28bf7
@ -15,6 +15,11 @@
|
|||||||
outline: 0px;
|
outline: 0px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
font-size: 1em;
|
||||||
|
border: 0!important;
|
||||||
|
}
|
||||||
|
|
||||||
.address-input {
|
.address-input {
|
||||||
width: 90%;
|
width: 90%;
|
||||||
}
|
}
|
||||||
|
@ -3,11 +3,13 @@ define(function(require) {
|
|||||||
|
|
||||||
var _ = require('underscore'),
|
var _ = require('underscore'),
|
||||||
appController = require('js/app-controller'),
|
appController = require('js/app-controller'),
|
||||||
moment = require('moment');
|
moment = require('moment'),
|
||||||
|
emailDao;
|
||||||
|
|
||||||
var MessageListCtrl = function($scope, $routeParams) {
|
var MessageListCtrl = function($scope, $routeParams) {
|
||||||
$scope.folder = $routeParams.folder;
|
$scope.folder = $routeParams.folder;
|
||||||
$scope.messageId = $routeParams.messageId;
|
$scope.messageId = $routeParams.messageId;
|
||||||
|
emailDao = appController._emailDao;
|
||||||
|
|
||||||
$scope.select = function(email) {
|
$scope.select = function(email) {
|
||||||
email.bodyDisplayParts = email.body.split('\n');
|
email.bodyDisplayParts = email.body.split('\n');
|
||||||
@ -48,7 +50,7 @@ define(function(require) {
|
|||||||
|
|
||||||
function fetchList(folder, callback) {
|
function fetchList(folder, callback) {
|
||||||
// fetch imap folder's message list
|
// fetch imap folder's message list
|
||||||
appController._emailDao.imapListMessages({
|
emailDao.imapListMessages({
|
||||||
folder: folder,
|
folder: folder,
|
||||||
offset: -6,
|
offset: -6,
|
||||||
num: 0
|
num: 0
|
||||||
@ -74,7 +76,7 @@ define(function(require) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
_.each(messageList, function(messageItem) {
|
_.each(messageList, function(messageItem) {
|
||||||
appController._emailDao.imapGetMessage({
|
emailDao.imapGetMessage({
|
||||||
folder: folder,
|
folder: folder,
|
||||||
uid: messageItem.uid
|
uid: messageItem.uid
|
||||||
}, function(err, message) {
|
}, function(err, message) {
|
||||||
|
@ -2,9 +2,11 @@ define(function(require) {
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var angular = require('angular'),
|
var angular = require('angular'),
|
||||||
|
appController = require('js/app-controller'),
|
||||||
aes = require('cryptoLib/aes-cbc'),
|
aes = require('cryptoLib/aes-cbc'),
|
||||||
util = require('cryptoLib/util'),
|
util = require('cryptoLib/util'),
|
||||||
str = require('js/app-config').string;
|
str = require('js/app-config').string,
|
||||||
|
emailDao;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Controller
|
// Controller
|
||||||
@ -13,32 +15,94 @@ define(function(require) {
|
|||||||
var WriteCtrl = function($scope) {
|
var WriteCtrl = function($scope) {
|
||||||
$scope.signature = str.signature;
|
$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
|
// generate key,iv for encryption preview
|
||||||
var key = util.random(128),
|
var key = util.random(128),
|
||||||
iv = util.random(128);
|
iv = util.random(128);
|
||||||
|
|
||||||
$scope.updatePreview = function() {
|
$scope.updatePreview = function() {
|
||||||
// remove generated html from body
|
|
||||||
var body = $scope.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.
|
// 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;
|
var plaintext = ($scope.subject) ? $scope.subject + body : body;
|
||||||
$scope.ciphertextPreview = aes.encrypt(plaintext, key, iv);
|
$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
|
// Directives
|
||||||
//
|
//
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
<div class="address-headers">
|
<div class="address-headers">
|
||||||
<p>
|
<p>
|
||||||
<span>To:</span>
|
<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>
|
||||||
<p>
|
<p>
|
||||||
<span>CC:</span>
|
<span>CC:</span>
|
||||||
@ -22,13 +22,14 @@
|
|||||||
</div><!--/.subject-box-->
|
</div><!--/.subject-box-->
|
||||||
|
|
||||||
<div class="mail-text-body">
|
<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">
|
<div class="encrypt-preview">
|
||||||
<p>-----BEGIN ENCRYPTED PREVIEW-----<br>{{ciphertextPreview}}<br>-----END ENCRYPTED PREVIEW-----</p>
|
<p>-----BEGIN ENCRYPTED PREVIEW-----<br>{{ciphertextPreview}}<br>-----END ENCRYPTED PREVIEW-----</p>
|
||||||
<p><br>--<br>{{signature}}</p>
|
<br>
|
||||||
|
<p>{{signature}}</p>
|
||||||
</div><!--/.encrypt-preview-->
|
</div><!--/.encrypt-preview-->
|
||||||
</div><!--/.mail-text-body-->
|
</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>
|
</div>
|
Loading…
Reference in New Issue
Block a user