mirror of
https://github.com/moparisthebest/mail
synced 2024-11-11 11:45:02 -05:00
sending email to multiple receivers works
This commit is contained in:
parent
6d0e562351
commit
87d26383f5
@ -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);
|
||||
|
@ -882,43 +882,10 @@ 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) {
|
||||
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]
|
||||
keys: email.receiverKeys // this Array is set in writer controller
|
||||
}, function(err, email) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
@ -927,7 +894,6 @@ define(function(require) {
|
||||
|
||||
self._smtpClient.send(email, callback);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
EmailDAO.prototype.sendPlaintext = function(options, callback) {
|
||||
|
Loading…
Reference in New Issue
Block a user