1
0
mirror of https://github.com/moparisthebest/mail synced 2024-08-13 16:43:47 -04:00

sending email to multiple receivers works

This commit is contained in:
Tankred Hase 2014-01-13 18:38:45 +01:00
parent 6d0e562351
commit 87d26383f5
2 changed files with 38 additions and 58 deletions

View File

@ -153,20 +153,13 @@ define(function(require) {
};
$scope.sendToOutbox = function() {
var to, email;
// validate recipients
to = $scope.to.replace(/\s/g, '').split(/[,;]/);
if (!to || to.length < 1) {
$scope.onError({
errMsg: 'Seperate recipients with a comma!',
sync: true
});
return;
}
var email;
// build email model for smtp-client
email = {
to: [], // list of receivers
to: [],
cc: [],
bcc: [],
subject: $scope.subject, // Subject line
body: $scope.body // use parsed plaintext body
};
@ -174,13 +167,34 @@ define(function(require) {
name: '',
address: emailDao._account.emailAddress
}];
to.forEach(function(address) {
email.to.push({
name: '',
address: address
});
});
// validate recipients and gather public keys
email.receiverKeys = []; // gather public keys for emailDao._encrypt
appendReceivers($scope.to, email.to);
appendReceivers($scope.cc, email.cc);
appendReceivers($scope.bcc, email.bcc);
function appendReceivers(srcField, destField) {
srcField.forEach(function(recipient) {
// validate address
if (!util.validateEmailAddress(recipient.address)) {
return;
}
// append address to email model
destField.push({
address: recipient.address
});
// add public key to list of recipient keys
if (recipient.key && recipient.key.publicKey) {
email.receiverKeys.push(recipient.key.publicKey);
}
});
}
// persist the email locally for later smtp transmission
emailDao.store(email, function(err) {
if (err) {
$scope.onError(err);

View File

@ -882,51 +882,17 @@ define(function(require) {
return;
}
// validate email addresses
for (var i = email.to.length - 1; i >= 0; i--) {
if (!util.validateEmailAddress(email.to[i].address)) {
callback({
errMsg: 'Invalid recipient: ' + email.to[i].address
});
return;
}
}
if (!util.validateEmailAddress(email.from[0].address)) {
callback({
errMsg: 'Invalid sender: ' + email.from
});
return;
}
// only support single recipient for e-2-e encryption
// check if receiver has a public key
self._keychain.getReceiverPublicKey(email.to[0].address, function(err, receiverPubkey) {
// public key found... encrypt and send
self._encrypt({
email: email,
keys: email.receiverKeys // this Array is set in writer controller
}, function(err, email) {
if (err) {
callback(err);
return;
}
// validate public key
if (!receiverPubkey) {
callback({
errMsg: 'User has no public key yet!'
});
return;
}
// public key found... encrypt and send
self._encrypt({
email: email,
keys: [receiverPubkey.publicKey]
}, function(err, email) {
if (err) {
callback(err);
return;
}
self._smtpClient.send(email, callback);
});
self._smtpClient.send(email, callback);
});
};